#include <iostream>
#include <vector>
#include <algorithm>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

vector<int> v;

bool Check(int x,int n,int m)
{
	int i = 0,j = 0,l = 0;

	while(i < m && j < n)
	{
		if(l + v[i] <= x)
		{
			l += v[i];
			i++;
		}
		else
		{
			l = 0;
			j++;
		}
	}

	if(i == m && j < n) return true;
	else return false;
}

int main()
{
	int n,m;
	while(cin >> n >> m)
	{
		if(n == 0 && m == 0) break;
		
		v.clear();

		rep(i,m)
		{
			int temp;
			cin >> temp;
			v.push_back(temp);
		}

		int l = 0,r = 1500000;

		rep(i,1000)
		{
			int mid = (l + r) / 2;
			if(Check(mid,n,m)) 
			{
				r = mid;
			}
			else 
			{
				l = mid;
			}
		}	

		cout << r << endl;
	}
	return 0;
}