#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>

using namespace std;

int m, n;
vector <int> book;

int f(int);

int main(){
	while(1){
		cin >> m >> n;
		if(m == 0 && n == 0)
			break;
		
		book = vector <int> (n);
		for(int i = 0; i < n; i++)
			cin >> book[i];
		
		int low = *max_element(book.begin(), book.end());
		int high;
		for(int i = 0; i < n; i++)
			high += book[i];
		int mid = (low + high) / 2;
		
		while(1){
			if(f(mid) == 1)
				high = mid;
			else
				low = mid + 1;
			
			if(low == high){
				cout << low << endl;
				break;
			}
			mid = (low + high) / 2;
		}
	}
	
	return 0;
}

int f(int width){
	int count = 0;
	int w = width;
	
	for(int i = 0; i < n; i++){
		if(book[i] <= w)
			w -= book[i];
		else{
			count++;
			if(count >= m)
				return 0;
			w = width - book[i];
		}
	}
	return 1;
}