#include <iostream>
#include <vector>

using namespace std;

int calc_m (vector <int> w, int curr_w )
{
	int n = w.size();
	int cm = 0;
	int j = 0;
	while (j < n ){
		int cw = 0;
		while (cw + w[j] <= curr_w && j < n ){
			cw += w[j];
			j++;
		} // end while
		cm++;
	} // end if

	return cm;
}

int main()
{
	const int MaxW = 1500000;
	int m, n;	// {IÌi 1  m  20, {Ìª 1  n  100

	while (cin >> m >> n && m && n ){
		vector <int> w (n, 0 );	// {Ì 1  w[i]  1000000
		int res = 0;				// {IÌ ans  1500000
		for (int i = 0; i < n; i++ ){
			cin >> w[i];
		} // end for
		int l = w[0];
		int r = MaxW;
		int mid = 0;
		while (l <= r ){
			mid = (l+r)/2;
			int curr_m = calc_m (w, mid );
			if (curr_m > m ){
				l = mid+1;
			}else{
				r = mid-1;		
			} // end if
		} // end while
		cout << mid << endl;
	} // end loop
		
	return 0;
}