Uses Math; Const MaxN = 100005; Type Edge = record x, y : Longint; End; Var e : array[0..MaxN] of Edge; a : array[0..2 * MaxN] of Longint; head : array[0..MaxN] of Longint; c : array[0..MaxN] of Longint; visited : array[0..MaxN] of Boolean; ans : Int64; n, m : Longint; Procedure Dfs(u : Longint; Var cost : Longint); Var i, v : Longint; Begin visited[u] := true; cost := min(cost, c[u]); For i := head[u] + 1 to head[u + 1] do Begin v := a[i]; if (visited[v]) then continue; Dfs(v, cost); End; End; Procedure Enter(); Var i, x, y : Longint; Begin Readln(n, m); For i := 1 to n do read(c[i]); For i := 1 to m do Begin readln(x, y); e[i].x := x; e[i].y := y; inc(head[x]); inc(head[y]); End; For i := 1 to n + 1 do inc(head[i], head[i - 1]); For i := 1 to m do Begin x := e[i].x; y := e[i].y; a[head[x]] := y; dec(head[x]); a[head[y]] := x; dec(head[y]); End; End; Procedure Solve(); Var i, cost : Longint; Begin For i := 1 to n do Begin if (not visited[i]) then Begin cost := 1123123123; Dfs(i, cost); inc(ans, cost); End; End; End; Begin Enter(); Solve(); Writeln(ans); End.