Dwarf Tower
Little Vasya is playing a new game named "Dwarf Tower". In this game there are different items, which you can put on your dwarf character. Items are numbered from to . Vasya wants to get the item with number .
There are two ways to obtain an item:
You can buy an item. The -th item costs money.
You can craft an item. This game supports only 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 .
Input
The first line contains two integers and — the number of different items and the number of crafting types.
The second line contains integers — values of the items.
The following lines describe crafting types, each line contains three distinct integers , where is the item that can be crafted from items and .
Output
Print a single integer — the least amount of money to spend.