#include <iostream>

bool fit(int m, int n, int* w, int width)
{
	int tray = 0;
	int sum_of_w = 0;
	int books;
	for (books=0; books<n; books++) {
		while (sum_of_w + w[books] > width && tray<m) { tray++; sum_of_w = 0; }
		if (tray == m) return false;
		sum_of_w += w[books];
	}
	return true;
}

int getWidth(int m, int n, int* w)
{
	int lb = w[0], ub = 1500000;
	while (lb < ub) {
		if (lb+1==ub) break;
		int mid = (lb + ub) / 2;
		if (fit(m, n, w, mid)) ub = mid;
		else lb = mid;
	}
	if (fit(m, n, w, lb)) return lb;
	else return ub;
}

int main()
{
	int m, n;
	while (true) {
		std::cin >> m >> n;
		if (m == 0) break;
		int* w = new int[n];
		for (int i=0; i<n; i++) std::cin >> w[i];
		std::cout << getWidth(m, n, w) << std::endl;
		delete[] w;
	}
	return 0;
}

