#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF 99999999


int m,n;
int b[110];

bool solve(int v){
    int l=0;
    int x=v;
    rep(i,n){
        while(x<b[i]&&l<m){
            x=v;
            l++;
        }
        if(l>=m)return false;
        if(x>=b[i]){
            x-=b[i];
        }
    }
    return true;
}

int main(){
    while(cin>>m>>n){
        if(m==0&&m==0)break;
        rep(i,n)cin>>b[i];
        
        int left=0;
        int right=1500000-1;
        while(right>left+1){
//            cout<<left<<" "<<right<<endl;
            int cent=(left+right)/2;
            bool res = solve(cent);
            if(res) right=cent;
            else left=cent;
        }
        cout<<right<<endl;
    }
}