#include <bits/stdc++.h>
using namespace std;
long long n, m, min_c, ans = 0, c[100100];
vector<long long> g[100100];
bool vis[100100];
void dfs(long long v, long long &min_c) {
  vis[v] = 1;
  min_c = min(min_c, c[v]);
  for (auto i : g[v]) {
    if (!vis[i]) {
      dfs(i, min_c);
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  long long a, b;
  for (long long i = 1; i <= n; i++) cin >> c[i];
  while (m--) {
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  for (long long i = 1; i <= n; i++) {
    min_c = 1001001001;
    if (!vis[i]) {
      dfs(i, min_c);
      ans += min_c;
    }
  }
  cout << ans << "\n";
  return 0;
}
