#include <bits/stdc++.h>
using namespace std;
int ar[100005], mn;
vector<int> v[100005];
bool vis[100005];
void dfs(int x) {
  vis[x] = 1;
  mn = min(mn, ar[x]);
  for (int i = 0; i < v[x].size(); i++) {
    int u = v[x][i];
    if (vis[u]) continue;
    dfs(u);
  }
  return;
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &ar[i]);
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    v[x].push_back(y);
    v[y].push_back(x);
  }
  long long sum = 0;
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      mn = INT_MAX;
      dfs(i);
      sum += (0ll + mn);
    }
  }
  printf("%lld\n", sum);
  return 0;
}
