#include <bits/stdc++.h>
using namespace std;
long long h[100000];
long long find(long long x) { return x == h[x] ? x : h[x] = find(h[x]); }
int main() {
  long long n, m, x, y, p, q, ans = 0;
  cin >> n >> m;
  long long c[n + 5];
  for (long long i = 1; i <= n; i++) {
    cin >> c[i];
    h[i] = i;
  }
  for (long long i = 1; i <= m; i++) {
    cin >> x >> y;
    p = find(x);
    q = find(y);
    if (p == q) continue;
    h[q] = p;
    c[p] = min(c[p], c[q]);
  }
  for (long long i = 1; i <= n; i++)
    if (h[i] == i) ans += c[i];
  cout << ans;
  return 0;
}
