#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
int getint(string s) {
  int x = stoi(s);
  return x;
}
string getstring(int x) {
  string lol = to_string(x);
  return lol;
}
bool ok(int x, int gg) { return (x <= gg - 1 and x >= 0); }
int X[4] = {1, 0, -1, 0};
int Y[4] = {0, 1, 0, -1};
int gcd(int a, int b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long int lcm(long long int a, long long int b) {
  return (a * b) / gcd(a, b);
}
long long int exponentMod(long long int A, long long int B, long long int C) {
  if (A == 0) return 0;
  if (B == 0) return 1;
  long long int y;
  if (B % 2 == 0) {
    y = exponentMod(A, B / 2, C);
    y = (y * y) % C;
  } else {
    y = A % C;
    y = (y * exponentMod(A, B - 1, C) % C) % C;
  }
  return (long long int)((y + C) % C);
}
bool ispal(string x) {
  for (int i = 0, j = x.size() - 1; i < x.size(); i++, j--) {
    if (i > j) break;
    if (x[j] != x[i]) return false;
  }
  return true;
}
vector<vector<int> > G;
const int N = 1e5 + 10;
int vis[N];
void dfs(int x) {
  vis[x] = 1;
  for (int i = 0; i < G[x].size(); i++) {
    int u = G[x][i];
    if (!vis[u]) dfs(u);
  }
}
int main() {
  int n, m;
  while (cin >> n >> m) {
    G = vector<vector<int> >(n);
    vector<pair<int, int> > v;
    for (int i = 0; i < n; i++) {
      int x;
      cin >> x;
      v.push_back(make_pair(x, i));
    }
    for (int i = 0; i < m; i++) {
      int x, y;
      cin >> x >> y;
      x--, y--;
      G[x].push_back(y);
      G[y].push_back(x);
    }
    memset(vis, 0, sizeof vis);
    sort(v.begin(), v.end());
    long long int ans = 0;
    for (int i = 0; i < n; i++) {
      if (!vis[v[i].second]) {
        ans += v[i].first;
        dfs(v[i].second);
      }
    }
    cout << ans << endl;
  }
}
