#include <bits/stdc++.h>
using namespace std;
const long long h = 1e9 + 5;
const int N = 1e5 + 5;
long long cost[N], mini = h;
vector<int> adj[N];
bool vis[N];
void dfs(int node) {
  vis[node] = true;
  if (cost[node] < mini) mini = cost[node];
  for (int child : adj[node]) {
    if (vis[child] == false) {
      vis[child] = true;
      dfs(child);
    }
  }
}
int main() {
  int n, m, x, y;
  long long tot = 0;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> cost[i];
  while (m--) {
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  for (int i = 1; i <= n; i++) {
    if (vis[i] == false) {
      dfs(i);
      tot += mini;
    }
    mini = h;
  }
  cout << tot;
  return 0;
}
