#include <bits/stdc++.h>
const long double PI = 3.141592653589793238L;
using namespace std;
long long c[200005], N, M, vis[200005], res = 0, m;
vector<long long> graph[200005];
void dfs(int x) {
  if (vis[x]) return;
  m = min(m, c[x]);
  vis[x] = 1;
  for (int y : graph[x]) dfs(y);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> N >> M;
  for (int i = 0; i < N; ++i) cin >> c[i];
  while (M--) {
    int x, y;
    cin >> x >> y;
    --x, --y;
    graph[x].push_back(y);
    graph[y].push_back(x);
  }
  for (int i = 0; i < N; ++i)
    if (!vis[i]) {
      m = 3e9;
      dfs(i);
      res += m;
    }
  cout << res;
  return 0;
}
