#include <bits/stdc++.h>
using namespace std;
vector<long long> adj[1000002];
bool vis[10000002];
vector<long long> lolz;
void dfs(long long u) {
  vis[u] = true;
  lolz.push_back(u);
  for (int i = 0; i < adj[u].size(); i++) {
    int v = adj[u][i];
    if (vis[v] == false) {
      dfs(v);
    }
  }
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<long long> lol;
  for (int i = 0; i < n; i++) {
    int p;
    ;
    cin >> p;
    lol.push_back(p);
  }
  for (int i = 0; i < m; i++) {
    long long u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  long long t = 0, sum = 0;
  for (int i = 1; i <= n; i++) {
    if (vis[i] == false) {
      dfs(i);
    }
    long long minim = 1000000000000000;
    for (int j = t; j < lolz.size(); j++) {
      long long p = lol[lolz[j] - 1];
      if (p < minim) minim = p;
      if (j == lolz.size() - 1) t = lolz.size();
    }
    if (minim != 1000000000000000) sum += minim;
  }
  cout << sum << endl;
  return 0;
}
