#include <bits/stdc++.h>
using namespace std;
void retcomp(unordered_map<int, int>* edge, int n,
             unordered_map<int, int>& visited, int start) {
  visited[start] = 1;
  for (auto i : edge[start]) {
    if (!visited.count(i.first)) {
      retcomp(edge, n, visited, i.first);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> p(n);
  unordered_map<int, int> edge[n];
  for (int i = 0; i < n; i++) {
    cin >> p[i];
  }
  for (int i = 0; i < m; i++) {
    int f, s;
    cin >> f >> s;
    f--;
    s--;
    edge[f][s] = 1;
    edge[s][f] = 1;
  }
  long long value = 0;
  vector<set<int>> components;
  unordered_map<int, int> whole;
  for (int i = 0; i < n; i++) {
    unordered_map<int, int> visited;
    if (!whole.count(i)) {
      retcomp(edge, n, visited, i);
      set<int> s1;
      for (auto it : visited) {
        s1.insert(p[it.first]);
        whole[it.first] = 1;
      }
      value += *s1.begin();
    }
  }
  cout << value << endl;
  return 0;
}
