#include <bits/stdc++.h>
using namespace std;
const long long int inf = 1e18;
const int32_t m = 1e9 + 7;
const int32_t mm = 998244353;
vector<vector<long long int>> adj;
vector<long long int> vis;
vector<long long int> cost;
long long int bfs(long long int node) {
  long long int min_cost = inf;
  queue<long long int> q;
  q.push(node);
  vis[node] = 1;
  min_cost = min(min_cost, cost[node]);
  while (!q.empty()) {
    long long int curr = q.front();
    min_cost = min(min_cost, cost[curr]);
    q.pop();
    for (auto &x : adj[curr]) {
      if (!vis[x]) {
        vis[x] = 1;
        q.push(x);
      }
    }
  }
  return min_cost;
}
void maxifier() {
  long long int n, m;
  cin >> n >> m;
  adj.resize(n + 1);
  vis.resize(n + 1);
  cost.resize(n + 1);
  for (long long int i = 1; i <= n; i++) {
    cin >> cost[i];
  }
  for (long long int i = 0; i < m; i++) {
    long long int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  long long int ans = 0;
  for (long long int i = 1; i <= n; i++) {
    if (!vis[i]) {
      ans += bfs(i);
    }
  }
  cout << ans << "\n";
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int tc, t = 0;
  tc = 1;
  while (tc--) {
    maxifier();
  }
  return 0;
}
