#include <bits/stdc++.h>
using namespace std;
const long long NMAX = 200000;
const long long LOGN = 17;
const long long INF = (1LL << 62);
map<long long, long long> MP;
long long gr[NMAX + 2], tt[NMAX + 2], best[NMAX + 2], Ans = 0, c[NMAX + 2];
long long N, M;
long long ROOT(long long nod) {
  if (tt[nod] == nod) return nod;
  return tt[nod] = ROOT(tt[nod]);
}
void UNION(long long x, long long y) {
  if (gr[x] > gr[y]) {
    gr[x] += gr[y];
    tt[y] = x;
  } else {
    gr[y] += gr[x];
    tt[x] = y;
  }
}
int main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);
  cin >> N >> M;
  for (long long i = 1; i <= N; ++i)
    cin >> c[i], best[i] = INF, gr[i] = 1, tt[i] = i;
  for (long long i = 1; i <= M; ++i) {
    long long x, y;
    cin >> x >> y;
    if (ROOT(x) != ROOT(y)) {
      UNION(ROOT(x), ROOT(y));
    }
  }
  for (long long i = 1; i <= N; ++i) {
    best[ROOT(i)] = min(best[ROOT(i)], c[i]);
  }
  for (long long i = 1; i <= N; ++i) {
    long long ind = ROOT(i);
    if (MP[ind]) continue;
    MP[ind] = best[ind] + 1;
  }
  for (auto pp : MP) {
    Ans += pp.second - 1;
  }
  cout << Ans << '\n';
  return 0;
}
