#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include <string>
#include <complex>
#include <functional>
using namespace std;
typedef pair<int,int> P;

int main(){
    int a,b,i;
    int w[100];
    while(cin>>a>>b&&a){
        int max=1500000;
        int min=1,res=0,dan=1;
        for(i=0;i<b;i++) {
            cin>>w[i];
            if(min<w[i]) min=w[i];
        }
        while(max-min>1){
            int hf=(max+min)/2;
            int j;
            res=0;
            dan=1;
            for(j=0;j<b;j++){
                if(res+w[j]<=hf) res+=w[j];
                else{
                    dan++;
                    res=w[j];
                }
            }
            if(dan<=a) max=hf;
            else min=hf;
        }
        int ans=min;
        res=0,dan=1;
        for(i=0;i<b;i++){
            if(res+w[i]<=ans) res+=w[i];
            else{
                dan++;
                res=w[i];
            }
        }
        if(dan<=a) cout<<ans<<endl;
        else cout<<max<<endl;
    }
    return 0;
}
