#include <bits/stdc++.h>
using namespace std;
long long dfs[1000005] = {0};
long long cost[1000005] = {0};
const long long mod = 1000000007;
vector<long long> v[100009], v2;
long long fun(long long n) {
  if (cost[n] == -1) return 1e10;
  long long cos = cost[n], i;
  cost[n] = -1;
  for (i = 0; i < v[n].size(); i++) {
    if (cost[v[n][i]] == -1)
      continue;
    else {
      cos = min(cos, fun(v[n][i]));
    }
  }
  return cos;
}
int main() {
  long long n, m, ansa = 0, ansb = 0, temp, i, j, k, flag = 2, flag2 = 1e6, a,
                  b;
  vector<pair<long long, long long> > vp;
  string st, st2, st3;
  queue<long long> q1;
  cin >> n >> m;
  for (i = 1; i <= n; i++) {
    cin >> cost[i];
  }
  for (i = 0; i < m; i++) {
    cin >> a >> b;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  for (i = 1; i <= n; i++) {
    if (cost[i] == -1)
      continue;
    else if (v[i].size() == 0) {
      ansa += cost[i];
    } else {
      ansa += fun(i);
    }
  }
  cout << ansa;
  return 0;
}
