#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > v;
vector<bool> vis(100001);
void inputund(vector<vector<int> > &v) {
  int a, b;
  scanf("%d", &a);
  scanf("%d", &b);
  a--, b--;
  v[a].push_back(b);
  v[b].push_back(a);
}
int dfs(int cur_node, int par_node, int &nodes_cnt) {
  if (vis[cur_node]) return 1;
  vis[cur_node] = 1;
  for (auto child_node : v[cur_node])
    if (child_node != par_node) {
      ++nodes_cnt;
      if (dfs(child_node, cur_node, nodes_cnt) == 0) return 1;
    }
  return 0;
}
void dfs(int node) {
  vis[node] = true;
  for (auto neighbour : v[node]) {
    if (!vis[neighbour]) dfs(neighbour);
  }
}
int concom(int nodes) {
  int ctr = 0;
  for (int i = 0; i < nodes; i++) {
    if (!vis[i]) {
      dfs(i);
      ctr++;
    }
  }
  return ctr;
}
int treeheight(int node, int prev) {
  int h = 0;
  for (int child : v[node])
    if (child != prev) {
      h = max(h, 1 + treeheight(child, node));
    }
  return h;
}
void dfstack() {
  stack<int> s;
  int node = 4;
  s.push(node);
  while (!s.empty()) {
    int y = s.top();
    s.pop();
    vis[y] = true;
    for (int i : v[y])
      if (!vis[i]) {
        s.push(i);
      }
  }
}
void A4E() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
int dx[3] = {-1, 0, 0};
int dy[3] = {0, 1, -1};
bool validpoint(int i, int j, int a, int b) {
  return i >= 0 && j >= 0 && i < a && j < b;
}
void dfs(int i, int j) {
  dfs(i + 1, j);
  dfs(i, j + 1);
  dfs(i, j - 1);
  dfs(i - 1, j);
}
vector<vector<int> > order(150);
bool visited[150];
vector<int> res;
void dfsorder(int x) {
  visited[x] = 1;
  for (int i = 0; i < order[x].size(); i++)
    if (!visited[order[x][i]]) dfsorder(i);
  res.insert(res.begin(), x + 1);
}
bool used[500];
vector<int> G[100500];
int a[100001];
vector<vector<int> > rumer(100001);
int mn = 1e9;
int dafs(int v) {
  mn = min(mn, a[v]);
  vis[v] = true;
  for (int i = 0; i < rumer[v].size(); ++i) {
    if (!vis[rumer[v][i]]) dafs(rumer[v][i]);
  }
  return mn;
}
int main() {
  A4E();
  int n, m;
  cin >> n >> m;
  rumer.resize(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  int x, y;
  for (int i = 1; i <= m; i++) {
    cin >> x >> y;
    rumer[x].push_back(y);
    rumer[y].push_back(x);
  }
  long long sum = 0;
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      sum += dafs(i);
      mn = 1e9;
    }
  }
  cout << sum << endl;
}
