#define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <iterator>
 
using namespace std;
 
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
 
#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)c.size())

typedef unsigned long long ull;
const int INF = (int)1e8;

int C(vector<int>& v,int md){
	int len = 0;
	int ret = 1;
	FOR(i,sz(v)){
		if(md < v[i]) return INF;
		if(len + v[i] <= md) len += v[i];
		else {ret++; len = v[i];}
	}

	return ret;
}

int main(){
	int n,m;
	while(cin>>n>>m,n||m){
		vector<int> v(m); FOR(i,m) cin>>v[i];
		int l = 1, r = INF;
		while(r-l!=1){
			int md = (r+l)/2;
			if(C(v,md) <= n) r = md;
			else l = md;
		}
		cout << r << endl;
	}
	return 0;
}