#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int MOD = 1e9 + 7, MAX = 1e6 + 5;
const long long INF = 1e18 + 5;
vector<vector<int> > A;
vector<int> vis;
vector<int> C;
int dfs(int u) {
  vis[u] = true;
  int ans = C[u];
  for (auto v : A[u]) {
    if (!vis[v]) {
      ans = min(ans, dfs(v));
    }
  }
  return ans;
}
int main() {
  int n, m;
  cin >> n >> m;
  C.resize(n + 1);
  for (int in = 1; in < 1 + n; in++) cin >> C[in];
  A.resize(n + 1);
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    A[u].push_back(v);
    A[v].push_back(u);
  }
  long long ans = 0;
  vis.resize(n + 1);
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      ans += dfs(i);
    }
  }
  cout << ans << endl;
}
