#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

int w[200];

bool judge(int num, int length, int height){
	int count = 0;
	int sum = 0;
	for(int i = 0; i < length; i++){
		if(w[i] > num){
			return false;
		}
		if(sum + w[i] > num){
			count++;
			sum = w[i];
		}else{
			sum += w[i];
		}
	}
	count++;
	if(count <= height){
		return true;
	}
	return false;
}

int binary_search(int lef, int rig, int m, int n){
	int middle = (lef + rig) / 2;
	if(rig - lef <= 1){
		if(judge(lef, n, m)){
			return lef;
		}else{
			return rig;
		}
	}
	if(judge(middle, n, m)){
		rig = middle;
		return binary_search(lef, rig, m, n);
	}else{
		lef = middle;
		return binary_search(lef, rig, m, n);
	}
}

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