#include <stdio.h>
#include <iostream>
#include <queue>
#include <algorithm>
using namespace std;

int main(void)
{
	int M,N;

	while(cin >> M >> N, M){
		priority_queue<long, vector<long>, greater<long> > pq;

		for(int i = 0; i < M; i++)
			pq.push(0);		//本棚初期

		long book;
		while(N > 0){
			cin >> book;

			int pqt = pq.top();	pq.pop();

			pqt += book;
			pq.push(pqt);
			N--;
		}
		while(pq.size()-1 > 0)
			pq.pop();

		cout << pq.top() << endl;
		pq.pop();
	}

	return 0;
}
			