#include <bits/stdc++.h>
using namespace std;
vector<int>adj[1000006];
long long n,m,u,v,a[1000006],mi,d[100006],s=0;
void dfs(int u)
{
    d[u]=1;
    for(int v:adj[u])
    {
        if(d[v]==0)
        {
            mi=min(mi,a[v]);
            dfs(v);
        }
    }
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    freopen("LIBRARY.inp","r",stdin);
    freopen("LIBRARY.out","w",stdout);
    cin>>n>>m;
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=1;i<=m;i++)
    {
        cin>>u>>v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    for(int i=1;i<=n;i++)
    {
        if(d[i]==0)
        {
            mi=a[i];
            dfs(i);
            s+=mi;
            //cout<<mi<<" ";
        }
    }
    cout<<s;
    return 0;
}
