#include <bits/stdc++.h>
using namespace std;
vector<int> adj[100009], cost(100009), vis(100009);
int mini = INT_MAX;
void dfs(int node) {
  if (vis[node]) return;
  vis[node] = 1;
  mini = min(mini, cost[node]);
  for (auto u : adj[node]) {
    dfs(u);
  }
}
void solve() {
  int n, m;
  long long ans = 0;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> cost[i];
  for (int i = 0; i < m; i++) {
    int n1, n2;
    cin >> n1 >> n2;
    adj[n1].push_back(n2);
    adj[n2].push_back(n1);
  }
  for (int i = 1; i <= n; i++) {
    if (vis[i] == 0) {
      dfs(i);
      ans += mini, mini = INT_MAX;
    }
  }
  cout << ans << '\n';
}
int main() {
  solve();
  return 0;
}
