#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

const int INF=1e9;

signed main(){
   	int n,m;
   	while(1){
	   	cin>>n>>m;
	   	if(n+m==0) break;
	   	vi d(m);
	   	rep(i,0,m){
	   		cin>>d[i];
	   	}
	   	int MIN=INF;
		rep(i,1,m+1){
			int sum=0,cnt=1,tmp=INF;
			rep(j,0,i){
				sum+=d[j];
			}
			rep(j,i,m){
				if(tmp+d[j]<=sum){
					tmp+=d[j];
				}else{
					tmp=d[j];
					cnt++;
				}
			}
			//cout << i << " " << sum << " " << cnt << endl;
			if(cnt<=n){
				MIN=min(MIN,sum);
			}
		}	   
	    cout<<MIN<<endl;
	}
}