#include<iostream>
#include<cstring>
#include<algorithm>

using namespace std;

int Width[100];
int M, N;


bool solve(int limit) {
	int nowWidth, nowSumShelf;

	nowWidth = 0;
	nowSumShelf = 1;
	for (int i = 0; i < N; ++i) {
		if (nowWidth + Width[i] <= limit) {
			nowWidth += Width[i];
			continue;
		}
		nowWidth = 0;
		--i;
		++nowSumShelf;
		if (nowSumShelf > M) {
			return false;
		}
	}
	return true;
}

int main() {
	int left, right, mid;

	while (cin >> M >> N, M) {
		for (int i = 0; i < N; ++i) {
			cin >> Width[i];
		}

		left = 0;
		right = 1500001;
		while (left < right) {
			mid = (left + right) / 2;
			//cout << "left:" << left << "  mid:"<<mid<<"  right:" << right << endl;
			if (solve(mid)) {
				right = mid;
			}
			else {
				left = mid + 1;
			}
		}
		cout <<left << endl;
	}

	return 0;
}


