#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
 
using namespace std;
 
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define rep(i,n) REP(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<double, int> pdi;
typedef pair<ll, ll> pll;
 

 
const int INF = 1000000;
const double EPS = 1e-8;
const int mod = 1e9 + 7;
const ll LINF = 1e18;
const double PI = acos(-1);

struct Input
{
	int n;
	char c;
	char str[1024];
	string s;
	ll l;
	int nextInt(){
		scanf("%d", &n);
		return n;
	}
	ll nextLong(){
		scanf("%lld", &l);
		return l;
	}
	char nextChar(){
		scanf("%c", &c);
		return c;
	}
	string next(){
		scanf("%s", str);
		return string(str);
	}
	string nextLine(){
		getline(cin, s);
		return s;
	}
};
Input in;

vi v;
int n, m;

bool check(int mid){
	int w = 0, h = 0;
	for(int i = 0; i < v.size(); i++){
		if(v[i] > mid) return false;
		if(w + v[i] > mid){
			h++;
			w = v[i];
		}
		else{
			w += v[i];
		}
	}
	return h < m;
}

int main(){
	while(1){
		m = in.nextInt(); n = in.nextInt();
		if(m == 0 && n == 0) break;
		v.resize(n);
		rep(i, n) v[i] = in.nextInt();
		int l = 0, r = 1e9;
		rep(i, 100){
			int mid = (l + r) / 2;
			if(check(mid)){
				r = mid;
			}
			else{
				l = mid;
			}
		}
		printf("%d\n", r);
	}
}