#include<iostream>
#include<vector>
#include<climits>

using namespace std;

bool check(vector<int> vi,int m,int mid){
	int buf=0;
	int use=0;
	for(int i=0;i<vi.size();i++){
		if(buf+vi[i] > mid){
			if(buf == 0){
				return false;
			}
			use++;
			buf=0;
			i--;
			continue;
		}
		buf += vi[i];
	}
	if(buf != 0){
		use++;
	}
	if(use <= m){
		return true;
	}else{
		return false;
	}

}

int main(){
	while(true){
		int m,n;
		cin >> m >> n;
		if(m==0){
			break;
		}

		vector<int> vi;
		int l=INT_MAX,u=1500001;
		for(int i=0;i<n;i++){
			int buf;
			cin >> buf;
			l = min(l,buf);
			vi.push_back(buf);
		}

		for(int i=0;i<100;i++){
			int mid = (l+u)/2;
			if(check(vi,m,mid)){
				u = mid;
			}else{
				l = mid+1;
			}
		}
		cout << ((l+u)/2) << endl;
	}
}