//AOJ:0181 Persistence

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>

using namespace std;

#define MAX -210000000
#define MIN 210000000
#define HABA 1500000

int n,m,book[101];
int low,high,tana,cunt,mid,flg;
int main(){
	
	while(1){
		scanf("%d %d",&m,&n);
		if(m==0 && n==0) break;
		for(int i=0;i<n;i++) scanf("%d",&book[i]);
		low=0;
		high=HABA;
		while(low<=high/*k!=50*/){
			mid=(low+high)/2;
			//printf("mid=%d\n",mid);
			tana=0;
			cunt=1;
			flg=0;
			for(int i=0;i<n;i++){
				if(tana+book[i]>mid && tana==0){//printf("%d low=%d high=%d mid=%d cunt=%d\n",k,low,high,mid,cunt);
				//	printf("??\???????????¬?????????\n");
					flg=1;
					break;
				}
				if(tana+book[i]>mid){
					cunt++;
					if(cunt>m){
					//	printf("?£?????¶??????????\n");
						flg=1;
						break;
					}
					tana=book[i];
				}else tana+=book[i];
			}
			if(flg==1){
				low=mid+1;
				//printf("k low  %d\n",low);
			}else high=mid-1;
		}
		printf("%d\n",low);
	}
	
	return 0;
}