#include <bits/stdc++.h>
using namespace std;
void c_p_c() {}
const int no = (int)1e6;
vector<int> graph[no];
vector<bool> visited(no);
vector<int> bribe(no);
int mn;
void dfs(int source) {
  visited[source] = 1;
  mn = min(mn, bribe[source]);
  for (int a : graph[source]) {
    if (!visited[a]) dfs(a);
  }
}
int main(int argc, char const *argv[]) {
  c_p_c();
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int node, edges;
  cin >> node >> edges;
  int u, v;
  for (int i = 1; i <= node; i++) {
    cin >> bribe[i];
  }
  for (int i = 0; i < edges; i++) {
    cin >> u >> v;
    graph[u].push_back(v);
    graph[v].push_back(u);
  }
  long long sum = 0;
  for (int i = 1; i <= node; i++) {
    if (!visited[i]) {
      mn = INT_MAX;
      dfs(i);
      sum += mn;
    }
  }
  cout << sum << endl;
  return 0;
}
