#include <bits/stdc++.h>
using namespace std;
long long int minn = 1000000009;
vector<int> adj[100005];
bool vis[100005] = {0};
long long int arr[100005];
void dfs(int i) {
  vis[i] = 1;
  minn = min(minn, arr[i]);
  for (auto x : adj[i]) {
    if (!vis[x]) dfs(x);
  }
}
void test_case() {
  int n, m, a, b;
  long long int sum = 0;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
  }
  for (int i = 1; i <= m; i++) {
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  for (int i = 1; i <= n; i++) {
    minn = 1000000009;
    if (!vis[i]) {
      dfs(i);
      sum += minn;
    }
  }
  cout << sum << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  long long int t;
  t = 1;
  while (t--) {
    test_case();
  }
}
