Dwarf Tower#6263

Dwarf Tower

2 seconds
128 megabytes
Medium

Little Vasya is playing a game called "Dwarf Tower". In this game, there are different items that can be equipped on a character — a dwarf. All items are numbered from to . Vasya wants to obtain item number .

There are two ways to obtain items:

Help Vasya spend as little money as possible to get item number .

Input

The first line contains two integers and m~(1 \le n \le 10^4, 0 \le m \le 10^5) — the number of different items and the number of crafting recipes.

The second line contains integers c_i~(0 \le c_i \le 10^9) — the costs of the items.

Each of the following lines describes a recipe. Each line contains three distinct integers a_i, x_i, y_i, where a_i is the item that can be crafted from items x_i and y_i~(1 \le a_i, x_i, y_i \le n, a_i \ne x_i, x_i \ne y_i, y_i \ne a_i).

Output

Print one integer — the minimum amount of money that needs to be spent.

Examples

Example 1

Loading
Loading

Example 2

Loading
Loading