#include <bits/stdc++.h>
using namespace std;
vector<long long> arr[600000];
long long par[600000];
bool vis[600000];
long long cost[500000];
void add_edge(long long u, long long v) {
  arr[u].push_back(v);
  arr[v].push_back(u);
}
void dfs(long long node, long long p, long long &c) {
  vis[node] = true;
  c = min(c, cost[node]);
  for (auto child : arr[node]) {
    if (!vis[child]) dfs(child, node, c);
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, m;
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) cin >> cost[i];
  for (long long i = 0; i < m; i++) {
    long long u, v;
    cin >> u >> v;
    add_edge(u, v);
  }
  long long ans = 0;
  for (long long i = 1; i <= n; i++) {
    if (vis[i] == false) {
      long long c = 1000000009;
      dfs(i, 0, c);
      ans += c;
    }
  }
  cout << ans << endl;
  return 0;
}
