#include <bits/stdc++.h>
using namespace std;
#define TLHAdepzais1tg ios_base::sync_with_stdio(0);cin.tie();cout.tie(0);
#define ll long long
#define N 100007
#define fi first
#define se second
#define pii pair<ll,ll>
#define str string
int n,m,a[N];
vector<int> adj[N];
vector<int> tp;
ll d[N],ans=0;
void DFS(int u)
{
    d[u]=1;
    tp.push_back(u);
    for(int v:adj[u])
    {
        if(d[v]==0)
            DFS(v);
    }
}
int main()
{
    TLHAdepzais1tg;
    if(fopen("library.inp","r"))
    {
        freopen("library.inp","r",stdin);
        freopen("library.out","w",stdout);
    }
    fill(d+1,d+N,0);
    cin>>n>>m;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    for(int i=1;i<=m;i++){
        int u,v;
        cin>>u>>v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    for(int i=1;i<=n;i++)
    {
        if(d[i]==0)
        {
            tp.clear();
            DFS(i);
            int res=1e9;
            for(int city:tp)
            {
                res=min(res,a[city]);
            }
            ans+=res;
        }
    }
    cout<<ans;
    return 0;
}

