#D5218. Bookshelf
Bookshelf
Bookshelf
Taro is addicted to a novel. The novel has n volumes in total, and each volume has a different thickness. Taro likes this novel so much that he wants to buy a bookshelf dedicated to it. However, if you put a large bookshelf in the room, it will be quite small, so you have to devise to make the width of the bookshelf as small as possible. When I measured the height from the floor to the ceiling, I found that an m-level bookshelf could be placed. So, how can we divide the n volumes of novels to minimize the width of the bookshelf in m columns? Taro is particular about it, and the novels to be stored in each column must be arranged in the order of the volume numbers. ..
Enter the number of bookshelves, the number of volumes of the novel, and the thickness of each book as input, and create a program to find the width of the bookshelf that has the smallest width that can accommodate all volumes in order from one volume. However, the size of the bookshelf frame is not included in the width.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
m n w1 w2 :: wn
The first line gives m (1 ≤ m ≤ 20) the number of bookshelves that can be placed in the room and n (1 ≤ n ≤ 100) the number of volumes in the novel. The next n lines are given the integer wi (1 ≤ wi ≤ 1000000), which represents the thickness of the book in Volume i.
However, the width of the bookshelf shall not exceed 1500000.
The number of datasets does not exceed 50.
Output
Outputs the minimum bookshelf width for each dataset on one line.
Example
Input
3 9 500 300 800 200 100 600 900 700 400 4 3 1000 1000 1000 0 0
Output
1800 1000
inputFormat
input, and create a program to find the width of the bookshelf that has the smallest width that can accommodate all volumes in order from one volume. However, the size of the bookshelf frame is not included in the width.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
m n w1 w2 :: wn
The first line gives m (1 ≤ m ≤ 20) the number of bookshelves that can be placed in the room and n (1 ≤ n ≤ 100) the number of volumes in the novel. The next n lines are given the integer wi (1 ≤ wi ≤ 1000000), which represents the thickness of the book in Volume i.
However, the width of the bookshelf shall not exceed 1500000.
The number of datasets does not exceed 50.
outputFormat
Output
Outputs the minimum bookshelf width for each dataset on one line.
Example
Input
3 9 500 300 800 200 100 600 900 700 400 4 3 1000 1000 1000 0 0
Output
1800 1000
样例
3 9
500
300
800
200
100
600
900
700
400
4 3
1000
1000
1000
0 0
1800
1000
</p>