#include <bits/stdc++.h>
const int Mod = 1e9 + 7, N = 1e5 + 1;
using namespace std;
bool visited[N];
int a[N];
long long total;
vector<pair<int, int>> v;
void div(set<int>& s, int n) {
  for (int i = 2; i <= sqrt(n); i++) {
    if (n % i == 0) {
      s.insert(i);
      s.insert(n / i);
    }
  }
}
long long dfs(int node, vector<vector<int>>& graph) {
  visited[node] = 1;
  for (auto child : graph[node]) {
    if (!visited[child]) {
      total -= a[child - 1];
      dfs(child, graph);
    }
  }
  return total;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, m;
  cin >> n >> m;
  int x;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    v.push_back({a[i], i});
    total += a[i];
  }
  sort(v.begin(), v.end());
  vector<vector<int>> adj(n + 1);
  for (int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  long long mn = 1e9;
  for (int i = 1; i <= n; i++) {
    dfs(v[i - 1].second + 1, adj);
  }
  cout << total << endl;
}
