#include <bits/stdc++.h>
using namespace std;
const int MAX = (int)1e5 + 55;
const int INF = (int)1e9 + 77;
const int MOD = (int)1e9 + 7;
const double PI = 2 * acos(0.0);
const double EPS = 1e-7;
const int N = (int)1e5 + 5;
vector<vector<int>> adj;
pair<int, int> cost[N];
int mn;
bool vis[N];
long long ans;
void dfs(int u) {
  if (vis[u]) return;
  vis[u] = 1;
  mn = min(mn, cost[u].first);
  for (int v : adj[u]) dfs(v);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  adj.resize(n + 1);
  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;
    cost[i] = {x, i};
  }
  for (int i = 0; i < m; ++i) {
    int x, y;
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  for (int i = 1; i <= n; ++i) {
    int cur = cost[i].second;
    if (vis[cur]) continue;
    mn = INF;
    dfs(cur);
    ans += mn;
  }
  cout << ans;
  return 0;
}
