#include <bits/stdc++.h>
using namespace std;
int n, m, e;
vector<vector<int> > g;
vector<int> mark, c;
void dfs(int v) {
  mark[v] = 1;
  if (c[v] < e) e = c[v];
  for (int i = 0; i < g[v].size(); i++)
    if (!mark[g[v][i]]) dfs(g[v][i]);
}
int main() {
  cin >> n >> m;
  g = vector<vector<int> >(n);
  mark = c = vector<int>(n);
  for (int i = 0; i < n; i++) {
    g[i].clear();
    mark[i] = 0;
  }
  for (int i = 0; i < n; i++) cin >> c[i];
  int v, u;
  for (int i = 0; i < m; i++) {
    cin >> v >> u;
    v--;
    u--;
    g[v].push_back(u);
    g[u].push_back(v);
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    if (!mark[i]) {
      e = 1000000007;
      dfs(i);
      ans += e;
    }
  }
  cout << ans << "\n";
  return 0;
}
