#include <iostream>
#include <vector>

using namespace std;

int main() {
	int m, n;
	while (cin >> m >> n) {
		if (m == 0 && n == 0) {
			break;
		}
		vector<int> d(n);
		for (int i = 0; i < n; i++) {
			cin >> d[i];
		}
		int lb = 0;
		int rb = 1500000;
		while (rb-lb > 1) {
			int mid = (lb+rb)/2;
			int mm = 1;
			int c = 0;
			bool h = true;
			for (int i = 0; i < n; i++) {
				if (d[i] > mid) {
					h = false;
					break;
				}
				c += d[i];
				if(c > mid) {
					mm++;
					c = 0;
					i--;
				}
			}
			if (mm > m) {
				h = false;
			}
			if (h) {
				rb = mid;
			} else {
				lb = mid;
			}
		}
		cout << rb << endl;
	}
	return 0;
}