#include <bits/stdc++.h>
#define ll long long
#define N 100003
#define ok "LIBRARY"
#define fi first
#define se second
#define pb push_back
#define pii pair <int,int>
#define mp make_pair
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define name if (fopen(ok".INP","r")){ freopen(ok".INP","r",stdin); freopen(ok".OUT","w",stdout);}
using namespace std;
int n,m,a[N],b[N],min1=1e9;
ll s=0;
vector <int> adj[N],d;
queue <int> q;
void DFS(int u,vector<int> adj[],int b[],queue<int> &q)
{
    b[u]=1;
    q.push(u);
    for (int v:adj[u])
    {
        if (b[v]==0) DFS(v,adj,b,q);
    }
}
int main()
{
    fast name
    cin>>n>>m;
    memset(b,0,sizeof(b));
    for (int i=1;i<=n;i++) cin>>a[i];
    while(m--)
    {
        int u,v;
        cin>>u>>v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    for (int i=1;i<=n;i++)
    {
        if (b[i]==0)
        {
            DFS(i,adj,b,q);
            min1=1e9;
            while(!q.empty())
            {
                int x=q.front();
                q.pop();
                min1=min(min1,a[x]);
            }
            s+=min1;
        }
    }
    cout<<s;
    return 0;
}

