#include <iostream>
using namespace std;

int n,m,w[100];


bool C(int width){
	int now = 0,b = 0;
	for(int i = 0;i < n;i++){
		if(now + w[i] > width){
			now = w[i];
			b++;
		}else now += w[i];
		if(b >= m) return false;
	}
	return true;
}

int main(){
	while(cin >> m >> n,n){
		int ma = 0;
		for(int i = 0;i < n;i++) {
			cin >> w[i];
			ma = max(ma,w[i]);
		}
		int low = ma - 1,up = 1500000;
		while(up - low > 1){
			int mid = (low + up) / 2;
			if(C(mid)) up = mid;
			else low = mid;
		}
		cout << up << endl;
	}
	return 0;
}