#include<iostream>

int n,m;
int DP[100][20];
int book[100];

int solve(){
	for(int i=1; i<n; i++){
		for(int j=1; j<m; j++){
			if(DP[i-1][j-1] <= book[i])
				DP[i][j] = book[i];
			else{
				int tmp = book[i];
				DP[i][j] = DP[i-1][j-1];
				for(int k=1; k<i; k++){
					tmp += book[i-k];
					if(DP[i-k-1][j-1]<=tmp){
						if(tmp < DP[i][j])
							DP[i][j] = tmp;
						break;
					}else{
						if(DP[i-k-1][j-1] < DP[i][j])
							DP[i][j] = DP[i-k-1][j-1];
					}
				}
			}
		}
	}
	return DP[n-1][m-1];
}

int main(){
	while(true){
		std::cin >> m >> n;
		if(!m && !n)
			return 0;
		for(int i=0; i<n; i++){
			std::cin >> book[i];
			if(i>0){
				DP[i][0] = book[i];
				DP[i][0] += DP[i-1][0];
			}else{
				for(int k=0; k<m; k++)
					DP[i][k] = book[i];
			}
		}

		std::cout << solve() << std::endl;
	}
}