#include <bits/stdc++.h>
using namespace std;
bool sortin(const pair<long long int, long long int> &e,
            const pair<long long int, long long int> &f) {
  return (e.first < f.first);
}
long long int a, b, c, i, j, k, l, m, n, p, q, r, x, y, z, ts, mn = 10e17,
                                                               mod = 10e8 + 7;
long long int ar[100005], br[100005], xr[100005];
long long int d[102][102];
vector<long long int> v[100005];
map<long long int, long long int> mp;
void dfs(int x) {
  c = min(c, ar[x]);
  mp[x] = 1;
  for (int i = 0; i < v[x].size(); i++) {
    if (mp[v[x][i]] == 0) {
      dfs(v[x][i]);
    }
  }
}
int main() {
  {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
  };
  cin >> n >> m;
  for (long long int i = 1; i <= n; i++) cin >> ar[i];
  for (long long int i = 1; i <= m; i++) {
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  for (long long int i = 1; i <= n; i++) {
    if (!mp[i]) {
      c = 1e18;
      dfs(i);
      k += c;
    }
  }
  cout << k;
}
