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

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define repr(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())

const int IINF = 1e9 + 10;
const long long LLINF = (long long)1e18 + 10;
const long long MOD = (long long)1e9 + 7;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

int n, m;
vector<int> w;
int maxi;

bool check(int mid){
    if(maxi > mid){
        return false;
    }
    int cnt = 1, sum = 0;
    rep(i, n){
        if(sum + w[i] <= mid){
            sum += w[i];
        }else{
            ++cnt;
            sum = w[i];
        }
    }
    return cnt <= m;
}

int meguru_search(int ok, int ng){
    while(abs(ok - ng) > 1){
        int mid = (ok + ng) / 2;
        if(check(mid)){
            ok = mid;
        }else{
            ng = mid;
        }
    }
    return ok;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    while(cin >> m >> n, m){

        w.resize(n);
        int sum = 0;
        maxi = 0;
        rep(i, n){
            cin >> w[i];
            sum += w[i];
            maxi = max(maxi, w[i]);
        }

        int ans = meguru_search(sum, 0);
        cout << ans << endl;

    }

    return 0;
}
