#include <bits/stdc++.h>
using namespace std;
int f[100005], v[100005];
int getf(int n) {
  if (f[n] == n) return n;
  f[n] = getf(f[n]);
  return f[n];
}
int main() {
  int n, m, i, a, b, fa, fb;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++) {
    scanf("%d", &v[i]);
    f[i] = i;
  }
  while (m--) {
    scanf("%d%d", &a, &b);
    fa = getf(a);
    fb = getf(b);
    f[fa] = fb;
    if (v[fb] > v[fa]) v[fb] = v[fa];
  }
  long long ans = 0;
  for (i = 1; i <= n; i++) {
    if (f[i] == i) ans += v[i];
  }
  printf("%lld\n", ans);
  return 0;
}
