#include <iostream>
#include <algorithm>
using namespace std;

bool comp(int i, int j){
	return i > j;
}

int main(){
	int n, m;
	while(cin >> m >> n){
		const int mmax = 30;
		int books[mmax];
		if(m == 0 && n == 0) break;
		for(int i = 0; i < n; i++){
			cin >> books[i];
		}
		while(n > m){
			sort(books, books+n, comp);
			books[n-2] += books[n-1];
			n--;
		}
		int size = -1;
		for(int i = 0; i < n; i++){
			size = max(size, books[i]);
		}
		cout << size << endl;
	}
	return 0;
}