#include <bits/stdc++.h>
using namespace std;
using namespace std;
int n, m;
vector<long long> bribe(100001);
vector<vector<int>> graph(100001);
vector<bool> visited(100001, false);
long long min_bribe(int node) {
  long long ans = bribe[node];
  visited[node] = true;
  for (int adjacent : graph[node]) {
    if (!visited[adjacent]) {
      ans = min(ans, min_bribe(adjacent));
    }
  }
  return ans;
}
int main() {
  cin >> n >> m;
  for (int node = 1; node <= n; ++node) cin >> bribe[node];
  for (int i = 0; i < m; ++i) {
    int x, y;
    cin >> x >> y;
    graph[x].push_back(y);
    graph[y].push_back(x);
  }
  long long ans = 0;
  for (int node = 1; node <= n; ++node) {
    if (!visited[node]) {
      ans += min_bribe(node);
    }
  }
  cout << ans << '\n';
}
