#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
vector<int>V;
int main(){
    int m,n;
    while(cin>>m>>n,m||n){
        V.clear();
        V.resize(n);
        int Max=0;
        for(int i=0;i<n;i++){
            cin>>V[i];
            Max=max(Max,V[i]);
        }
        int l=Max,r=100000000;
        while(r-l>=1){
            int mid=(l+r)/2;
            int cnt=1,leftW=mid;
            for(int i=0;i<n;i++){
                if(leftW>=V[i])leftW-=V[i];
                else{
                    cnt++;
                    leftW=mid-V[i];
                }
            }
            if(m<cnt)l=mid+1;
            else r=mid;
        }
        cout<<r<<endl;
    }
    return 0;
}