#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

long long int len[1000];

int n, m;

bool check(long long int w){
	int count = 0;
	int sum = 0;
	for(int i = 0; i < n; i++){
		if(len[i] > w){
			return false;
		}
	}
	for(int i = 0; i < n; i++){
		sum += len[i];
		if(sum > w){
			sum = len[i];
			count++;
		}
	}
	count += 1;
	return count <= m;
}

long long int bin_search(long long int wmin, long long int wmax){
	if(wmax - wmin <= 1){
		if(check(wmin)){
			return wmin;
		}else{
			return wmax;
		}
	}
	long long int wmid = (wmin + wmax) / 2;
	if(check(wmid)){
		wmax = wmid;
	}else{
		wmin = wmid;
	}
	bin_search(wmin, wmax);
}

int main(){
	
	while(true){
		cin >> m >> n;
		if(n == 0 && m == 0){
			break;
		}
		for(int i = 0; i < n; i++){
			cin >> len[i];
		}
		
		cout << bin_search(0, 2000000) << endl;
	}
	
	return 0;
}