#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
vector<int> edges[MAXN];
int N, M;
long long A[MAXN];
bool visited[MAXN];
long long dfs(int node) {
  visited[node] = true;
  int l = edges[node].size();
  long long int MIN = A[node];
  for (int i = 0; i < l; ++i) {
    if (visited[edges[node][i]] == false) MIN = min(MIN, dfs(edges[node][i]));
  }
  return MIN;
}
int main() {
  cin >> N >> M;
  for (int i = 1; i <= N; ++i) cin >> A[i];
  for (int i = 1; i <= M; ++i) {
    int u, v;
    cin >> u >> v;
    edges[u].push_back(v);
    edges[v].push_back(u);
  }
  long long res = 0;
  for (int i = 1; i <= N; ++i) {
    if (visited[i] == false) res = res + dfs(i);
  }
  cout << res << endl;
  return 0;
}
