#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> vis(100001);
vector<long long> c(100001);
vector<vector<int> > a(100001);
long long ans = 0;
long long Min = 1e9;
void dfs(int k) {
  vis[k] = 1;
  Min = min(Min, c[k]);
  for (int i = 0; i < a[k].size(); i++) {
    if (!vis[a[k][i]]) dfs(a[k][i]);
  }
}
void solve() {}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> c[i];
  }
  for (int i = 1; i <= m; i++) {
    int x, y;
    cin >> x >> y;
    a[x].push_back(y);
    a[y].push_back(x);
  }
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      Min = 1e9;
      dfs(i);
      ans = ans + Min;
    }
  }
  cout << ans << endl;
}
