#include <bits/stdc++.h>
using namespace std;
class Graph {
  long V;
  list<long> *adj;
  long *c;
  bool *visited;

 public:
  Graph(int V) {
    this->V = V;
    adj = new list<long>[V];
    c = new long[V];
    visited = new bool[V];
    for (int i = 0; i < V; i++) visited[i] = false;
  }
  void addEdge(long v, long w) { adj[v].push_back(w); }
  void addCost(long i, long cost) { c[i] = cost; }
  bool isVisited(long i) { return visited[i]; }
  void dfs(long v, long &cost);
};
void Graph::dfs(long v, long &cost) {
  visited[v] = true;
  if (cost > c[v]) cost = c[v];
  for (list<long>::iterator i = adj[v].begin(); i != adj[v].end(); ++i)
    if (!visited[*i]) dfs(*i, cost);
}
int main() {
  long n, m, c, x, y;
  cin >> n >> m;
  Graph g(n);
  for (int i = 0; i < n; ++i) {
    cin >> c;
    g.addCost(i, c);
  }
  for (int i = 0; i < m; ++i) {
    cin >> x >> y;
    g.addEdge(--x, --y);
    g.addEdge(y, x);
  }
  long long sum = 0;
  long cost = LONG_MAX;
  for (int i = 0; i < n; ++i) {
    if (!g.isVisited(i)) {
      g.dfs(i, cost);
      sum += cost;
      cost = LONG_MAX;
    }
  }
  cout << sum;
  return 0;
}
