#include<bits/stdc++.h>
using namespace std;

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int M,N;
int W[100];

bool C(int x){
    int cnt=0;
    int cur=0;
    while(cur<N){
        int next=cur;
        int sum=0;
        while(next<N&&sum+W[next]<=x)sum+=W[next++];
        cur=next;
        cnt++;
    }
    return cnt<=M;
}

signed main(){
    while(cin>>M>>N,M||N){
        rep(i,N)cin>>W[i];
        int lb=*max_element(W,W+N)-1,ub=1500000;
        while(ub-lb>1){
            int mid=(ub+lb)/2;
            if(C(mid))ub=mid;
            else lb=mid;
        }
        cout<<ub<<endl;
    }
    return 0;
}