#include <bits/stdc++.h>
using namespace std;
const int MXN = 1e5 + 10;
int n, m, r, t, p, A[MXN], M[MXN];
long long c;
vector<int> V[MXN];
int DFS(int nd) {
  int Mn = A[nd];
  M[nd] = 1;
  for (int i = 0; i < V[nd].size(); i++) {
    if (M[V[nd][i]] == 1) continue;
    Mn = min(Mn, DFS(V[nd][i]));
  }
  return (Mn);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &A[i]);
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &r, &t);
    V[r].push_back(t);
    V[t].push_back(r);
  }
  for (int i = 1; i <= n; i++) {
    if (M[i] == 1) continue;
    c += DFS(i);
  }
  printf("%I64d", c);
  return (0);
}
