#T232. 装箱问题

装箱问题

Description

There is a box with a capacity of V (a positive integer, 0 ≤ V ≤ 20000), and there are n items (0 < n ≤ 30), each with a volume (a positive integer).
The task is to select any number of these n items to pack into the box such that the remaining space in the box is minimized.

Input Format

The first line is an integer V, representing the box's capacity.
The second line is an integer n, representing the number of items.
The next n lines each contain a positive integer (not exceeding 10000), representing the volume of each of the n items.

Output Format

An integer representing the remaining space in the box.

24
6
8
3
12
7
9
7


0