#include <bits/stdc++.h>
using namespace std;
long long c[100005];
int pre[100005];
int Rank[100005];
int n, m;
long long cost = 0;
map<int, long long> haha;
void init() {
  for (int i = 1; i <= n; i++) {
    pre[i] = i;
    Rank[i] = 0;
  }
}
int Find(int x) {
  if (x == pre[x]) return pre[x];
  return pre[x] = Find(pre[x]);
}
void unite(int x, int y) {
  x = Find(x);
  y = Find(y);
  if (Rank[x] < Rank[y]) {
    pre[x] = y;
  } else {
    pre[y] = x;
    if (Rank[x] == Rank[y]) Rank[x]++;
  }
}
int main() {
  scanf("%d%d", &n, &m);
  init();
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &c[i]);
  }
  for (int i = 0; i < m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    unite(x, y);
  }
  for (int i = 1; i <= n; i++) {
    if (haha[Find(i)] == 0)
      haha[Find(i)] = c[i] + 1;
    else
      haha[Find(i)] = min(haha[Find(i)], c[i] + 1);
  }
  map<int, long long>::iterator it;
  for (it = haha.begin(); it != haha.end(); it++) cost += it->second;
  cost -= haha.size();
  printf("%lld\n", cost);
  return 0;
}
