Day2 1517. Knapsack problem

Input

The first line is two positive integers v and T separated by spaces. Represents the space of the backpack and the number of groups of items. Next, there are T lines. Each line is a positive integer ni, which means that there are ni items in this group, and then ni positive integer, which means the size of each item.

Output

Only one number, representing the minimum of the remaining space.

Sample Input

100 3
3 7 6 8
2 80 70
4 101 108 103 150

Sample Output

6

Data Constraint

Hint

[sample description]
Select 6 and 8 in the first group, 80 in the second group and no in the third group.
[restrictions]
60% of the data meet the following requirements: 1 < = Ni < = 10
100% of the data meet the following requirements: 1 < = Ni < = 100, 1 < = V < = 5000, 1 < = T < = 10

Method: preprocess all possible values. That's 01 knapsack The code is as follows: