#include <bits/stdc++.h>
typedef struct node {
  int num;
  struct node* next;
} N;
typedef struct {
  int cost;
  N* tail;
  N* head;
} F;
F friends[100001];
void Friend_Insert(int dst, int src) {
  N* newnode = (N*)malloc(sizeof(N));
  newnode->next = NULL;
  newnode->num = src;
  if (friends[dst].head == NULL) friends[dst].head = newnode;
  if (friends[dst].tail != NULL) friends[dst].tail->next = newnode;
  friends[dst].tail = newnode;
}
int connected[100001], counted[100001], n;
long long ans = 0;
void MakeCon(int x, int y) {
  connected[x] = 1;
  connected[y] = 1;
  Friend_Insert(x, y);
  Friend_Insert(y, x);
}
int dfs(int fidx, int min) {
  if (!counted[fidx]) {
    counted[fidx] = 1;
    if (friends[fidx].cost < min) {
      min = friends[fidx].cost;
    }
  }
  N* cur = friends[fidx].head;
  while (cur) {
    if (!counted[cur->num]) min = dfs(cur->num, min);
    cur = cur->next;
  }
  return min;
}
int main(void) {
  int m, a, x, y;
  scanf("%d %d", &n, &m);
  for (a = 1; a <= n; a = a + 1) {
    scanf("%d", &friends[a].cost);
    friends[a].tail = NULL;
    friends[a].head = NULL;
  }
  for (a = 1; a <= m; a = a + 1) {
    scanf("%d %d", &x, &y);
    MakeCon(x, y);
  }
  for (a = 1; a <= n; a = a + 1) {
    if (!counted[a]) {
      ans += dfs(a, friends[a].cost);
    }
  }
  printf("%I64d", ans);
  return 0;
}
