WARNING Large input/output files. Use faster I/O.
It's Galactik Football time! The Galactik Football Assosiation (GFA) has announced a football tournament between all the teams of all the planets in the galaxy (say N). Teams like Snow Kids, Shadows, Xenons, Red Tigers, Wambas, Pirates, etc. are in total enthusiasm and are practising hard to win the cup using their talent and flux.
Each planet of the galaxy has a government. Some governments have a mutual agreement between them. If planet A has mutual agreement with planet B, then there is a bidirectional spaceway between A and B using which anybody can go from A to B and vice-versa. People can use these spaceways to travel from one planet to another, if there exists a path between them using some of the spaceways.
Each planet has it's own football ground. The GFA has planned the matches in such a way that a team can have a match at any of these grounds. The GFA has come across some problems in the execution of their plan. They have found out that there are many pairs of planets between which there does not exist any path, so the football team of one of those planets can't reach the other planet. They requested the corresponding governments to make a spaceway between them, but because of absense of mutual agreement (duhhh.. Politics!), these goverment did not agree. So the GFA suggested that they will make teleports between some pairs of planets which will be used only by the football teams to travel.
But there are two types of governments in the galaxy
1. Some of the governments are greedy (duhhh..). They want to make money (You don't say!) throught the GFA. So each of these government has asked the GFA for a tax value which it has to pay if it wants to make a teleport ending at their planet.
2. Others want to sponser the event, so they will give money to the GFA if they make a teleport ending at their planet (That's new..). The GFA would always avoid such governments no matter what the consequences are, because these kind of governments have always some dirty plans in their minds for the GFA.
Now, the GFA wants to make bi-directional teleports between planets such that the football teams of any planet can reach any other planet to play a football match, using spaceways between the planets and/or teleports made by the GFA.
The GFA also has financial problems and want to spend as little money as possible. They have come to you so that you can help them calculate the minimum ammount of money needed to fulfill their plan.

Input
The first line of the input consists of two integers - N and M. N is number of planets and M is number of pairs of planets which have a mutual agreement, i.e they have a spaceway between them. Then, M lines follow, each containing two space separated integers A and B, denoting a mutual agreement and hence a spaceway to travel, between plenet A and planet B. Then, N lines follow. The i^th line has an integer C. If C ≥ 0, then it represents the tax value which the GFA has to pay to the government of planet i (it's a type 1 government). If C < 0, then it represents the money the ith government will pay to the GFA (it's a type 2 government).

Output
Print the minimum amount needed for the GFA to fulfill their plan if it can be fulfilled, else print "-1" (without quotes).

Constraints

1 ≤ N ≤ 100,000
0 ≤ M ≤ 1,000,000
0 ≤ |C| ≤ 10,000
1 ≤ A,B ≤ N
A ≠ B

Sample

Input 1
6 6
1 2
2 3
1 3
4 5
5 6
4 6
1
3
5
2
4
6

Output 1
3


Input 2
3 1
2 3
1
-1
-1

Output 2
-1
def visit(x):
    global count,visited,path
    for i in path[x]:
        if(visit[i]==0):
            visit[i]=1
            count+=1
            visit(i)
def getcost(x):
    global count,cost,visited
    val=cost[x]
    visited[x]=1
    count+=1
    for i in path[x]:
        if(visited[i]==0):
            v=getcost(i)
            if(v>=0):
                if(val<0):
                    val=v
                else:
                    val=min(val,v)
    return val

n,m=[int(u) for u in raw_input().split()]
visited=[0]*(n+1)
path=[]
for i in range(n+1):
    path.append([])
cost=[0]*(n+1)
count=1
visited[1]=1

def mainf():
    global count,cost,visited,path
    for i in range(m):
        a,b=[int(u) for u in raw_input().split()]
        if(visited[a]==1 and visited[b]==1):
            continue
        elif(visited[a]==1):
            visited[b]=1
            count+=1
            visit(b)
    
        elif(visited[b]==1):
            visited[a]=1
            count+=1
            visit(a)
    
        else:
            path[a].append(b)
            path[b].append(a)

    answer=0
    if(count==n):
        print '0'
        return

    cost2=[]
    pos=0
    ct=-1
    min_c=110001
    cos=110001
    flag=True
    for i in range(1,n+1):
        ct=int(raw_input())
        if((ct>=0) and visited[i]==1):                
            min_c=min(min_c,ct)
            flag=False
        cost[i]=ct

    if(flag and min_c==110001):
        print '-1'
        return
    
    ct=0
    for i in range(2,n+1):
        if(visited[i]!=1):
            c=getcost(i)
            if(c<0):
                print '-1'
                return
            else:
                cost2.append(c)
                if(c<cos):
                    pos=ct
                    cos=c
                ct+=1
    
    answer+=(min_c + cos)
    min_c=min(min_c,cos)
    for i in range(0,pos):
        answer+=(cost2[i])
    for i in range(pos+1,len(cost2)):
        answer+=(cost2[i])
        
    answer+=((len(cost2))-1)*min_c
    print answer    
mainf()