#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF INT_MAX/3
#define ALL(a) (a).begin(),(a).end()
#define CLR(a) memset(a,0,sizeof(a))

typedef long long int ll;

using namespace std;

int main(){
    while(true){
	int w,n;
	cin >> w >> n;
	vector<int> b(n);
	vector<int> temp(n);
	if(w == 0 && n == 0) break;
	REP(i,n) cin >> b[i];
	temp = b;
	sort(ALL(temp));
	int l,m,h;
	int s,count;
	h = 1500000;
	l = 0;
	m = (h+l)/2;
	while(h-l>1){
	    s = 0;
	    count = 0;
	    if(temp.back() > m){
		l = m;
		m = (h+l)/2;
		continue;
	    }
	    REP(i,n){
		if((s+b[i]) > m){
		    s = 0;
		    count++;
		}
		s += b[i];
	    }

	    if(count < w){
		h = m;
	    }else{
		l = m;
	    }
	    m = (h+l)/2;
	}
	cout << h << endl;
    }
    return 0;
}