#include <bits/stdc++.h>
using namespace std;
vector<vector<long long int>> adj;
vector<long long int> cost;
vector<long long int> visited;
long long int dfs(long long int u) {
  long long int ans = cost[u];
  visited[u] = true;
  for (auto v : adj[u]) {
    if (!visited[v]) {
      ans = min(ans, dfs(v));
    }
  }
  return ans;
}
void solve(long long int T) {
  long long int n, m;
  cin >> n >> m;
  adj.resize(n);
  cost.resize(n);
  visited.resize(n);
  for (long long int i = 0; i < n; i++) cin >> cost[i];
  for (long long int i = 0; i < m; i++) {
    long long int x, y;
    cin >> x >> y;
    x--, y--;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  long long int ans = 0;
  for (long long int i = 0; i < n; i++) {
    if (!visited[i]) ans += dfs(i);
  }
  cout << ans << endl;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int T = 1;
  for (long long int t = 1; t <= T; t++) {
    solve(t);
  }
  cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
  return 0;
}
