#include <bits/stdc++.h>
using namespace std;
vector<long long int> adj[100005];
long long int vis[100005] = {0};
long long int ans;
void dfs(long long int x, long long int arr[]) {
  vis[x] = 1;
  ans = min(ans, arr[x]);
  for (long long int j = 0; j < adj[x].size(); j++) {
    long long int i = adj[x][j];
    if (vis[i] == 0) {
      dfs(i, arr);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int n, m;
  cin >> n >> m;
  long long int arr[n + 1];
  for (int a = 1; a <= n; a++) cin >> arr[a];
  for (long long int a = 0; a < m; a++) {
    long long int x, y;
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  long long int x = 0;
  for (int a = 1; a <= n; a++) {
    if (vis[a] == 0) {
      ans = 999999999999;
      dfs(a, arr);
      x += ans;
    }
  }
  cout << x;
  return 0;
}
