#include <bits/stdc++.h>
using namespace std;
int dp[100001][21][27];
int cnt[27][21];
vector<int> v[100001];
int vis[100001];
int a[100001];
int val;
void dfs(int x) {
  vis[x] = 1;
  if (a[x] < val) val = a[x];
  for (int i = 0; i < v[x].size(); i++) {
    if (vis[v[x][i]] == 0) dfs(v[x][i]);
  }
}
signed main() {
  int n, m;
  cin >> n >> m;
  map<int, int> mp;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    mp[a[i]] = i;
  }
  while (m--) {
    int x, y;
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  long long int sum = 0;
  for (int i = 1; i <= n; i++) {
    if (vis[i] != 1) {
      val = INT_MAX;
      dfs(i);
      sum += val;
    }
  }
  cout << sum << endl;
}
