#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, e;
  cin >> n >> e;
  vector<vector<int> > graph(n + 1);
  vector<int> cost(n + 1);
  vector<bool> vis(n + 1, false);
  for (int i = 1; i <= n; i++) cin >> cost[i];
  while (e--) {
    int x, y;
    cin >> x >> y;
    graph[x].push_back(y);
    graph[y].push_back(x);
  }
  long long ans = 0, m = INT_MAX;
  for (int i = 1; i <= n; i++) {
    if (vis[i] == false) {
      stack<int> st;
      st.push(i);
      vis[i] = true;
      m = min((int)m, cost[i]);
      while (st.size() != 0) {
        int u = st.top();
        vis[u] = true;
        st.pop();
        m = min((int)m, cost[u]);
        for (int j = 0; j < graph[u].size(); j++) {
          if (!vis[graph[u][j]]) {
            st.push(graph[u][j]);
          }
        }
      }
      ans += m;
      m = INT_MAX;
    }
  }
  cout << ans;
  cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n";
}
