#include <bits/stdc++.h>
using namespace std;
vector<long long> par;
void make_par(long long szz) {
  for (long long i = 0; i < szz; i++) {
    par[i] = i;
  }
}
long long find_par(long long x) {
  if (par[x] == x) {
    return x;
  } else {
    long long result = find_par(par[x]);
    par[x] = result;
    return result;
  }
}
void unionn(long long x, long long y) {
  long long px = find_par(x);
  long long py = find_par(y);
  par[px] = py;
}
void solve() {
  long long n, m;
  cin >> n >> m;
  par.resize(n);
  make_par(n);
  long long cost[n];
  for (long long i = 0; i < n; i++) cin >> cost[i];
  long long x, y;
  for (long long i = 0; i < m; i++) {
    cin >> x >> y;
    x--, y--;
    unionn(x, y);
  }
  map<long long, long long> mp;
  for (long long i = 0; i < n; i++) {
    long long k = find_par(i);
    long long cst = cost[i];
    if (cst == 0)
      mp[k] = -1;
    else if (mp[k] == 0)
      mp[k] = cst;
    else
      mp[k] = min(mp[k], cst);
  }
  long long ans = 0;
  for (auto &it : mp) {
    if (it.second != -1) ans += it.second;
  }
  cout << ans << endl;
}
signed main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL);
  long long t;
  t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
