#include <bits/stdc++.h>
using namespace std;
long long ar[100001];
long long dfs(vector<long long> v[], long long* visited, long long i) {
  visited[i] = 1;
  long long min = ar[i - 1];
  for (long long j = 0; j < v[i].size(); j++) {
    if (visited[v[i][j]] == 0) {
      long long temp = dfs(v, visited, v[i][j]);
      if (temp < min) min = temp;
    }
  }
  return min;
}
int main() {
  long long n, m;
  cin >> n >> m;
  for (long long i = 0; i < n; i++) cin >> ar[i];
  vector<long long> v[n + 1];
  long long visited[n + 1];
  memset(visited, 0, sizeof(visited));
  for (long long i = 0; i < m; i++) {
    long long x, y;
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  long long count = 0;
  for (long long i = 1; i <= n; i++) {
    if (visited[i] == 0) {
      count += dfs(v, visited, i);
    }
  }
  cout << count;
  return 0;
}
