#include <iostream>
using namespace std;

int m,c,maxim,minim,k;
int bc[100];

int search(int w){
    int empty = 0;
    int d = 1;
    for(int i = 0; i < c; i++){
        if(empty + bc[i] >= w){
            if(d == m){
                return 0;
            }else{
                d++;
                empty = bc[i];
            }
        }else{
            empty += bc[i];
        }
    }
    //cout << "ばーか" << w <<endl;
    return 1;
}

int saiki(int n,int s){
    //cout << n << " " << s << endl;
    if(s <= 2){
        if(search(n + 1)==1){
            return n;
        }else{
            return n + 1;
        }
    }else{
        if(s % 2 == 1){
            if(search(n + (s + 1) / 2)==1){
                return saiki(n, (s + 1) / 2);
            }else{
                return saiki(n + (s + 1) / 2, (s + 1) / 2);
            }
        }else{
            if(search(n + s / 2)==1){
                return saiki(n, s / 2);
            }else{
                return saiki(n + s / 2, s / 2);
            }
        }
    }
}

int main(){
    for(;;){
        maxim = 0;
        minim = 0;
        if(cin >> m >> c){
            if(m == 0 && c == 0){
                break;
            }else{
                for(int i = 0; i < c; i++){
                    cin >> bc[i];
                    maxim += bc[i];
                    if(minim <= bc[i]){
                        minim = bc[i];
                    }
                    //cout << bc[i] << endl;
                }
                cout << saiki(minim, maxim-minim) << endl;
            }
        }else{
            break;
        }
    }
    return 0;
}