#include<iostream>
using namespace std;

int m,n;
int books[110];
int solves();
int search(int a);

int main(){
	while(1){
		cin >> m >> n;
		if(m == 0 && n == 0) break;
		for(int i=0;i<n;i++){
			cin >> books[i];
		}
		int ans = solves();
		cout << ans << endl;
	}
}

int solves(){
	int ub = 0,lb = 2000000, mid;
	for(int i=0;i<1000;i++){
		mid = (ub + lb) / 2;
		if(search(mid)) lb = mid;
		else ub = mid;
		cout << ub << " " << lb << endl;
	}
	return lb;
}

int search(int a){
	int len = a;
	int cou = 0;
	for(int i=0;i<n;i++){
		while(1){
			if(0 > len-books[i]){
				cou++;
				len = a;
			}
			else break;
			if(cou == m) return 0;
		}
		len -= books[i];
	}
	return 1;
}