#include <string>
#include <vector>
#include <cmath>
#include <ctime>
#include <iostream>
#include <cstdio>
#include <set>
#include <map>
#include <queue>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <cstring>
#include <limits>
using namespace std;
typedef long long ll;

int n, m;
int book[110];

bool can(int W){
	int cnt = 1;
	int w = 0;

	for(int i=0;i<n;i++){
		if(w + book[i] <= W){
			w += book[i];
		} else {
			++cnt;
			w = book[i];
		}
	}

	return (cnt <= m);
}

int main(){
	while(cin >> m >> n){
		if(n == 0 && m == 0)break;
		for(int i=0;i<n;i++)cin >> book[i];

		int sum = accumulate(book, book + n, 0);
		int maxi = *max_element(book, book + n);

		int low = maxi - 1, high = sum;

		while(high - low > 1){
			int mid = (high - low) / 2 + low;
			if(can(mid))high = mid; else low = mid;
		}

		cout << high << endl;
	}
	return 0;
}