#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)

int n, m, w[105];

bool check(int x){
    int cnt = 1, sum = 0;
    REP(i,n){
        if(sum+w[i] <= x) sum += w[i];
        else{
            if(w[i] > x)return false;
            cnt++;
            sum = w[i];
        }
    }
    return cnt <= m;
}

int main() {
    while(cin >> m >> n, n){
        REP(i,n) cin >> w[i];
        int ok = 1500000, ng = 0;
        while(abs(ok-ng)>1){
            int mid = (ok+ng)/2;
            if(check(mid)) ok = mid;
            else ng = mid;
        }
        cout << ok << endl;
    }
    return 0;
}   

