#include <bits/stdc++.h>
using namespace std;
long long int pow1(long long int a, long long int b) {
  long long int ans = 1;
  while (b) {
    if (b & 1) ans = (ans * a) % 1000000007;
    a = (a * a) % 1000000007;
    b = b >> 1;
  }
  return ans;
}
int n, m;
pair<int, int> a[100005];
vector<int> v[100005];
bool vis[100005] = {0};
void dfs(int x) {
  vis[x] = 1;
  for (int i = 0; i < v[x].size(); i++)
    if (!vis[v[x][i]]) dfs(v[x][i]);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i].first;
    a[i].second = i + 1;
  }
  sort(a, a + n);
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  long long int sum = 0;
  for (int i = 0; i < n; i++) {
    if (!vis[a[i].second]) {
      sum += a[i].first;
      dfs(a[i].second);
    }
  }
  cout << sum;
  return 0;
}
