#include<iostream>
using namespace std;
int m, n;
int a[1000];
bool check(int v) {
	int cnt = 0, s = 1000000000;
	for (int i = 0; i < n; i++) {
		if (a[i] > v)return false;
	}
	for (int i = 0; i < n; i++) {
		if (s + a[i] > v) {
			cnt++;
			s = a[i];
		}
		else {
			s += a[i];
		}
	}
	if (cnt > m)return false;
	return true;
}
int main() {
	while (true) {
		cin >> m >> n;
		if (m == 0 && n == 0) { break; }
		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}
		int L = 0, R = 100000000, M;
		for (int i = 0; i < 50; i++) {
			M = (L + R) / 2;
			bool r1 = check(M - 1);
			bool r2 = check(M);
			if (r1 == true)R = M;
			if (r2 == false) { L = M; }
		}
		cout << M << endl;
	}
	return 0;
}