#include <iostream>
using namespace std;

int m,n,*b,ans;

int max(int *l, int size){
	int tmp = l[0];
	for(int i=1; i<size; i++)
		if(tmp < l[i])
			tmp = l[i];
	return tmp;
}

int min(int *l, int size){
	int tmp = l[0];
	for(int i=0; i<size; i++)
		if(tmp > l[i])
			tmp = l[i];
	return tmp;
}

bool bbb(){
	int j=0;
	int a[m];
	for(int i=0; i<m; i++){
		a[i] = 0;
		for(; j<n; j++){
			a[i] += b[j];
			if(a[i] > ans){
				a[i] -= b[j];
				break;
			}
		}
	}
	if(j == n)
		return true;
	else
		return false;
}

void solve(){
	int plus = min(b, n);
	while(true){
		if(bbb())
			return;
		ans += plus;
	}
}

int main(){
	while(true){
		cin >> m >> n;
		if(!m && !n)
			return 0;
		b = new int[n];
		for(int i=0; i< n; i++)
			cin >> b[i];
		ans = max(b, n);
		solve();
		cout << ans << endl;
		delete[] b;
	}
}