#include <bits/stdc++.h>
const long long MXN = 1e6 + 1;
const long long MNN = 1e3 + 1;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
using namespace std;
long long n, b[MXN], ans, cnt, x, mn = INF, m, u, v;
bool used[MXN];
vector<long long> g[MXN];
void dfs(long long l) {
  used[l] = true;
  mn = min(b[l], mn);
  for (int i = 0; i < g[l].size(); i++) {
    long long to = g[l][i];
    if (used[to] == 0) {
      dfs(to);
    }
  }
}
int main() {
  ios_base::sync_with_stdio, cout.tie(0), cin.tie(0);
  ;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
  }
  for (int i = 1; i <= m; i++) {
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  for (int i = 1; i <= n; i++) {
    mn = INF;
    if (used[i] == false) {
      dfs(i);
      ans += mn;
    }
  }
  cout << ans;
  return 0;
}
