#include <bits/stdc++.h>
using namespace std;
#define rep(i,b) range(i,0,b)
#define range(i,a,b) for(int i = (a); i < (int)(b); i++)

int m,n;
vector<int> a;

bool ok(int x){
    int k = 0;
    rep(i,m){
        int t = 0;
        while(k != n){
            if(t + a[k] > x) break;
            t += a[k];
            k++;
        }
    }
    return k == n;
}

int main(){
    while(cin >> m >> n && m){
        a.resize(n);
        rep(i,n) cin >> a[i];
        int l = 0, r = 1e8;
        while(l+1 < r){
            int m = (l+r)/2;
            if(ok(m)) r = m; else l = m;
        }
        cout << r << endl;
    }
}