#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

using int64 = int64_t;

constexpr int64 MOD = 1000000007;

int M, N;
int arr[100];

int main() {
    while (true) {
        cin >> M >> N;
        if (M+N == 0) break;
        for (int j = 0; j < N; ++j) {
            cin >> arr[j];
        }

        int l = 0, r = 1500000;
        while (l < r) {
            int m = (l+r) / 2;
            int row = 0, acc = 0;
            bool ok = true;
            for (int j = 0; j < N; ++j) {
                if (m-acc < arr[j]) {
                    ++row;
                    acc = 0;
                }
                if (row == M || m < arr[j]) {
                    ok = false;
                    break;
                } 
                if (m-acc >= arr[j]) {
                    acc += arr[j];
                }
            }
            if (ok) {
                r = m;
            } else {
                l = m+1;
            }
        }
        cout << r << endl;
    }
    return 0;
}