#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
long long small(long long a, long long b) {
  if (a < b) return a;
  return b;
}
long long large(long long a, long long b) {
  if (a > b) return a;
  return b;
}
long long root(long long x, vector<long long>& a) {
  if (a[x] == x) return x;
  a[x] = root(a[x], a);
  return (a[x]);
}
int main() {
  long long t;
  t = 1;
  while (t--) {
    long long n, i, c, m, x, y, a1, h, k = 0;
    cin >> n >> m;
    vector<long long> v(n + 1, 0), a(n + 1, 0);
    for (i = 1; i <= n; i++) {
      cin >> v[i];
      a[i] = i;
    }
    while (m--) {
      cin >> x >> y;
      x = root(x, a);
      y = root(y, a);
      if (v[x] < v[y])
        a[y] = x;
      else
        a[x] = y;
    }
    for (i = 1; i <= n; i++) {
      if (a[i] == i) k = k + v[i];
    }
    cout << k << endl;
  }
}
