Vova promised himself that he would never play computer games... But recently Firestorm — a well-known game developing company — published their newest game, World of Farcraft, and it became really popular. Of course, Vova started playing it.

Now he tries to solve a quest. The task is to come to a settlement named Overcity and spread a rumor in it.

Vova knows that there are *n* characters in Overcity. Some characters are friends to each other, and they share information they got. Also Vova knows that he can bribe each character so he or she starts spreading the rumor; *i*-th character wants *c*<sub class="lower-index">*i*</sub> gold in exchange for spreading the rumor. When a character hears the rumor, he tells it to all his friends, and they start spreading the rumor to their friends (for free), and so on.

The quest is finished when all *n* characters know the rumor. What is the minimum amount of gold Vova needs to spend in order to finish the quest?

Take a look at the notes if you think you haven't understood the problem completely.
The first line contains two integer numbers *n* and *m* (1 ≤ *n* ≤ 10<sup class="upper-index">5</sup>, 0 ≤ *m* ≤ 10<sup class="upper-index">5</sup>) — the number of characters in Overcity and the number of pairs of friends.

The second line contains *n* integer numbers *c*<sub class="lower-index">*i*</sub> (0 ≤ *c*<sub class="lower-index">*i*</sub> ≤ 10<sup class="upper-index">9</sup>) — the amount of gold *i*-th character asks to start spreading the rumor.

Then *m* lines follow, each containing a pair of numbers (*x*<sub class="lower-index">*i*</sub>, *y*<sub class="lower-index">*i*</sub>) which represent that characters *x*<sub class="lower-index">*i*</sub> and *y*<sub class="lower-index">*i*</sub> are friends (1 ≤ *x*<sub class="lower-index">*i*</sub>, *y*<sub class="lower-index">*i*</sub> ≤ *n*, *x*<sub class="lower-index">*i*</sub> ≠ *y*<sub class="lower-index">*i*</sub>). It is guaranteed that each pair is listed at most once.
In the first example the best decision is to bribe the first character (he will spread the rumor to fourth character, and the fourth one will spread it to fifth). Also Vova has to bribe the second and the third characters, so they know the rumor.

In the second example Vova has to bribe everyone.

In the third example the optimal decision is to bribe the first, the third, the fifth, the seventh and the ninth characters.
5 2
2 5 3 4 8
1 4
4 5
10
10 0
1 2 3 4 5 6 7 8 9 10
55
10 5
1 6 2 7 3 8 4 9 5 10
1 2
3 4
5 6
7 8
9 10
15
1 0
0
0
1 0
1000000000
1000000000
2 0
0 0
0
2 0
1000000000 0
1000000000
2 0
0 1000000000
1000000000
2 0
1000000000 1000000000
2000000000
2 1
0 0
1 2
0
import math

# We get two numbers, "n" is the number of characters in overcity
# and "m" the number of pair of friends.
n, m = [int(nm) for nm in input().split()]

# Here it is getting the amount of gold each character needs.
c = [int(cc) for cc in input().split()]

# An adjency list for keeíng track of the relation of each character
# with another is created
adj_list_friends = [[] for i in range(n)]
for i in range(m):
    x, y = [int(xy) for xy in input().split()]
    adj_list_friends[x-1].append(y-1)
    adj_list_friends[y-1].append(x-1)

# An array of the size of the number of characters in the game
# is created. This is for keeping track of the visited "nodes"
# or characters which relation is storen in the adj_list of firends
visited = [False] * n

# It is implemented a dfs search algorith.
def dfs(s):
        # stack for keeping track the "to visit" nodes.
        stack = []
        # node to search for is added to the stack
        stack.append(s)
        # iterator number for the gold of the node character
        inf=math.inf
        # while the stack is not empty
        while(stack):
            # the first node index is poped and saved
            s =stack.pop()
            # if the required gold for the character is greater than
            # the previous character, then set it to be the same, else
            # set the amout of gold the character requires
            inf = inf if inf < c[s] else c[s]
            # if it hasnt been visited, then mark it as visited
            if visited[s] != True:
                visited[s]=True
            # for each none visisted on adj_list of friends, then
            # add it to the stack and repeat the cycle
            for u in adj_list_friends[s]:
                if not visited[u]:
                    stack.append(u)
        # return the amout of required gold
        return inf

amount_gold = 0
# for each element in the range of the number of characters
for i in range(n):
    # if the character has not been visited, then 
    # run the dfs search.
    if not visited[i]:
        amount_gold += dfs(i)
        print("==============")
        
print(amount_gold)
	  	 			 	    			   		 		  	 	