#include<cstdio>

#define	rep(i,n)	for(int i=0;i<(n);i++)

using namespace std;

int m,n,book[100];

bool check(int w){
	int h=1,pos=0;
	rep(i,n){
		if(book[i]>w)	return false;
		if(pos+book[i]<=w)	pos+=book[i];
		else				pos=book[i],h++;
	}
	return h<=m;
}

int main(){
	while(scanf("%d%d",&m,&n),m){
		rep(i,n)	scanf("%d",book+i);

		int lo=0,hi=1500000;
		while(lo<hi){
			int mi=(lo+hi)/2;
			if(check(mi))	hi=mi;
			else			lo=mi+1;
		}

		printf("%d\n",lo);
	}

	return 0;
}