#include <bits/stdc++.h>
using namespace std;
int n, m, a[100005];
int pre[100005];
int b[100005];
int findd(int x) { return x == pre[x] ? x : pre[x] = findd(pre[x]); }
void join(int x, int y) {
  int xx = findd(x), yy = findd(y);
  pre[xx] = yy;
}
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) pre[i] = i;
  for (int i = 1; i <= n; i++) b[i] = 2e9;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= m; i++) {
    int x, y;
    cin >> x >> y;
    join(x, y);
  }
  for (int i = 1; i <= n; i++) {
    b[findd(i)] = min(b[findd(i)], a[i]);
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    if (findd(i) == i) ans += b[i];
  }
  cout << ans << endl;
  return 0;
}
