
Fax McClad, Croneria's most meticulous bounty hunter, is going to prepare a dish for Christmas!
There are
Fax wants to have one unit of item
What is the earliest day that Fax can obtain item
Constraints
Subtask | Points | Additional Constraints |
---|---|---|
1 | 10 | |
2 | 10 | |
3 | 30 | |
4 | 50 | None |
Input Specification
The first line will contain integers
Each of the next
- The first integer is the target item.
- The second integer is the number of required items.
- The remaining integers are the required items.
The last line will contain
Output Specification
If Fax cannot obtain item -1
. Otherwise, output the earliest day that Fax can obtain item
Sample Input 1
7 3 8
2 2 3 6
4 2 5 7
1 2 2 4
3 3 6 3 5 4 4 1
Sample Output 1
6
Explanation for Sample Output 1
After 3 3 6 3 5 4
. Fax can follow the first recipe to get 2 3 3 5 4
, then the third recipe to get 1 3 3 5
.
Sample Input 2
4 1 7
1 3 2 3 4
2 2 3 3 2 3 3
Sample Output 2
-1
Comments