#include <bits/stdc++.h>
using namespace std;
long long powi(long long base, int p) {
  long long res = 1;
  while (p--) res *= base;
  return res;
}
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
bool is_vowel(char c) {
  c = tolower(c);
  return c == 'a' || c == 'e' || c == 'o' || c == 'i' || c == 'u' || c == 'y';
}
int used[100001];
vector<int> gr[100001];
void dfs(int v) {
  if (used[v]) return;
  used[v] = 1;
  for (int u : gr[v]) {
    dfs(u);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> c(n);
  for (int i = 0, s; i < n; i++) {
    cin >> s;
    c[i] = {s, i + 1};
  }
  sort(c.begin(), c.end());
  for (int i = 0; i < m; i++) {
    int v, u;
    cin >> v >> u;
    gr[v].push_back(u);
    gr[u].push_back(v);
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    if (used[c[i].second]) continue;
    ans += c[i].first;
    dfs(c[i].second);
  }
  cout << ans;
  return 0;
}
