#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <tuple>
#include <queue>
#include <functional>
using namespace std;
const int INF = 1 << 30;
int main(){
	int m,n;
	while (cin >>m >>n, n) {
		vector<int> a(n);
		for (int &x : a)cin >> x;
		int min = 0, max = 1500000;
		while (min != max) {
			int mid = (min + max) / 2;
			int dan = 0;
			int w = 0;
			for (int x : a) {
				w += x;
				if (w > mid) {
					if (x > mid) {
						dan = m;
						break;
					}
					dan++;
					w = x;
				}
			}
			if (dan < m)max = mid;
			else min = mid + 1;
		}
		cout << min << endl;
	}
	return 0;
}