#include <bits/stdc++.h>
using namespace std;
vector<int> c(100001);
vector<vector<int> > g(100001);
vector<int> color(100001);
vector<int> ans(100001, 1e9);
int t = 1;
void dfs(int u) {
  color[u] = t;
  ans[t] = min(ans[t], c[u]);
  for (auto i : g[u])
    if (color[i] == 0) dfs(i);
}
int main() {
  ios_base::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) cin >> c[i];
  for (int i = 1; i <= m; ++i) {
    int x, y;
    cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  for (int i = 1; i <= n; ++i)
    if (color[i] == 0) {
      dfs(i);
      ++t;
    }
  long long sum = 0;
  for (int i = 1; i < t; ++i) sum += ans[i];
  cout << sum;
  return 0;
}
