#include <bits/stdc++.h>
using namespace std;
const long long OO = 1e8;
const long long OOL = 1e16;
const long long MOD = 1e9 + 7;
const double EPS = 1e-9;
unsigned long long gcd(unsigned long long a, unsigned long long b) {
  return (b == 0 ? a : gcd(b, a % b));
}
unsigned long long lcm(unsigned long long a, unsigned long long b) {
  return (a * (b / gcd(a, b)));
}
long long N, K;
void printVec(vector<int> v2) {
  for (int i = 0; i < (int)v2.size(); ++i) cout << v2[i] << " ";
  cout << endl;
}
vector<bool> visited;
vector<int> bribe;
vector<vector<long long> > friends;
long long dfs(int node) {
  visited[node] = true;
  long long mn = bribe[node];
  for (int i = 0; i < friends[node].size(); i++)
    if (!visited[friends[node][i]]) mn = min(mn, dfs(friends[node][i]));
  return mn;
}
int main() {
  int x, y;
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> N >> K;
  friends = vector<vector<long long> >(N + 1);
  visited = vector<bool>(N + 1, false);
  long long nb = 0;
  bribe.push_back(0);
  for (int i = 0; i < N; i++) cin >> x, bribe.push_back(x);
  for (int i = 0; i < K; i++) {
    cin >> x >> y;
    friends[x].push_back(y);
    friends[y].push_back(x);
  }
  for (int i = 1; i <= N; i++)
    if (!visited[i]) nb += dfs(i);
  cout << nb;
}
