#include <bits/stdc++.h>
using namespace std;
bool vis[900001];
vector<int> adj[900001];
long long n, m, minl = 1e9, arr[900001], ans = 0;
void dfs(int x) {
  if (vis[x]) return;
  vis[x] = 1;
  minl = min(minl, arr[x]);
  for (auto u : adj[x]) {
    dfs(u);
  }
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
  }
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      dfs(i);
      ans += minl;
      minl = 1e9;
    }
  }
  cout << ans << endl;
}
