- Time limit: 1.00 s
- Memory limit: 512 MB
You have coins with positive integer values. The coins are numbered .
Your task is to process queries of the form: "if you can use coins , what is the smallest sum you cannot produce?"
Input
The first input line has two integers and : the number of coins and queries.
The second line has integers : the value of each coin.
Finally, there are lines that describe the queries. Each line has two values and : you can use coins .
Output
Print the answer for each query.
Constraints
Example
Input:
5 3 2 9 1 2 7 2 4 4 4 1 5
Output:
4 1 6
Explanation: First you can use coins , then coins and finally coins .