#include <bits/stdc++.h>
using namespace std;
vector<int> E[100005];
int n, m, c[100005], tmp;
bool b[100005];
long long ans;
void dfs(int x) {
  b[x] = true;
  tmp = min(tmp, c[x]);
  for (int j = 0; j < E[x].size(); j++)
    if (!b[E[x][j]]) dfs(E[x][j]);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &c[i]);
  for (int i = 1, u, v; i <= m; i++)
    scanf("%d%d", &u, &v), E[u].push_back(v), E[v].push_back(u);
  for (int i = 1; i <= n; i++)
    if (!b[i]) tmp = 2E9, dfs(i), ans += tmp;
  printf("%I64d", ans);
  return 0;
}
