#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int m, n;
    while(cin >> m >> n, m){
        vector<int> v(n);
        for (auto &&i : v) scanf("%d", &i);
        int ng = *max_element(v.begin(),v.end())-1, ok = 1500001;
        while(ok-ng > 1){
            int mid = (ok+ng)/2;
            int val = 0, cnt = 1;
            for (int i = 0; i < n; ++i) {
                if(val+v[i] > mid){
                    cnt++; val = v[i];
                }else {
                    val += v[i];
                }
            }
            if(cnt <= m) ok = mid;
            else ng = mid;
        }
        cout << ok << "\n";
    }
    return 0;
}
