#include <bits/stdc++.h>
using namespace std;

int n;
int a[100];

bool check(int x, int r)
{
	int st = 0;
	for (int i = 0; i < n; i++){
		if (a[i] > x) return false;
		if (st + a[i] > x){
			--r;
			st = 0;
		}
		st += a[i];
	}
	
	return r > 0;
}

int main()
{
	int m;
	while (scanf("%d %d", &m, &n), n){
		for (int i = 0; i < n; i++){
			scanf("%d", &a[i]);
		}
		
		int l = 1, r = 1500000;
		while (l <= r){
			int mid = (l + r) / 2;
			if (check(mid, m)) r = mid - 1;
			else l = mid + 1;
		}
		
		printf("%d\n", l);
	}
	
	return 0;
}