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

template<typename T>
T in(){T tmp; cin >> tmp; return tmp;}

int n, m;
int book[100];

int search(int low, int high);

int main()
{

    while (scanf("%d %d", &m, &n), m){
        int sum = 0;
        int maxi = 0;

        for (int i = 0; i < n; i++){
            scanf("%d", book + i);
            sum += book[i];
            maxi = max(maxi, book[i]);
        }
        printf("%d\n", search(maxi, min(1500000, sum)));
    }

    return 0;
}

int search(int low, int high)
{
    int mini, maxi;

    mini = low, maxi = high;
    while (mini < maxi){
        int sum;
        int now = 1;
        int middle = (mini + maxi) / 2;
        bool flag = true;

        sum = 0;
        for (int i = 0; i < n; i++){
            if (sum + book[i] > middle){
                now++;
                if (now > m){
                    mini = middle + 1;
                    flag = false;
                    break;
                }
                sum = book[i];
            }
            else {
                sum += book[i];
            }
        }
        if (flag){
            maxi = middle;
        }
    }

    return mini;
}