#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
vector<int> d[100000 + 1];
long long count1;
long long min(long long a, long long b) {
  if (a > b) return b;
  return a;
}
void dfs(long long visited1, bool visited[], long long a[]) {
  visited[visited1] = true;
  count1 = min(count1, a[visited1]);
  for (int i = 0; i < d[visited1].size(); i++) {
    if (visited[d[visited1][i]] == false) {
      visited[d[visited1][i]] = true;
      dfs(d[visited1][i], visited, a);
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  long long n, m;
  cin >> n >> m;
  long long a[n + 1];
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 0; i < m; i++) {
    long long x, y;
    cin >> x >> y;
    d[x].push_back(y);
    d[y].push_back(x);
  }
  bool visited[n + 1];
  for (int i = 1; i <= n; i++) visited[i] = false;
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    if (visited[i] == false) {
      count1 = INT_MAX;
      dfs(i, &visited[0], a);
      ans += count1;
    }
  }
  cout << ans;
}
