#include <bits/stdc++.h>
using namespace std;
map<int, vector<int>> arr;
map<int, bool> visit;
long long price[100005];
int dfs(int src) {
  int mn;
  visit[src] = true;
  mn = price[src];
  for (auto child : arr[src]) {
    if (!visit[child]) {
      mn = min(mn, dfs(child));
    }
  }
  return mn;
}
int main() {
  long long n, m, ans = 0;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> price[i];
  while (m--) {
    int a, b;
    cin >> a >> b;
    arr[a].push_back(b), arr[b].push_back(a);
  }
  for (int i = 1; i <= n; i++) {
    if (!visit[i]) ans += dfs(i);
  }
  cout << ans;
}
