#include <bits/stdc++.h>
using namespace std;
vector<long long int> adj[100000];
bool vis[100000];
long long int c[1000000];
long long int s;
vector<long long> st;
void dfs(long long int start) {
  vis[start] = 1;
  st.push_back(start);
  for (long long int i = 0; i < adj[start].size(); i++) {
    if (!vis[adj[start][i]]) dfs(adj[start][i]);
  }
  return;
}
int main() {
  long long int n, m;
  cin >> n >> m;
  for (long long int i = 0; i < n; i++) cin >> c[i];
  for (long long int i = 1; i <= m; i++) {
    long long int a, b;
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  long long int sum = 0;
  for (long long int i = 1; i <= n; i++) {
    if (!vis[i]) {
      st.clear();
      s = INT_MAX;
      dfs(i);
      for (int j = 0; j < st.size(); j++) {
        s = min(s, c[st[j] - 1]);
      }
      sum += s;
    }
  }
  cout << sum << endl;
  return 0;
}
