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

using namespace std;

int main(void){
	int m,n;
	
	while(cin >> m >> n){
		if(!(m|n)) break;
		int lb=0,ub=1500000;
		int mini = 1 << 29;
		vector<int> books(n);
		for(int i=0;i<n;i++){
			cin >> books[i];
			mini = min(mini, books[i]);
		}
		while(ub - lb > 1){
			int mid = (lb + ub) / 2;
			int count=1;
			int tmp=0;
			for(int i=0;i<n;i++){
				if(tmp + books[i] <= mid){
					tmp += books[i];
				}else{
					tmp = books[i];
					count++;
				}
			}
			if(count <= m && mid >= mini){
				ub = mid;
			}else{
				lb = mid;
			}
		}
		cout << ub << endl;
	}
}