#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
vector<int> G[maxn];
int a[maxn];
bool vis[maxn];
long long ans = 0;
int dfs(int x) {
  vis[x] = 1;
  int now = a[x];
  for (int v : G[x]) {
    if (vis[v]) continue;
    now = min(now, dfs(v));
  }
  return now;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = 1; i <= m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    G[u].push_back(v);
    G[v].push_back(u);
  }
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      ans += dfs(i);
    }
  }
  return 0 * printf("%lld\n", ans);
}
