#include<cstdio>
#include<iostream>

using namespace std;
#define INF 1500000


int main(void) {

	while (1) {
		int max = INF, min = 0;
		int floor, n, book[102] = { 0 };
		cin >> floor >> n;

		if (floor == 0)return 0;

		for (int i = 0; i < n; i++) {
			cin >> book[i];
		}
		while (max - min > 1) {
			int count = floor;
			int  mid = (max + min) / 2;
			int length = mid;
			int i = 0;
			while (count != 0 && i < n) {
				if (length >= book[i]) {
					length -= book[i];
					i++;
				}
				else {
					length = mid;
					count = count - 1;
				}
			}	
				if (count != 0) {
					max = mid;
				}else {
					min = mid;
				
			}
		}
		cout << max << endl;
	}
}