#include <bits/stdc++.h>
using namespace std;
void fastscan(long long &x) {
  bool neg = false;
  register long long c;
  x = 0;
  c = getchar();
  if (c == '-') {
    neg = true;
    c = getchar();
  }
  for (; (c > 47 && c < 58); c = getchar()) x = (x << 1) + (x << 3) + c - 48;
  if (neg) x *= -1;
}
string alpha = "abcdefghijklmnopqrstuvwxyz";
const long long mod = 1e9 + 7;
const long long inf = 2e18 + 5;
const long long nax = 100010;
const long long mod1 = 998244353;
vector<long long> c;
vector<vector<long long>> adj;
vector<bool> vis(100001, false);
long long bfs(long long start) {
  long long count = c[start - 1];
  queue<long long> q;
  q.push(start);
  vis[start] = true;
  while (!q.empty()) {
    long long s = q.front();
    q.pop();
    for (auto u : adj[s]) {
      if (vis[u]) continue;
      vis[u] = true;
      count = min(count, c[u - 1]);
      q.push(u);
    }
  }
  return count;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, m;
  cin >> n >> m;
  adj = vector<vector<long long>>(n + 1);
  c = vector<long long>(n + 1);
  for (long long i = (0); i < (n); i++) cin >> c[i];
  for (long long i = (0); i < (m); i++) {
    long long x, y;
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  long long ans = 0;
  for (long long i = (1); i < (n + 1); i++) {
    if (!vis[i]) ans += bfs(i);
  }
  cout << ans;
  return 0;
}
