#include <iostream>
#include <vector>

using namespace std;

void solve()
{
	int m, n;
	while(cin >> m >> n)
	{
		if(!m && !n)
		{
			break;
		}
		vector<int> Vec(n);
		for(int i = 0; i < n; ++i)
		{
			cin >> Vec[i];
		}
		int pre_width = 0;
		int width = 1500000;
		for(int a = 0; a < 50; ++a)
		{
			int pos = 0;
			for(int i = 0; i < m; ++i)
			{
				int buf = width;
				while(buf > Vec[pos])
				{
					buf -= Vec[pos];
					pos++;
					if(pos == n)
					{
						int pre_width_buf = width;
						width -= abs(width - pre_width) / 2;
						pre_width = pre_width_buf;
						goto NEXT;
					}
				}
			}
			if(pos < n)
			{
				int pre_width_buf = width;
				width += abs(width - pre_width) / 2;
				pre_width = pre_width_buf;
			}
NEXT:
			;
		}
		cout << width << endl;
	}
}

int main()
{
	solve();
	return(0);
}