#include <bits/stdc++.h>
#define ll long long
using namespace std;
vector<ll> adj[100005];
ll n,a[100005],m,l,r,dd[100004],ans=0,rest;
void dfs(ll u)
{
    dd[u]=1;
    rest=min(a[u],rest);
    for(ll v:adj[u])
        if(dd[v]==0)
            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>>l>>r;
        adj[l].push_back(r);
        adj[r].push_back(l);
    }
    for(int i=1;i<=n;i++)
    {
        rest=1e16;
        if(dd[i]==0)
            {
                dfs(i);
                ans+=rest;
            }

    }
    cout<<ans;
    return 0;
}
