March 28 ADA University Students + Schoolchildren

Dwarf Tower

Time limit 1 second
Memory limit 128 MiB

Little Vasya is playing a new game named "Dwarf Tower". In this game there are n different items, which you can put on your dwarf character. Items are numbered from 1 to n. Vasya wants to get the item with number 1.

There are two ways to obtain an item:

  • You can buy an item. The i-th item costs c[i] money.

  • You can craft an item. This game supports only m types of crafting. To craft an item, you give two particular different items and get another one as a result.

Help Vasya to spend the least amount of money to get the item number 1.

Input data

The first line contains two integers n and m (1n10000, 0m100000) - the number of different items and the number of crafting types.

The second line contains n integers c[i] - values of the items (0c[i]10^9).

The following m lines describe crafting types, each line contains three distinct integers a[i], x[i], y[i] - a[i] is the item that can be crafted from items x[i] and y[i] (1a[i], x[i], y[i]n, a[i]x[i], x[i]y[i], y[i]a[i]).

Output data

Print a single integer - the least amount of money to spend.


Input example #1
5 3
5 0 1 2 5
5 2 3
4 2 3
1 4 5
Output example #1
Input example #2
3 1
2 2 1
1 2 3
Output example #2
Source 2013 ACM NEERC, Northern Subregional Contest, St Petersburg, October 26