#include <bits/stdc++.h>
using namespace std;
using lli = int64_t;
const int maxN = 100010;
vector<int> adj[maxN];
int input[maxN];
bool visited[maxN];
int cost = INT_MAX;
void dfs(int node) {
  visited[node] = true;
  cost = min(cost, input[node]);
  for (auto child : adj[node]) {
    if (!visited[child]) {
      dfs(child);
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int T = 1;
  for (int t = 1; t <= T; t++) {
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
      cin >> input[i];
    }
    for (int i = 1; i <= m; i++) {
      int u, v;
      cin >> u >> v;
      adj[u].push_back(v);
      adj[v].push_back(u);
    }
    int64_t total_cost = 0;
    for (int i = 1; i <= n; i++) {
      cost = input[i];
      if (!visited[i]) {
        dfs(i);
        total_cost += cost;
      }
    }
    cout << total_cost << "\n";
  }
}
