시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 512 MB 1 1 1 100.000%

문제

Gigel wants to test his cooking abilities and goes to the market to get some supplies. At the market, there are m types of objects sold as promotional packages for a period of n days. On the ith day, Gigel has two options: he either buys the promotional package available on that day or not. The promotional package is represented by a non-empty subset of the set of the m types of objects and it has a certain price.

Knowing m, n, the price and the composition of each of the n promotional packages, find the minimal price that Gigel should pay in order to buy at least one object of each of the m types.

입력

The first line of the input contains 2 numbers, m and n.

The next n lines will describe the n promotional packages in this way: the (i+1)th line (1 ≤ i ≤ n) contains nr and p, which stand for the number of objects in the promotional package from that day and its price. Then, on the same line, there are given nr numbers which represent the indexes of the objects that belong to that package.

출력

In the output print a positive integer number equal to the minimal price that should be paid in order to buy at least one object of every type.

제한

  • 1 ≤ m ≤ 17, 1 ≤ n ≤1,000, 1 ≤ p ≤1,000,000
  • All numbers found in the input file are positive integers.
  • A promotional package shall be bought only completely.
  • The indexes of the objects that describe a certain package have values from the following set: {1,2, … , m}.
  • It is guaranteed that there is a solution for all test cases.

예제 입력 1

5 4
3 10 1 3 2
2 8 1 4
3 11 5 4 3
5 27 1 4 2 3 5

예제 출력 1

21

힌트

The chosen packages are the first and the third ones, thus obtaining a minimal cost of 10+11 = 21. Note that Gigel buys one object of type 1, one object of type 2, two objects of type 3, one object of type 4 and one object of type 5.

채점 및 기타 정보

  • 예제는 채점하지 않는다.