DWITE Online Computer Programming Contest
October 2007
Problem 4
Stacks of Blocks

Some kids play with blocks, and build things by stacking different blocks on top of each other. Given a set of blocks and a target height, we want to find out if it's possible to construct a stack with an exact specified height.

The input file DATA4.txt will contain at least 3 lines, one positive integer value per line. The first line will contain an integer H, the target height for the stack. 0 < H < 100

The second line will contain an integer S, number of blocks in a set. 0 < S < 10

The next S lines will contain integers, one per line; 0 < N < 10; representing the height of blocks in the set.

The output file OUT4.txt will contain a single interger value, a minimum number of blocks out of the supplied set, required to build a stack of the given height. If it is impossible to build the desired stack, output 0.

Sample Input:
5
3
1
2
3
        
Sample Output:
2
        
Sample Input:
10
3
1
5
7
        
Sample Output:
0