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

int n, m, max_a;
int a[100000];

bool check(int k) {
	int num = 1, sum = 0;
	for(int i = 0; i < n; i++) {
		sum += a[i];
		if(sum > k) {
			num++;
			sum = a[i];
		}
	}
	return num <= m;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	while(cin >> m >> n, m) {
		for(int i = 0; i < n; i++) {
			cin >> a[i];
		}
		max_a = *max_element(a, a + n);

		int ng = max_a - 1, ok = max_a * n;
		while(abs(ng - ok) > 1) {
			int mid = (ng + ok) / 2;
			if(check(mid)) ok = mid;
			else ng = mid;
		}

		cout << ok << endl;
	}
}