#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

const int INF=1e9;

signed main() {
	int n, m;
	while (1) {
		cin >> n >> m;
		if (n + m == 0) break;
		vi d(m);
		rep(i, 0, m) {
			cin >> d[i];
		}
		int MIN = INF;
		rep(i, 1, m + 1) {
			int sum = 0, cnt = 1, tmp = 0;
			rep(j, 0, i) {
				sum += d[j];
			}
			if (i < m) cnt++;
			rep(j, i, m) {
				if (tmp + d[j] <= sum && tmp + d[j] <= 1500000) {
					tmp += d[j];
				}
				else {
					tmp = d[j];
					cnt++;
				}
			}
			//cout << i << " " << sum << " " << cnt << endl;
			if (cnt <= n) {
				MIN = min(MIN, sum);
			}
		}
		cout << MIN << endl;
	}
}