// AOJ 0181
#include <iostream>

const int kMaxWidth = 1500000;
const int kMaxBooks = 100;

int thickness[kMaxBooks];
int m, n;

bool canPlace(int width) {
	int k = 0;
	int filled = 0;
	for (int i = 0; i < n; i++) {
		if (thickness[i] > width) return false;
		if (filled + thickness[i] > width) {
			if (++k >= m) return false;
			filled = 0;
		}
		filled += thickness[i];
	}
	return true;
}

int solve() {
	int left = 0, right = kMaxWidth;
	while (right - left > 1) {
		int mid = (left + right) / 2;
		if (canPlace(mid)) right = mid;
		else left = mid;
	}
	return right;
}

int main() {
	while (1) {
		std::cin >> m >> n;
		if (m == 0) break;
		for (int i = 0; i < n; i++)
			std::cin >> thickness[i];
		std::cout << solve() << std::endl;
	}
	return 0;
}