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
#! /usr/bin/python

import sys

max_val = sys.maxint
inp = sys.stdin.readline().split()
N, M = int(inp[0]), int(inp[1])
g = range(N+1)    # group of i'th point which is equal to least point index in the group;
                  # all points connected to each other are in a same group
for i in xrange(M):
    inp = sys.stdin.readline().split()
    A, B = int(inp[0]), int(inp[1])
    if g[A] < g[B]:
        A, B = B, A
    while A != g[A]:
        A = g[A]
    g[A] = g[B]

for i in xrange(1, N+1):
    if g[i] == g[g[i]]:
        continue
    while g[i] != g[g[i]]:
        g[i] = g[g[i]]

v = {}   # key=group; value=least cost of connecting that group
for i in xrange(1, N+1):
    C = int(sys.stdin.readline())
    if C < 0:
        C = max_val
    if v.has_key(g[i]):
        v[g[i]] = min(C, v[g[i]])
    else:
        v[g[i]] = C

if len(v) == 1:
    print 0
else:
    _sum, _min = 0, max_val
    no_sol = False
    for key in v:
        val = v[key]
        if val == max_val:
            no_sol = True
            break
        _sum += val
        if val < _min:
            _min = val
    if no_sol:
        print -1
    else:
        print _sum + (len(v) - 2)*_min