#include <iostream>
#include <algorithm>

using namespace std;

const int INF = 1500000-1;
const int MAX_N = 100;

int M, N;
int W[MAX_N];

bool C ( int x )
{
	int sum = 0, res = 1;

	for (int i = 0; i < N; ++i) {
		if (sum+W[i] <= x) {
			sum += W[i];
		}
		else {
			++res;
			if (x < W[i]) { return false; }
			sum = W[i];
		}
	}
	return M >= res;
}

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

		int l = 0, u = INF;

		while (u-l > 1) {
			int mid = (l + u) / 2;
			if (C(mid)) {
				u = mid;
			}
			else {
				l = mid;
			}
		}

		cout << u << endl;
	}
	return 0;
}