#include <bits/stdc++.h>
using namespace std;
vector<int> adj[100005];
bool visited[100005];
long long a[100005], pre = LLONG_MAX;
void dfs(int u, int p) {
  if (visited[u]) return;
  visited[u] = 1;
  pre = min(pre, a[u]);
  for (int v = 0; v < adj[u].size(); v++) {
    if (adj[u][v] == p) continue;
    if (!visited[adj[u][v]]) dfs(adj[u][v], u);
  }
}
int main() {
  memset(visited, 0, sizeof(visited));
  int n, m, i;
  scanf("%d %d", &n, &m);
  for (i = 1; i <= n; i++) {
    scanf("%I64d", &a[i]);
  }
  for (i = 1; i <= m; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    adj[u].push_back(v), adj[v].push_back(u);
  }
  long long ans = 0;
  for (i = 1; i <= n; i++) {
    pre = LLONG_MAX;
    if (!visited[i]) dfs(i, -1), ans += pre;
  }
  printf("%I64d\n", ans);
  return 0;
}
