#include <iostream>
#include <vector>
#include <string>
#include <climits>

using namespace std;

bool a(vector < int > book, int mid, int m) {
	vector < int > total(m);
	int count = 0;

	for(int i = 0; i < m; i++) {
		for(int j = count; j < book.size(); j++) {
			total[i] += book[j];
			count++;
			if(total[i] > mid) {
				total[i] -= book[j];
				count--;
				break;
			}
		}
	}

	if(count == book.size()) {
		return true;
	} else {
		return false;
	}
}

int main() {
	int n, m;

	

	while ( true ) {
		cin >> m >> n;

		if(!m && !n) {
			break;
		}
		vector < int > book(n);

		for(int i = 0; i < n; i++) {
			cin >> book[i];
		}

		int bottom = 0, top = 1500000;

		for(int i = 1; i <= 100; i++) {
			int mid = (bottom + top) / 2;
			if( a(book, mid, m) ) {
				top = mid;
			} else {
				bottom = mid + 1;
			}
		}

		cout << (bottom + top) / 2 << endl;
	}
}