#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
vector<int> adj[(int)1e5 + 5];
bool vis[(int)1e5 + 5];
int weights[(int)1e5 + 5];
long long mini = 1e18;
void dfs(int node) {
  vis[node] = true;
  mini = min((long long)weights[node], mini);
  for (auto child : adj[node]) {
    if (vis[child] == false) {
      dfs(child);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long nodes, edges;
  cin >> nodes >> edges;
  for (int i = 1; i <= nodes; i++) {
    int x;
    cin >> x;
    weights[i] = x;
  }
  for (int i = 0; i < edges; i++) {
    int x, y;
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  long long sum = 0;
  for (int i = 1; i <= nodes; i++) {
    if (vis[i] == false) {
      mini = 1e9;
      dfs(i);
      sum += mini;
    }
  }
  cout << sum;
  return 0;
}
