Item Crafting

No attempts yetTime limit2sMemory limit256 MB

Problem

Sunyoung recently started a game called "Norris Tower". The game has nn kinds of items, and her character can wear every one of them. The items are numbered 1 through nn. Sunyoung wants to obtain item 1.

There are two ways to obtain an item.

  • She can buy the item. Item ii costs cic_i won.
  • She can craft the item. There are mm crafting recipes in total. If she brings two items of different kinds to the blacksmith, the blacksmith makes the resulting item for free. The two items she hands over are not returned, so using the same kind twice means preparing two of them.

Write a program that computes the smallest amount of money Sunyoung needs to obtain item 1.

Input

The first line contains the number of item kinds nn and the number of crafting recipes mm. (1n100001 \le n \le 10\,000, 0m1000000 \le m \le 100\,000)

The second line contains the prices c1,c2,,cnc_1, c_2, \dots, c_n in increasing order of item number. (0ci1090 \le c_i \le 10^9)

Each of the next mm lines contains one recipe as the result item and the two ingredient items, aia_i, xix_i, yiy_i, in that order. Handing one item xix_i and one item yiy_i to the blacksmith yields item aia_i. (1ai,xi,yin1 \le a_i, x_i, y_i \le n, aixia_i \ne x_i, xiyix_i \ne y_i, yiaiy_i \ne a_i)

Output

Print, on one line, the smallest amount of money needed to obtain item 1.