#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e9;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
int main(){
	int n,m;
	while(cin>>n>>m,n||m){
		vi in(m);
		rep(i,m)cin>>in[i];
		int r=1,l=15000001;
		while(l-r>1){
			int h=(r+l)/2;
			int c=1;
			int sum=0;
			rep(i,m){
				if(sum==0&&in[i]>h){
					c=1e9;
					break;
				}else if(sum+in[i]>h){
					c++;sum=0;
					i--;
				}else{
					sum+=in[i];
				}
			}
			if(c<=n)l=h;
			else r=h;
		}
		cout<<l<<endl;
	}
}