#include <bits/stdc++.h>
using namespace std;
int n, m, g[100010], fa[100010], xiao[100010], a, b;
int xia[100010];
int findf(int x) {
  int z = x;
  int y;
  while (fa[x] != x) x = fa[x];
  while (fa[z] != z) {
    y = fa[z];
    fa[z] = x;
    z = y;
  }
  return x;
}
void unio(int c, int d) {
  int a = findf(c);
  int b = findf(d);
  if (a != b) fa[a] = b;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    fa[i] = i;
    scanf("%d", &g[i]);
    xiao[i] = g[i];
    xia[i] = g[i];
  }
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &a, &b);
    unio(a, b);
  }
  long long sum = 0;
  for (int i = 1; i <= n; i++) {
    g[findf(i)] = min(g[findf(i)], g[i]);
  }
  for (int i = 1; i <= n; i++) {
    if (findf(i) == i) sum += g[i];
  }
  printf("%lld", sum);
  return 0;
}
