#include <bits/stdc++.h>
using namespace std;
const int N = 1e5;
vector<int> vc[N + 10];
pair<long long, int> c[N + 10];
bool mrk[N + 10];
void dfs(int v) {
  mrk[v] = true;
  for (int i = 0; i < vc[v].size(); i++) {
    int u = vc[v][i];
    if (!mrk[u]) dfs(u);
  }
  return;
}
int main() {
  long long n, m, cnt = 0;
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> c[i].first, c[i].second = i;
  while (m--) {
    int x, y;
    cin >> x >> y, x--, y--;
    vc[x].push_back(y);
    vc[y].push_back(x);
  }
  sort(c, c + n);
  for (int i = 0; i < n; i++)
    if (!mrk[c[i].second]) dfs(c[i].second), cnt += c[i].first;
  return cout << cnt, 0;
  return 0;
}
