#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<set>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll,ll> pll;
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
#define MOD 1000000007
#define ARRAY_MAX 100005

const int INF = 1e9+7;


bool check(int mid,vector<int>& w,int maxi_step){

    int now_step = 1;//現在の段数
    int sum = 0;//本の厚みの和
    for(int i = 0;i < w.size();i++){

        if(w[i] > mid){
            return false;//幅を超えている
        }

        if(sum + w[i] <= mid){
            sum += w[i];
        }else{
            sum = w[i];//次の段の最初の本
            now_step++;
        }
    }
    
    if(now_step <= maxi_step){
        return true;
    }else{
        return false;
    }
}

int solve(int maxi_step,vector<int>& w){//段数、本の厚み

    int ok = 1500000;
    int ng = 0;//(ng,ok]

    while(abs(ok-ng) > 1){
        int middle = (ok+ng)/2;//本棚1段の厚み
        if(check(middle,w,maxi_step)){
            ok = middle;
        }else{
            ng = middle;
        }
    }
    return ok;
}



int main(){

    int m,n;
    while(cin >> m >> n,m|n){

        vector<int> w(n);
        for(int i = 0;i < n;i++){
            cin >> w[i];
        }
        int ans = solve(m,w);
        cout << ans << endl;
        w.shrink_to_fit();
    }

    return 0;
}
