#include <bits/stdc++.h>
using namespace std;
const long long N = 100005;
const long long M = 1000000007;
long long dfs(long long st, vector<vector<long long> > &v, vector<bool> &visit,
              long long m, long long a[]) {
  if (visit[st]) return M;
  visit[st] = true;
  for (long long i = 0; i < v[st].size(); i++) {
    m = min(m, dfs(v[st][i], v, visit, a[v[st][i]], a));
  }
  return m;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, m;
  cin >> n >> m;
  long long a[n + 1];
  a[0] = (-1);
  for (long long i = 1; i < n + 1; i++) {
    cin >> a[i];
  }
  vector<vector<long long> > v(n + 1);
  vector<bool> visit(n + 1, false);
  long long x, y;
  for (long long i = 0; i < m; i++) {
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  long long ans = 0;
  long long x2;
  for (long long i = 1; i < n + 1; i++) {
    x2 = dfs(i, v, visit, a[i], a);
    if (x2 == M) continue;
    ans += x2;
  }
  cout << ans << endl;
  return 0;
}
