#include <bits/stdc++.h>
using namespace std;
const int LIM = 1e5 + 10;
int men_group[LIM], root[LIM];
bool vis[LIM] = {};
int find(int a) {
  if (a == root[a]) return a;
  return root[a] = find(root[a]);
}
void join(int a, int b) {
  a = find(a);
  b = find(b);
  if (a != b) {
    if (men_group[a] < men_group[b])
      root[b] = a;
    else
      root[a] = b;
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  for (int i = 1; i <= N; i++) {
    root[i] = i;
    cin >> men_group[i];
  }
  int a, b;
  while (M--) {
    cin >> a >> b;
    join(a, b);
  }
  long long ans = 0;
  for (int i = 1, j; i <= N; i++) {
    j = find(i);
    if (vis[j] == 0) {
      vis[j] = 1;
      ans += men_group[j];
    }
  }
  cout << ans << "\n";
  return 0;
}
