#include <bits/stdc++.h>
using namespace std;
int cost[100000];
int visited[100000];
int minCost;
vector<vector<int> > graph(100000);
void dfs(int index) {
  visited[index] = 1;
  for (int i = 0; i < graph[index].size(); i++) {
    if (visited[graph[index][i]] != 1) {
      minCost = min(cost[graph[index][i]], minCost);
      dfs(graph[index][i]);
    }
  }
  return;
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    cost[i] = x;
  }
  for (int i = 0; i < m; i++) {
    int x;
    int y;
    cin >> x >> y;
    graph[x - 1].push_back(y - 1);
    graph[y - 1].push_back(x - 1);
  }
  long long answer = 0;
  for (int i = 0; i < n; i++) {
    if (visited[i] != 1) {
      minCost = cost[i];
      dfs(i);
      answer += minCost;
    }
  }
  cout << answer;
  return 0;
}
