//b
#include <iostream>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <memory>
#include <functional>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>

#define REP(i,b,n) for(int i=b;i<n;i++)
#define REPR(i,b,n) for(int i=n-1;i>=b;i--)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define NCLR(mat) memset(mat, -1, sizeof(mat))
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define EACH(i, c) for(typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define BIT(n, b) ((n>>b) & 1)
#define PB push_back
#define MP make_pair

using namespace std;

static const double PI = acos(-1.0);
static const double EPS = 1e-9;
typedef long long ll;
typedef pair<int, int> pii;	

int m, n;
int book[10000];

bool chk(int width){
	
	int sum = 0, height = 0;
	
	for(int i=0; i<n; ++i){
		
		if(book[i] > width){
			return false;	//明らかに入らない本が出てきたら広げなくてはいけない
		}
		
		sum += book[i];		//本を詰める
		
		if(sum > width){
			sum = book[i];	//入らなくなったら下の段に移動
			height++;		//段の数を増やす
		}
	}
	
	return height < m;
}	

int main(){
	
	while(cin>>m>>n, (m||n)){
		
		for(int i=0; i<n; ++i){
			cin>>book[i];
		}
		
		int upper = INT_MAX/2, lower = 0, middle;
		
		while(upper - lower > 1){
			
			middle = (upper+lower)/2;
			
			if( chk(middle) ){ 
				upper = middle;
			}
			else{
				lower = middle;
			}
		}
		
		cout << upper << endl;
	}
	
	return 0;	
}