#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll n,m,j=0,tong=0;
ll a[100005],b[100005],v[100005];
pair<ll,ll> p[100005];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    if(fopen("LIBRARY.INP","r"))
    {
        freopen("LIBRARY.INP","r",stdin);
        freopen("LIBRARY.OUT","w",stdout);
    }
    cin >> n >> m;
    for(ll i=1;i<=n;i++) cin >> a[i];
    for(ll i=1;i<=m;i++)
    {
        cin >> p[i].first >> p[i].second;
    }
    sort(p+1,p+n+1);
    for(ll i=1;i<=m;i++)
    {
        if(b[p[i].first]==b[p[i].second]&& b[p[i].first]==0)
        {
            b[p[i].first] = j;
            b[p[i].second] = j;
            j++;
        }
        if(b[p[i].first]==0&&b[p[i].second]!=0)
        {
            b[p[i].first] = b[p[i].second];
        }
        if(b[p[i].second]==0&&b[p[i].first]!=0)
        {
            b[p[i].second] = b[p[i].first];
        }
    }
    for(ll i=1;i<=n;i++)
    {
        if(v[b[i]]==0) v[b[i]]=a[i];
        else v[b[i]] = min(v[b[i]],a[i]);
    }
    for(ll i=1;i<j;i++)
    {
        tong += v[i];
    }
    cout << tong;
}
