#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using namespace std;
template <typename T>
istream &operator>>(istream &in, vector<T> &v) {
  for (auto &i : v) in >> i;
  return in;
}
template <typename T>
ostream &operator<<(ostream &out, vector<T> &v) {
  if (is_same<T, pair<int, int>>::value) {
    for (auto &i : v) out << i << endl;
  } else {
    for (auto &i : v) out << i << " ";
  }
  return out;
}
template <typename T, typename V>
ostream &operator<<(ostream &out, pair<T, V> &v) {
  out << v.first << " " << v.second;
  return out;
}
template <typename T, typename V>
istream &operator>>(istream &in, pair<T, V> &v) {
  in >> v.first >> v.second;
  return in;
}
vector<bool> used;
vector<vector<int>> gr;
void dfs(int x) {
  used[x] = true;
  for (auto &v : gr[x]) {
    if (!used[v]) dfs(v);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  ll ans = 0;
  cin >> n >> m;
  vector<pair<int, int>> c(n);
  gr.resize(n);
  used.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> c[i].first;
    c[i].second = i;
  }
  sort((c).begin(), (c).end());
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    gr[u].push_back(v);
    gr[v].push_back(u);
  }
  for (auto &[v, i] : c) {
    if (!used[i]) {
      ans += v;
      dfs(i);
    }
  }
  cout << ans << endl;
}
