#include <iostream>

using namespace std;

int n, m;
int books[100];

bool solve(int width)
{
	int w, h;
	w = 0;
	h = 1;
	for(int i=0; i<n; i++)
	{
		if(w > width) return false;
		if(w + books[i] > width)
		{
			h++;
			w = 0;
		}
		w += books[i];
	}

	return h <= m;
}

int main()
{
	while( 1 )
	{
		scanf("%d", &m);
		scanf("%d", &n);
		if(m==0 && n==0) break;

		for(int i=0; i<n; i++)
		{
			scanf("%d", &books[i]);
		}

		int upper = 1500001;
		int lower = 0;
		
		while(upper - lower > 1)
		{
			int mid = (upper + lower) / 2;
			if(solve(mid)) upper = mid;
			else  lower = mid;
		}

		printf("%d\n", solve(lower) ? lower : upper);
	}
}