#include <bits/stdc++.h>
using namespace std;
long long int n, m, c[100005], b[100005], t, ans;
vector<long long int> v[100005];
void DFS(long long int second) {
  t = min(t, c[second]);
  b[second] = 1;
  for (long long int i = 0; i < v[second].size(); i++) {
    if (b[v[second][i]] == 0) DFS(v[second][i]);
  }
}
int main() {
  cin >> n >> m;
  for (long long int i = 1; i <= n; i++) cin >> c[i];
  for (long long int i = 1; i <= m; i++) {
    long long int x, y;
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  for (long long int i = 1; i <= n; i++) {
    if (b[i] == 0) {
      t = 1000000001;
      DFS(i);
      ans += t;
    }
  }
  cout << ans;
  return 0;
}
