#include <iostream>

using namespace std;

typedef unsigned long long ull;

int m, n;
double avg;
ull books[100];

bool judge(int i, ull width)
{
	ull w = 0;
	int h = 2;
	for(int k=i+1; k<n; k++)
	{
		w += books[k];
		if(w > width)
		{
			w = books[k];
			h++;
		}

		if(h > m) return false;
	}

	return true;
}

ull solve()
{
	ull width = 0;
	for(int i=0; i<n; i++)
	{
		width += books[i];
		if(width > 0)
		{
			if(judge(i, width)) return width;
		}
	}

	return -1;
}

int main()
{
	while( 1 )
	{
		cin >> m >> n;
		if(m==0 && n==0) break;
		
		avg = 0.0;
		for(int i=0; i<n; i++)
		{
			scanf("%llu", &books[i]);
			avg += books[i];
		}
		avg /= (float)n;

		ull ans = solve();
		printf("%llu\n", ans);
	}
}