#include<cstdio>
#include<iostream>
#include<string>
#include<map>
#include<queue>
#include<set>

using namespace std;

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

int main(){
	while(1){
		int n,m;
		cin>>n>>m;
		if(n==0)break;
		
		int hon[1000];
		rep(i,m){
			cin>>hon[i];
		}
		
		int right,left;
		right=0;
		left=1000000000;
		
		int ans;
		while(1){
			double harf = double(right+left)/2;
			
			int cont=0;
			int sum=0;
			
			int flg=1;
			rep(i,m){
				if(sum+hon[i]<=harf){
					sum+=hon[i];
				}else{
					i--;
					cont++;
					sum=0;
				}
				
				if(cont>=n){
					flg=0;
					break;
				}
			}
			
			if(flg==0){
				right=harf;
			}else{
				left = harf+0.5;
			}
			
			ans=left;
			if(right+1 == left)break;
		}
		
		printf("%d\n",ans);
	}
}