#include <cstdio>
using namespace std;

int main()
{
	int M,N;
	while(scanf("%d%d", &M,&N), (M||N))
	{
		int wid[100]={0}, swid=0;
		for(int i=0; i<N; i++)
		{
			scanf("%d", &wid[i]);
			swid+=wid[i];
		}
		
		int hi=swid, lo=0,mi;
		
		while(hi>lo)
		{
			mi=(hi+lo)/2;
			int cap=0, d=1;
			bool g=true;
			for(int i=0; i<N; i++)
			{
				if(mi < wid[i])
				{
					g=false;
					break;
				}
				if(cap+wid[i] > mi)
				{
					cap=wid[i];
					d++;
				}
				else
				{
					cap+=wid[i];
				}
			}
			
			if(!g||d>M) lo=mi+1;
			else hi=mi;
		}
		
		printf("%d\n", hi);
	}
}