#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 100;
const int N = 1e3 + 10;
const int mod = 1e9 + 7;
const long long maxll = 9223372036854775807;
const long long minll = -9223372036854775808;
bool mark[maxn];
vector<long long> a_list[maxn];
long long coin[maxn];
long long tmp;
long long dfs(long long n, long long mn) {
  mark[n] = true;
  mn = min(mn, coin[n]);
  for (long long e : a_list[n])
    if (not mark[e]) {
      tmp = dfs(e, mn);
      mn = min(mn, tmp);
    }
  return mn;
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  long long n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> coin[i];
  for (int i = 0; i < m; i++) {
    long long a, b;
    cin >> a >> b;
    a_list[a].emplace_back(b);
    a_list[b].emplace_back(a);
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    if (not mark[i]) ans += dfs(i, maxll);
  }
  cout << ans;
  return 0;
}
