#include <bits/stdc++.h>
using namespace std;
long long int sum, ans, mx, mn = 100000000, pos;
vector<int> v[100001];
int used[100001], a[100001];
void dfs(int u) {
  used[u] = 1;
  if (a[u] < mn) {
    mn = a[u];
  }
  for (int i = 0; i < v[u].size(); i++) {
    int to = v[u][i];
    if (used[to] == 0) {
      dfs(to);
    }
  }
  return;
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  int b, c;
  for (int i = 1; i <= m; i++) {
    cin >> b >> c;
    v[b].push_back(c);
    v[c].push_back(b);
  }
  for (int i = 1; i <= n; i++) {
    mn = 1000000000;
    if (used[i] == 0) {
      dfs(i);
      sum += mn;
    }
  }
  cout << sum;
}
