#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5;
long long father[maxn];
long long cnt[maxn];
int find(int x) { return father[x] == x ? x : father[x] = find(father[x]); }
int main() {
  long long n, m;
  long long mon[maxn];
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    father[i] = i;
    cin >> mon[i];
  }
  long long a, b;
  for (int i = 1; i <= m; i++) {
    cin >> a >> b;
    father[find(a)] = find(b);
  }
  long long ans = 0;
  memset(cnt, 0, sizeof(cnt));
  for (int i = 1; i <= n; i++) {
    if (find(i) == i) {
      cnt[i] = 1e9;
    }
  }
  for (int i = 1; i <= n; i++) {
    cnt[find(i)] = min(cnt[find(i)], mon[i]);
  }
  for (int i = 1; i <= n; i++) {
    if (find(i) == i) {
      ans += cnt[i];
    }
  }
  cout << ans << endl;
  return 0;
}
