#include <bits/stdc++.h>
using namespace std;
const long long maxn = 100005;
const long long N = 100005;
std::vector<long long> G[N];
long long vis[N] = {0};
long long mi = 1000000000000009;
long long a[N];
void dfs(long long s) {
  vis[s] = 1;
  mi = min(a[s], mi);
  for (auto c : G[s]) {
    if (vis[c] == 1) continue;
    dfs(c);
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false), cin.tie(nullptr);
  ;
  long long t = 1;
  while (t--) {
    long long n, m;
    cin >> n >> m;
    for (long long i = 1; i <= n; i++) cin >> a[i];
    for (long long i = 1; i <= m; i++) {
      long long x, y;
      cin >> x >> y;
      G[x].push_back(y), G[y].push_back(x);
    }
    long long cost = 0;
    for (long long i = 1; i <= n; i++) {
      mi = 1000000000000009;
      if (!vis[i]) dfs(i), cost += mi;
    }
    cout << cost;
    cout << endl;
    ;
  }
}
