#include <iostream>
#include <cstdlib>
#define MAX_N 100
#define INF 1500000
using namespace std;
int t[MAX_N];
int m, n;

bool C(int x) {
	int i, sum, shelf = m;
	
	i = 0;
	while (shelf--) {
		sum = 0;
		while (i < n && sum + t[i] <= x) {
			sum += t[i];
			i++;
		}
	}
	return i == n;
}

int solve() {
	int ok = INF, ng = 0, mid;
	while (abs(ok - ng) > 1) {
		mid = (ok + ng) / 2;
		if (C(mid)) ok = mid;
		else ng = mid;
	}
	return ok;
}

int main() {
	while (cin >> m, m) {
		cin >> n;
		for (int i = 0; i < n; ++i) {
			cin >> t[i];
		}
		cout << solve() << endl;
	}
	return 0;
}