#include <bits/stdc++.h>
using namespace std;
vector<int> v;
int bs(int lo, int hi, int key) {}
string num_to_string(int n) {
  string s;
  while (n) {
    s.push_back((n % 10) - '0');
    n /= 10;
  }
  reverse(s.begin(), s.end());
  return s;
}
vector<int> adj[200000];
long long int ans = 0;
int temp = INT_MAX;
vector<int> costs;
map<int, bool> visited;
void dfs(int node, int s) {
  visited[node] = true;
  temp = min(temp, costs[node - 1]);
  bool flag = false;
  for (int i = 0; i < adj[node].size(); i++)
    if (!visited[adj[node][i]]) dfs(adj[node][i], s);
  if (node == s) {
    ans += temp;
    temp = INT_MAX;
  }
}
void solve() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    costs.push_back(x);
  }
  while (m--) {
    int x, y;
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  for (int i = 1; i <= n; i++)
    if (!visited[i]) dfs(i, i);
  cout << ans << endl;
}
int main() { solve(); }
