#include <bits/stdc++.h>

using namespace std;

typedef unsigned long long ull;

#define loop(i,a,b) for(int i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)

int main(){
    int n, m;
    while(cin >> n >> m, n+m){
        vector<int> v(m);
        int mb = 0;
        rep(i, m){ cin >> v[i]; mb = max(mb, v[i]);}
        int lb = -1, ub = 1500010;
        while(ub-lb > 1){
            int mid = (ub+lb)/2;
            int count = 1, width = 0;
            rep(i, m){
                width += v[i];
                if(mid < width){width = v[i]; count++;}
            }
            if(count <= n && mb <= mid){
                ub = mid;
            } else {
                lb = mid;
            }
        }
        cout << ub << endl;
    }
}