#include<cstdio>
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<map>

using namespace std;

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

typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<int,int> pii;


int main(){
	A:;
	int n,m;
	cin>>n>>m;
	if(n==0)return 0;
	
	int sina[101];
	rep(i,m){
		cin>>sina[i];
	}
	
	int st = 0, en = 1500000;
	
	while(1){
		int half = (st+en)/2;
		
		int dan = 0;
		int sum = 0;
		int ind = 0;
		
		bool erflg = false;
		
		//printf("%d %d %d\n",st,en,half);
		while(1){
			//printf("%d %d %d\n",dan,sum,ind);
			if(ind >= m)break;
			if(dan > n)break;
			if(sum+sina[ind]<=half){
				sum += sina[ind];
				ind++;
			}else{
				sum = 0;
				dan++;
			}
			
		}
		
		if(dan>=n){
			st = half;
		}else{
			en = half;
		}
		
		if(st+1 >= en)break;
	}
	
	printf("%d\n",en);
	
	goto A;
}