#include<cstdio>
#include<vector>
#include<algorithm>
#include<functional>
using namespace std;
int main()
{
	int a[100],N,M,i,j,k,s,h;
	while(scanf("%d%d",&M,&N),N)
	{
		vector<int>v;
		for(i=0;i<N;++i)scanf("%d",&a[i]);
		for(i=0;i<N;++i)
			for(j=0;j+i<N;v.push_back(s),++j)
				for(s=k=0;k<=i;++k)
					s+=a[j+k];
		sort(v.begin(),v.end(),greater<int>());
		v.erase(unique(v.begin(),v.end()),v.end());
		s=*max_element(a,a+N);
		for(i=v.size()-1;;--i)if(v[i]>=s)break;
		v.erase(v.begin()+i+1,v.end());
		for(i=v.size()-1;;--i)
		{
			for(h=s=j=0;j<N;++j)
			{
				if(s+a[j]>v[i])
				{
					s=a[j];++h;
					if(h>=M)goto E;
				}
				else s+=a[j];
			}
			printf("%d\n",v[i]);
			goto N;
E:;
		}
N:;
	}
	return 0;
}