#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
int par[MAXN], cost[MAXN], Rank[MAXN];
int n, m;
set<int> book;
vector<int> llog[MAXN];
void init(int n) {
  for (int i = 1; i <= n; i++) {
    par[i] = i;
    Rank[i] = 1;
  }
}
int find(int x) {
  if (par[x] == x)
    return x;
  else {
    return par[x] = find(par[x]);
  }
}
void unite(int x, int y) {
  x = find(x);
  y = find(y);
  if (x == y) return;
  if (Rank[x] < Rank[y]) {
    par[x] = y;
  } else {
    par[y] = x;
    if (Rank[x] == Rank[y]) {
      Rank[x]++;
    }
  }
}
int main() {
  scanf("%d%d", &n, &m);
  init(n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &cost[i]);
  }
  int u, v;
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &u, &v);
    unite(u, v);
  }
  for (int i = 1; i <= n; i++) {
    book.insert(find(i));
    llog[find(i)].push_back(i);
  }
  long long ans = 0;
  for (int i : book) {
    int _min = cost[llog[i][0]];
    for (int j = 0; j < llog[i].size(); j++) _min = min(_min, cost[llog[i][j]]);
    ans += _min;
  }
  printf("%lld\n", ans);
  return 0;
}
