#include <bits/stdc++.h>
const long long N = 1000000;
using namespace std;
long long k, i = 0, j, mn, ans = 0, als, t, v, ii, n, m, r1, r2, r3, r4;
string d1, d3, d2;
char kl, km, mk, lk;
double fg;
long long a[N];
int oK(long long x) {
  if (a[x] <= 0) return x;
  return a[x] = oK(a[x]);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  cin >> n >> m;
  for (i = 1; i <= n; i++) {
    cin >> k;
    a[i] = -k;
  }
  while (m--) {
    cin >> r1 >> r2;
    r1 = oK(r1);
    r2 = oK(r2);
    if (r1 == r2) continue;
    if (a[r1] > a[r2]) {
      k = r1;
      r1 = r2;
      r2 = k;
    }
    a[r1] = r2;
  }
  for (i = 1; i <= n; i++)
    if (oK(i) == i) ans -= a[i];
  cout << ans;
}
