#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int M;
int N;
const int INF = 1500000;
vector<int> book;

bool c(int x) {
	int d = 1;
	int wid = 0;
	for (int i = 0; i < N; i++) {
		wid += book[i];
		if (wid > x) {
			wid = 0;
			d++;
			i--;
		}
	}
	return d <= M;
}

int main(void) {
	while (cin >> M >> N, N) {
		// input
		book.clear();
		int buf;
		for (int i = 0; i < N; i++) {
			cin >> buf;
			book.push_back(buf);
		}

		// calc
		int l = *(max_element(book.begin(), book.end())) - 1, u = INF;
		while (u - l > 1) {
			int mid = (l + u) / 2;
			if (c(mid)) {
				u = mid;
			}else {
				l = mid;
			}
		}

		// output
		cout << u << endl;
	}

	return 0;
}