#include <bits/stdc++.h>
using namespace std;
const long long MAX = 1e5 + 1;
vector<long long> adj[MAX];
vector<long long> val(MAX, 0);
long long dfs(long long src, vector<bool>& vis) {
  vis[src] = true;
  long long a = val[src];
  for (auto child : adj[src]) {
    if (!vis[child]) {
      a = min(a, dfs(child, vis));
    }
  }
  return a;
}
int32_t main() {
  long long n, m;
  cin >> n >> m;
  for (auto i = 1; i <= n; i++) cin >> val[i];
  for (auto i = 0; i < m; i++) {
    long long a, b;
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  long long ans = 0;
  vector<bool> vis(n + 1, false);
  for (auto i = 1; i <= n; i++) {
    if (!vis[i]) {
      ans += dfs(i, vis);
    }
  }
  cout << ans;
  return 0;
}
