(n,m),a,*q=[map(int,t.split())for t in open(0)]

t=[-1]*n

def r(x):

 while-1<t[x]:x=t[x]

 return x

def u(x):

 x,y=map(r,x)

 if x!=y:

  if t[x]>t[y]:x,y=y,x

  t[x]+=t[y];t[y]=x

[*map(u,q)]

i=c=0

k,*b=n+~m<<1,

*d,=eval('[],'*n)

for v in a:d[r(i)]+=v,;i+=1

print(k<1and'0'or(k>n)*'Impossible'or exec('for p in d:x,*y=sorted(p)+[0];c+=x;b+=y[:-1];k-=p>[]')or c+sum(sorted(b)[:k]))

(n,m,*b),a,*q=[list(map(int,t.split()))for t in open(0)]

t=[-1]*n

def r(x):

 while-1<t[x]:x=t[x]

 return x

def u(x):

 x,y=list(map(r,x))

 if x!=y:

  if t[x]>t[y]:x,y=y,x

  t[x]+=t[y];t[y]=x

[*list(map(u,q))]

i=c=0

k=j=n+~m<<1

*d,=eval('[],'*n)

for v in a:d[r(i)]+=v,;i+=1

for p in d:x,*y=sorted(p)+[0];c+=x;b+=y[:-1];j-=p>[]

print((k<1and'0'or(k>n)*'Impossible'or c+sum(sorted(b)[:j])))
(n, m), a, *q = [map(int, t.split()) for t in open(0)]
t = [-1] * n


def r(x):
    while -1 < t[x]:
        x = t[x]
    return x


def u(x):
    x, y = map(r, x)
    if x != y:
        if t[x] > t[y]:
            x, y = y, x
        t[x] += t[y]
        t[y] = x


[*map(u, q)]
i = c = 0
k, *b = (n + ~m << 1,)
(*d,) = eval("[]," * n)
for v in a:
    d[r(i)] += (v,)
    i += 1
print(
    k < 1
    and "0"
    or (k > n) * "Impossible"
    or exec("for p in d:x,*y=sorted(p)+[0];c+=x;b+=y[:-1];k-=p>[]")
    or c + sum(sorted(b)[:k])
)

(n, m, *b), a, *q = [list(map(int, t.split())) for t in open(0)]
t = [-1] * n


def r(x):
    while -1 < t[x]:
        x = t[x]
    return x


def u(x):
    x, y = list(map(r, x))
    if x != y:
        if t[x] > t[y]:
            x, y = y, x
        t[x] += t[y]
        t[y] = x


[*list(map(u, q))]
i = c = 0
k = j = n + ~m << 1
(*d,) = eval("[]," * n)
for v in a:
    d[r(i)] += (v,)
    i += 1
for p in d:
    x, *y = sorted(p) + [0]
    c += x
    b += y[:-1]
    j -= p > []
print((k < 1 and "0" or (k > n) * "Impossible" or c + sum(sorted(b)[:j])))

-(n, m), a, *q = [map(int, t.split()) for t in open(0)] +(n, m, *b), a, *q = [list(map(int, t.split())) for t in open(0)] -    x, y = map(r, x) +    x, y = list(map(r, x)) -[*map(u, q)] +[*list(map(u, q))] -k, *b = (n + ~m << 1,) +k = j = n + ~m << 1 -print( -    k < 1 -    and "0" -    or (k > n) * "Impossible" -    or exec("for p in d:x,*y=sorted(p)+[0];c+=x;b+=y[:-1];k-=p>[]") -    or c + sum(sorted(b)[:k]) -) +for p in d: +    x, *y = sorted(p) + [0] +    c += x +    b += y[:-1] +    j -= p > [] +print((k < 1 and "0" or (k > n) * "Impossible" or c + sum(sorted(b)[:j])))