#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
int a[maxn], fa[maxn];
int b[maxn];
int c[maxn];
int n, m;
void init() {
  for (int i = 1; i <= n; ++i) fa[i] = i;
}
int fifa(int x) {
  if (fa[x] == x) return fa[x];
  fa[x] = fifa(fa[x]);
  return fa[x];
}
void Comb(int p, int q) {
  int x = fifa(p);
  int y = fifa(q);
  if (x != y) fa[x] = y;
  return;
}
int main() {
  memset(b, -1, sizeof(b));
  scanf("%d%d", &n, &m);
  init();
  for (int i = 1; i <= n; ++i) scanf("%d", &c[i]);
  for (int i = 1; i <= m; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    Comb(x, y);
  }
  for (int i = 1; i <= n; ++i) {
    int f = fifa(i);
    if (b[f] == -1)
      b[f] = c[i];
    else
      b[f] = min(b[f], c[i]);
  }
  long long ans = 0;
  for (int i = 1; i <= n; ++i) {
    if (b[i] != -1) ans += b[i];
  }
  printf("%lld\n", ans);
  return 0;
}
