#include <bits/stdc++.h>
using namespace std;
vector<long long> graph[100005];
vector<long long> gold;
bool vis[100005];
long long mn = 1e15;
long long BFS(long long src) {
  queue<long long> q;
  q.push(src);
  vis[src] = true;
  while (!q.empty()) {
    long long p = q.front();
    mn = min(mn, gold[p - 1]);
    q.pop();
    for (long long i = 0; i < graph[p].size(); i++) {
      if (!vis[graph[p][i]]) {
        vis[graph[p][i]] = true;
        q.push(graph[p][i]);
      }
    }
  }
  return mn;
}
int main() {
  long long n, m, x, u, v;
  cin >> n >> m;
  for (long long i = 0; i < n; i++) {
    cin >> x;
    gold.push_back(x);
  }
  for (long long i = 0; i < m; i++) {
    cin >> u >> v;
    graph[u].push_back(v);
    graph[v].push_back(u);
  }
  long long sum = 0;
  for (long long i = 1; i <= n; i++) {
    if (!vis[i]) {
      sum += BFS(i);
      mn = 1e15;
    }
  }
  printf("%lld\n", sum);
}
