#include <iostream>
#include <algorithm>
using namespace std;

int m,n;
int b[100];
int check(int w){
	int cnt=1;
	int tmp=0;
	for(int i=0;i<n;i++){
		if(b[i]>w)return 0;
		if(tmp+b[i]<=w)tmp+=b[i];
		else{
			tmp=b[i];
			cnt++;
		}
	}
	if(m>=cnt)return 1;
	return 0;
}

int main(){
	while(cin>>m>>n,m){
		for(int i=0;i<n;i++){
			cin>>b[i];
		}
		
		int safe=1500000,out=1;
		while(safe-out>1){
			if(check((out+safe)/2)){
				safe=(out+safe)/2;
			}
			else{
				out=(out+safe)/2;
			}
		}
		cout<<safe<<endl;
	}
	
	
	return 0;
}
