#include <bits/stdc++.h>
using namespace std;
vector<int> graph[100001];
bool visited[100001];
int cost[100001];
vector<int> cts;
void dfs(int st) {
  cts.push_back(cost[st]);
  visited[st] = true;
  for (int j = 0; j < int(graph[st].size()); j++) {
    if (!visited[graph[st][j]]) {
      dfs(graph[st][j]);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  clock_t t1, t2;
  t1 = clock();
  int n, m;
  cin >> n >> m;
  memset(visited, false, sizeof(visited));
  long long int sumt = 0;
  for (int i = 1; i <= n; i++) {
    int ct;
    cin >> ct;
    sumt += ct;
    cost[i] = ct;
  }
  if (m == 0) {
    cout << sumt << "\n";
  } else {
    for (int i = 1; i <= m; i++) {
      int x, y;
      cin >> x >> y;
      graph[x].push_back(y);
      graph[y].push_back(x);
    }
    long long int anss = 0;
    for (int i = 1; i <= n; i++) {
      if (visited[i] == false) {
        cts.clear();
        dfs(i);
        sort(cts.begin(), cts.end());
        anss += cts[0];
        cts.clear();
      }
    }
    cout << anss << "\n";
  }
  t2 = clock();
  float diff = (float)t2 - (float)t1;
  float execution_time = diff / CLOCKS_PER_SEC;
}
