Sunyoung recently started a game called "Norris Tower". The game has n kinds of items, and her character can wear every one of them. The items are numbered 1 through n. Sunyoung wants to obtain item 1.
There are two ways to obtain an item.
Write a program that computes the smallest amount of money Sunyoung needs to obtain item 1.
The first line contains the number of item kinds n and the number of crafting recipes m. (1≤n≤10000, 0≤m≤100000)
The second line contains the prices c1,c2,…,cn in increasing order of item number. (0≤ci≤109)
Each of the next m lines contains one recipe as the result item and the two ingredient items, ai, xi, yi, in that order. Handing one item xi and one item yi to the blacksmith yields item ai. (1≤ai,xi,yi≤n, ai=xi, xi=yi, yi=ai)
Print, on one line, the smallest amount of money needed to obtain item 1.