#include <iostream>
#include <vector>
using namespace std;

typedef long long ll;

int main() {
	int n, m;
	while(cin >> m >> n, n || m) {
		vector<int> v;
		v.resize(n);
		for(int i = 0; i < n; i++)
			cin >> v[i];

		ll l, r, res;
		l = 0; r = 1600000;
		res = -1;
		while(l <= r) {
			int mid = (l + r) / 2;
			int d = 0;
			int cnt = 0;
			for(int i = 0; i < v.size(); i++) {
				if(d + v[i] > mid) {
					if(d == 0) {
						cnt = 1e9;
						break;
					}
					d = 0;
					i--;
					cnt++;
				}
				else
					d += v[i];
			}

			if(cnt < m) {
				res = mid;
				r = mid-1;
			}
			else {
				l = mid+1;
			}
		}
		cout << res << endl;
	}
}