#include <iostream>
#include <fstream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define INF 1e8
#define EPS 1e-9

#define rep2(i,m,n) for(int i=m;i<n;i++)
#define rep(i,n) rep2(i,0,n)
#define ll long long
#define P pair<int,int>
#define pb push_back

int m,n,b[100];

int main(){
	while(cin>>m>>n&&m){
		rep(i,n)cin>>b[i];
		int l=0,u=15000000;
		while(l<u-1){
			int M=(l+u)/2,x=0,y=0,cur=0;
			for(;;){
				if(x+b[cur]<=M)x+=b[cur++];
				else{y++;x=0;}
				if(cur==n||y==m)break;
			}
			if(cur==n)u=M;
			else l=M;
		}
		cout<<u<<endl;
	}
}