#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int m, n;
int w[111];

bool f(ll x) {
    ll step = 1, len = 0;
    for (int i = 0; i < n; i++) {
        if (len + w[i] <= x) len += w[i];
        else {
            step++;
            if (w[i] <= x) len = w[i];
            else return false;
        }
        if (step > m) return false;
    }
    return true;
}

int main() {
    while (cin >> m >> n && (m != 0 || n != 0)) {
        for (int i = 0; i < n; i++) cin >> w[i];
        ll ng = 0, ok = 1515151;
        while (ok - ng > 1) {
            ll md = (ok + ng) / 2;
            if (f(md)) ok = md;
            else ng = md;
        }
        cout << ok << endl;
    }
}
