#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> a;
vector<vector<int> > graph;
vector<int> used;
int mn = 1000000000;
void dfs(int vertex, int k) {
  used[vertex] = k;
  if (a[vertex] < mn) mn = a[vertex];
  for (vector<int>::iterator i = graph[vertex].begin();
       i != graph[vertex].end(); i++) {
    if (!used[*i]) dfs(*i, k);
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  graph.resize(n);
  used.resize(n, 0);
  a.resize(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < m; i++) {
    int var1, var2;
    cin >> var1 >> var2;
    graph[var1 - 1].push_back(var2 - 1);
    graph[var2 - 1].push_back(var1 - 1);
  }
  int k = 1;
  long long sum = 0;
  for (int i = 0; i < n; i++)
    if (used[i] == 0) {
      mn = 1000000000;
      dfs(i, k);
      sum += mn;
      k++;
    }
  cout << sum;
  return 0;
}
