After decades of searching, you have finally given up on the eternal fame and glory for discovering the elusive Philosopher's Stone. However, you are still able to make a fortune producing gold, even without the Philosopher's Stone! For the right amount of money, alchemists will perform certain spells, transforming one element into another.

The world consists of elements labelled from to , and you currently have a piece of iron (element ) at your disposal. Your goal is to transform this iron into gold (element ), possibly by transforming the iron into several other elements along the way in order to eventually obtain gold.

There are different alchemists you can pay, labelled from to , each of them having their own spells they can perform. Every time you visit a particular alchemist, you can pay them to perform any number of spells. (Here, a visit is counted as a contiguous set of spells performed by the same alchemist, such that no two consecutive visits involve the same alchemist.) The -th alchemist has an associated value with it, , and is a type alchemist. The three different types of alchemist are detailed below:

Type alchemists work with different elements. The -th of these elements is element , which has an associated trading value of . In one spell, they can convert any element from the set into another new element from that set, where the value of the spell is equal to the sum of the trading values of the old and new elements. More specifically, for any , with , they can turn element into element for a cost of . The base cost of the visit is equal to the sum of the values of the spells performed.

Type and type alchemists can perform different spells labelled from to . The -th spell converts element to element or vice-versa, where the value of the spell is . For type alchemists, the base cost of the visit is equal to the sum of the values of the spells performed. For type alchemists, the base cost of the visit is equal to the maximum of the values of the spells performed.

Furthermore, each time you visit the -th alchemist, you will have to pay a visiting fee of . The total cost of a visit is hence the sum of the base cost and the visiting fee, and the final cost is equal to the sum of the total costs of each visit. **Note that if you visit an alchemist several times, you will have to pay the visiting fee each time.**

Of course, there is no point in producing gold if it costs too much to produce it. What is the minimum possible final cost to transform your piece of iron into gold?

#### Constraints

(the sum of for each alchemist does not exceed )

It is guaranteed that every element is obtainable, starting with element .

The elements that type 1 alchemists work with are pairwise distinct.

##### Subtask 1 [10%]

All alchemists are of type . More specifically, for all .

Furthermore, for all , .

##### Subtask 2 [20%]

All alchemists are of type or . More specifically, for all .

##### Subtask 3 [70%]

No additional constraints.

#### Input Specification

The first line contains two space separated integers , .

The -th of the following sets of lines describes the -th alchemist.

The -th set of lines begins with a line containing three space separated integers , denoting the type, special value and visiting fee respectively of the -th alchemist.

If , then the following line containing space separated integers , corresponding to the set of elements the -th alchemist works with. This is followed by a line containing space separated integers , corresponding to the associating trading values of the elements that the -th alchemist works with.

Otherwise, -th of the following lines contains three space separated integers , denoting the initial element, new element and value of the -th spell able to be performed by the -th alchemist.

#### Output Specification

On a single line, print the minimum possible final cost of obtaining element .

#### Sample Input

```
9 3
2 3 2
1 2 3
3 2 4
8 9 1
1 4 3
3 4 5 6
1 2 3 4
3 3 4
8 7 2
4 7 6
7 6 3
```

#### Sample Output

`27`

#### Explanation

To obtain gold (element ), you can perform the following:

- Begin visiting alchemist , incurring a visiting fee of .
- Turn your element into element , and then turn your element into element . The base cost of this visit is .
- Finish visiting alchemist .
- Begin visiting alchemist , incurring a visiting fee of .
- Turn your element into element . The base cost of this visit is .
- Finish visiting alchemist .
- Begin visiting alchemist , incurring a visiting fee of .
- Turn your element into element , and then turn your element into element . The base cost of this visit is .
- Finish visiting alchemist .
- Begin another visit to alchemist . Note that you will have to pay the visiting fee of again.
- Turn your element into element . The base cost of this visit is .
- Finish visiting alchemist .

The final cost is . It can be shown that this is the minimum possible final cost to obtain gold.

## Comments