Subset Sum

Time limit1sMemory limit128 MB

Summary
Given up to 20 bag sizes and a target n, pick each bag at most once to reach at least n with the smallest possible total.
Level

Easy3 of 10

Topics
Brute force, Bit manipulation, Array
Solved
No attempts yet

Problem

Maia wants to buy exactly nn microlitres of milk. Her grocery store does not sell a single bag of that size, so she buys several bags and adds them together. It may be impossible to reach exactly nn microlitres, so she is willing to buy a little more if needed, but she wants the extra amount to be as small as possible.

The store offers mm bag sizes. Maia refuses to buy two bags of the same size, so she may take each offered bag at most once. Choose some of the offered bags so that Maia buys at least nn microlitres of milk while making the total amount she buys as small as possible.

Input

The first line contains two integers nn and mm (0≤n≤10000000000 \le n \le 1000000000, 0<m≤200 < m \le 20): the number of microlitres of milk Maia wants, and the number of bag sizes the store sells.

Each of the next mm lines contains one integer aa (0≤a≤10000000000 \le a \le 1000000000): the size, in microlitres, of one bag the store sells.

Output

Print a single integer: the minimum total number of microlitres Maia must buy so that she has at least nn microlitres, using each offered bag at most once. If she cannot reach at least nn microlitres, print IMPOSSIBLE instead.

Examples3

  1. Example 1

    Input
    5859870 3
    3141592
    2718281
    1000000
    
    Expected output
    5859873
    
  2. Example 2

    Input
    15 3
    10
    5
    3
    
    Expected output
    15
    
  3. Example 3

    Input
    100 2
    10
    20
    
    Expected output
    IMPOSSIBLE