#include <vector>
#include <list>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <deque>
#include <cstdio>
#include <cmath>
#include <complex>
#include <iostream>
#include <iterator>

using namespace std;

#define reps(i,f,t) for(int i=f ; i<int(t) ; ++i)
#define rep(i,n) reps(i, 0, n) 

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

bool C(int m, int n, int book[], int w)
{
	int dan = 1;
	int now = 0;
	rep(i, n){
		if(now+book[i] <= w)
			now += book[i];
		else if(book[i] <= w){
			now = book[i];
			++dan;
		}
		else
			return false;
	}
	return dan <= m;	
}

int main()
{
	int m, n;
	while(scanf("%d", &m), m){
		scanf("%d", &n);
		
		int book[100];
		rep(i, n)
			scanf("%d", &book[i]);
		
		int left = 0, right = 1500000;
		while(right-left>1){
			int mid = (left + right)/2;
			if(C(m, n, book, mid))
				right = mid;
			else
				left = mid;
		}
		printf("%d\n", right);
	}
	return 0;
}