from collections import deque

from collections import defaultdict

import heapq



N,M=list(map(int, input().split()))

cost=list(map(int, input().split()))



if M==N-1:

	print(0)

	quit()



nl=[ [] for i in range(N) ]



for i in range(M):

	x,y=list(map(int,input().split()))

	nl[x].append(y)

	nl[y].append(x)





d=[ None for i in range(N) ]

V=[ None for i in range(N) ]



group_cost=defaultdict(lambda: [])



def dfs(start):

	q = deque([]) 

	V[start]=start

	d[start]=0

	heapq.heappush(group_cost[start],cost[start])

	q.append(start)



	while len(q)!=0:

		v=q.pop()

		for i in nl[v]:

			if V[i] is None:

				V[i]=start

				q.append(i)

				heapq.heappush(group_cost[start],cost[i])



for i in range(N):

	if V[i] is None:

		dfs(i)





H = []



ans=0

for v in list(group_cost.values()):

	v=sorted(v)

	ans+=v[0]

	H.append(v[1:])



nokori_cost=list(heapq.merge(*H))





if N < 2*(N-M-1):

	print("Impossible")

elif M == N-1:

	print(0)

else:

	ans += sum(nokori_cost[:2*(N-M-1) - len(list(group_cost.keys()))])

	print(ans)







from collections import deque

from collections import defaultdict

import heapq



N,M=list(map(int, input().split()))

cost=list(map(int, input().split()))



par=[i for i in range(N)]



def root(x):

	if par[x]==x:

		return x

	else:

		r=root(par[x])

		par[x]=r

		return r



def unite(x,y):

	x=root(x)

	y=root(y)

	if x==y: return

	par[x]=y





for i in range(M):

	x,y=list(map(int,input().split()))

	unite(x,y)





group_cost=defaultdict(lambda: [])



for i in range(N):

	root(i)

	group_cost[par[i]].append(cost[i])





H = []



ans=0

for v in list(group_cost.values()):

	v=sorted(v)

	ans+=v[0]

	H.append(v[1:])



nokori_cost=list(heapq.merge(*H))





if N < 2*(N-M-1):

	print("Impossible")

elif M == N-1:

	print(0)

else:

	ans += sum(nokori_cost[:2*(N-M-1) - len(list(group_cost.keys()))])

	print(ans)





from collections import deque
from collections import defaultdict
import heapq

N, M = list(map(int, input().split()))
cost = list(map(int, input().split()))
if M == N - 1:
    print(0)
    quit()
nl = [[] for i in range(N)]
for i in range(M):
    x, y = list(map(int, input().split()))
    nl[x].append(y)
    nl[y].append(x)
d = [None for i in range(N)]
V = [None for i in range(N)]
group_cost = defaultdict(lambda: [])


def dfs(start):
    q = deque([])
    V[start] = start
    d[start] = 0
    heapq.heappush(group_cost[start], cost[start])
    q.append(start)
    while len(q) != 0:
        v = q.pop()
        for i in nl[v]:
            if V[i] is None:
                V[i] = start
                q.append(i)
                heapq.heappush(group_cost[start], cost[i])


for i in range(N):
    if V[i] is None:
        dfs(i)
H = []
ans = 0
for v in list(group_cost.values()):
    v = sorted(v)
    ans += v[0]
    H.append(v[1:])
nokori_cost = list(heapq.merge(*H))
if N < 2 * (N - M - 1):
    print("Impossible")
elif M == N - 1:
    print(0)
else:
    ans += sum(nokori_cost[: 2 * (N - M - 1) - len(list(group_cost.keys()))])
    print(ans)

from collections import deque
from collections import defaultdict
import heapq

N, M = list(map(int, input().split()))
cost = list(map(int, input().split()))
par = [i for i in range(N)]


def root(x):
    if par[x] == x:
        return x
    else:
        r = root(par[x])
        par[x] = r
        return r


def unite(x, y):
    x = root(x)
    y = root(y)
    if x == y:
        return
    par[x] = y


for i in range(M):
    x, y = list(map(int, input().split()))
    unite(x, y)
group_cost = defaultdict(lambda: [])
for i in range(N):
    root(i)
    group_cost[par[i]].append(cost[i])
H = []
ans = 0
for v in list(group_cost.values()):
    v = sorted(v)
    ans += v[0]
    H.append(v[1:])
nokori_cost = list(heapq.merge(*H))
if N < 2 * (N - M - 1):
    print("Impossible")
elif M == N - 1:
    print(0)
else:
    ans += sum(nokori_cost[: 2 * (N - M - 1) - len(list(group_cost.keys()))])
    print(ans)

-if M == N - 1: -    print(0) -    quit() -nl = [[] for i in range(N)] +par = [i for i in range(N)] + + +def root(x): +    if par[x] == x: +        return x +    else: +        r = root(par[x]) +        par[x] = r +        return r + + +def unite(x, y): +    x = root(x) +    y = root(y) +    if x == y: +        return +    par[x] = y + + -    nl[x].append(y) -    nl[y].append(x) -d = [None for i in range(N)] -V = [None for i in range(N)] +    unite(x, y) - - -def dfs(start): -    q = deque([]) -    V[start] = start -    d[start] = 0 -    heapq.heappush(group_cost[start], cost[start]) -    q.append(start) -    while len(q) != 0: -        v = q.pop() -        for i in nl[v]: -            if V[i] is None: -                V[i] = start -                q.append(i) -                heapq.heappush(group_cost[start], cost[i]) - - -    if V[i] is None: -        dfs(i) +    root(i) +    group_cost[par[i]].append(cost[i])