#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int m, n;
int w[110];

bool judge(ll x) {
    int cnt = 1;
    ll acc = 0;
    
    for (int i=0; i<n; i++) {
        if (acc+w[i]>x) {
            cnt++;
            if (w[i]>x) return false;
            else acc = w[i];
        }
        else acc += w[i];
    }
    
    return cnt<=m;
}

ll binary_search() {
    ll l=0, r=1000000*n;
    
    while (l<=r) {
        ll mid = (l+r)/2;
        
        if (judge(mid)) r = mid-1;
        else l = mid+1;
    }
    
    return l;
}

int main() {
    while (true) {
        cin >> m >> n;
        if (m==0) break;
        for (int i=0; i<n; i++) cin >> w[i];
        cout << binary_search() << endl;
    }
}
