#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

vector<int> books;
int m,n;

bool check(int r){
	int rank=0;
	int place=0;
	for(int i = 0; i < books.size(); i++){
		if(books[i]>r)
			return false;
		// àµTCYª éå«³æè¬³¯êÎ
		if(place+books[i]<=r){
			place+=books[i];
		}
		else{
			rank++;
			if(rank>=m)
				return false;
			place=0;
			place+=books[i];
		}
	}
	return true;
}

int main(){

	while(cin>>m>>n&&!(n==0&&m==0)){
		for(int i = 0; i < n; i++){
			int t;
			cin>>t;
			books.push_back(t);
		}

		int ub=1500000;
		int lb=-1;
		while(ub-lb>1){
			int med=ub+lb;
			med/=2;
			// ¨¯éÈç
			if(check(med)){
				ub=med;
			}
			else{
				lb=med;
			}
		}
		cout<<ub<<endl;
		books.clear();
	}
	
	return 0;
}