#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
int n, m;
long long c[maxn], ans, s;
vector<int> g[maxn];
bool v[maxn];
void dfs(int a) {
  s = min(s, c[a]);
  v[a] = 1;
  for (int i = 0; i < g[a].size(); i++) {
    int b = g[a][i];
    if (!v[b]) dfs(b);
  }
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%lld", &c[i]);
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    g[x].push_back(y);
    g[y].push_back(x);
  }
  ans = 0;
  for (int i = 1; i <= n; i++) {
    if (v[i]) continue;
    s = (1e9) + 1;
    dfs(i);
    ans += s;
  }
  printf("%lld\n", ans);
  return 0;
}
