문제
Farmer John is at the market to purchase supplies for his farm. He has in his pocket K coins
Please compute the maximum amount of money FJ can end up with after making his N purchases in sequence. Output -1 if it is impossible for FJ to make all of his purchases.
입력
* Line 1: Two integers, K and N.
* Lines
* Lines
출력
* Line 1: The maximum amount of money FJ can end up with, or -1 if FJ cannot complete all of his purchases.
예제1
36
12
15
10
6
3
3
2
3
7
12
INPUT DETAILS:
FJ has 3 coins of values 12, 15, and 10.
He must make purchases in sequence of value 6, 3, 3, 2, 3, and 7.
OUTPUT DETAILS:
FJ spends his 10-unit coin on the first two purchases, then the 15-unit coin on the remaining purchases. This leaves him with the 12-unit coin.