#include <bits/stdc++.h>
using namespace std;
vector<int> g[100005];
bool vis[100005];
long long min_val;
void dfs(int v, long long* arr) {
  min_val = min(arr[v], min_val);
  vis[v] = true;
  for (int i = 0; i < g[v].size(); i++) {
    int neig = g[v][i];
    if (!vis[neig]) {
      dfs(neig, arr);
    }
  }
}
int main() {
  std::ios::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m, x, y;
  cin >> n >> m;
  long long* v = new long long[n + 1]();
  for (int i = 1; i <= n; i++) {
    cin >> v[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  long long ans = 0;
  memset(vis, false, sizeof(vis));
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      min_val = LONG_MAX;
      dfs(i, v);
      ans += min_val;
    }
  }
  cout << ans;
  return 0;
}
