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

#define loop(i)    for(int lp=0; lp<(i); lp ++)
#define ascent(i,a,b) for(int i=(a); i<(b); i ++)

#define pb push_back

using namespace std;

int m, n;

int max(vector<int> vec) {
	int max = 0;
	ascent(i, 0, n) {
		if(max < vec[i]) max = vec[i];
	}
	
	return max;
}

int main() {
	vector<int> a;
	
	while(cin >> m >> n, m||n) {
		int ans = 0;
		
		a.clear();
		int tmp;
		loop(n) {
			cin >> tmp;
			a.pb(tmp);
		}
		
		int l=0, r=0;
		ascent(i,0,n) {
			r+= a[i];
		}
		int mid;
		while(r-l>1) {
			mid = (l+r)/2;
			
			if(mid < max(a)) {
				l = mid;
			}
			else {
				int count = m-1;
				int a_sum = 0;
				vector<int> tmpvec;
				for(int i=0; i<n; i++) {
					if(a_sum + a[i] > mid) {
						tmpvec.pb(a_sum);
						a_sum = a[i];
						count --;
					}
					else {
						a_sum += a[i];
					}
				}
//				tmpvec.pb(a_sum);
//				cout << mid << " " << count << endl;
//				ascent(i, 0, tmpvec.size()) {
//					cout << " " << tmpvec[i];
//				}
//				cout << endl;
				
				if(count >= 0) {
					ans = mid;
				}
				
				if(count == m || count < 0) l=mid;
				else r=mid;
			}
		}
		cout << ans << endl;
	}
	return 0;
}