// LonggVuz.
#include<bits/stdc++.h>
using namespace std;
// Legendary Grandmaster
void End(){
    cerr << "=> Thời gian code chạy: ";
    cerr << (1.0 * clock() / CLOCKS_PER_SEC) << " giây" << string(27, '\t');
}
#define Sonic() ios_base::sync_with_stdio(false); cin.tie(NULL);
#define use(x) freopen(x".inp", "r", stdin); freopen(x".out", "w", stdout);
#define fix(x) fixed << setprecision(x)
#define all(x) x.begin(), x.end()
#define len(x) (int)x.size()
#define ms(a, x) memset(a, x, sizeof(a))
#define bit(n, x) (n >> x & 1)
#define pb push_back
#define is insert
#define el '\n'
#define ld long double
#define int int64_t

const int mod = 1e9 + 7;
const int oo = 1e18 + 7;
const int maxn = 1e5 + 7;

int n, m, c[maxn], r[maxn];

int get(int u){
	if(u == r[u]) return u;
	return r[u] = get(r[u]);
}

void LonggVuz(){
	cin >> n >> m;
	for(int i=1; i<=n; i++){
		cin >> c[i];
		r[i] = i;
	}
	while(m--){
		int x, y; cin >> x >> y;
		x = get(x); y = get(y);
		if(x != y){
			if(c[x] < c[y]){
				r[y] = x;
			}else{
				r[x] = y;
			}
		}
	}int res = 0;
	for(int i=1; i<=n; i++){
		int x = get(i);
		if(c[x] > 0){
			res += c[x];
			c[x] = 0;
		}
	}cout << res;
}

signed main(){
	Sonic();
	
	int TC = 1; //cin >> TC;
	while(TC--) LonggVuz();
	
	End();
}