#include <bits/stdc++.h>
using namespace std;
int n;
int m;
;
int vis[100005];
int c[100005];
vector<int> v[100005];
int dfs(int i) {
  vis[i] = 1;
  int p = c[i];
  for (int j = 0; j < v[i].size(); j++) {
    if (vis[v[i][j]] == 0) p = min(p, dfs(v[i][j]));
  }
  return (p);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  int x, y;
  for (int i = 1; i <= n; i++) {
    cin >> c[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  long long int mn = 0;
  memset(vis, 0, sizeof(vis));
  for (int i = 1; i <= n; i++) {
    if (vis[i] == 0) {
      mn += dfs(i);
    }
  }
  cout << mn;
  return (0);
}
