#include <bits/stdc++.h>
using namespace std;
vector<long long int> ar[100005];
long long int vis[100005];
long long int mi;
long long int val[100005];
void dfs(long long int a) {
  vis[a] = 1;
  mi = min(val[a], mi);
  for (auto it : ar[a]) {
    if (vis[it] == 0) {
      dfs(it);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n, i, m, a, b, sum = 0;
  cin >> n >> m;
  for (i = 1; i <= n; i++) cin >> val[i];
  for (i = 1; i <= m; i++) {
    cin >> a >> b;
    ar[a].push_back(b);
    ar[b].push_back(a);
  }
  for (i = 1; i <= n; i++) {
    if (vis[i] == 0) {
      mi = INT_MAX;
      dfs(i);
      sum = sum + mi;
    }
  }
  cout << sum << "\n";
  return 0;
}
