#include <bits/stdc++.h>
using namespace std;
const int oo = 0x3f3f3f3f;
const int maxn = 1e5 + 10;
int n, m, val[maxn];
bool memo[maxn];
vector<int> adj[maxn];
int keep;
void DFS(int idx) {
  keep = min(keep, val[idx]);
  memo[idx] = true;
  for (auto& u : adj[idx]) {
    if (!memo[u]) {
      DFS(u);
    }
  }
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> val[i];
  }
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    keep = oo;
    if (!memo[i]) DFS(i);
    if (keep != oo) ans += keep;
  }
  cout << ans << endl;
}
