#include<iostream>
#include<vector>
#include<cstdio>

using namespace std;
vector<int> books;

int m, n;

bool judge(int obs)
{
	int sum = 0;
	int cont = 1;
	for(int i = 0; i < books.size(); i++)
	{
		if(books[i] > obs) return false;
		if(sum + books[i] > obs)
		{
			cont++;
			sum = 0;
		}
		sum += books[i];
	}
	return ( (m >= cont)? true : false );
}

int main()
{
	int c;
	while(cin >> m >> n)
	{
		if(m ==0 && n == 0) break;
		for(int i = 0; i < n; i++)
		{
			cin >> c;
			books.push_back(c);
		}
		
		int ub = 1500000, lb = 0;

		while(ub - lb > 1)
		{
			int mid = (ub + lb) / 2;
			if(judge(mid)){
				ub = mid;
			}
			else{
				lb = mid;
			}
		}
		cout << ub << endl;
		books.clear();
	}
}