#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <complex>
using namespace std;

#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define EPS 1e-8
#define DEB 0

int n,m;
int data[128];

int f(int mid){
	int cnt = 0;
	int sum = 0;
	rep(i,n){
		if( mid<data[i] ) return INT_MAX;
		sum += data[i];
		if( sum>mid ){
			cnt++;
			sum = data[i];
		}
	}
	return cnt+1;
}

int main(){
	while(scanf("%d%d",&m,&n),m|n){
		int sum = 0;
		rep(i,n){
			scanf("%d",data+i);
			sum += data[i];
		}
		int l = 0;
		int r = sum;
		while( l<r ){
			int mid = (l+r)/2;
			int k = f(mid);
#if DEB
			printf("mid:%d   k:%d\n",mid,k);
#endif			
			if( k<=m ){
				r = mid;
			}else{
				l = mid + 1;
			}
#if DEB
			printf("(l,r) = (%d,%d)\n",l,r);
#endif 			
		}
		printf("%d\n",r);
	}
	return 0;
}