#include<vector>
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i,j;
  int w[100],b[21],e[21],s[21],m,n,y,wmn,bmn;
  for(;;){
    cin>>m>>n;
    if(m+n==0)
      break;
    y=0;
    for(i=0;i<n;i++){
      cin>>w[i];
      y=max(y,w[i]);
    }
    i=0;
    j=0;
    s[i]=w[j];
    b[i]=j;
    e[i]=j;
    for(j++;j<n;j++){
      if(s[i]+w[j]<=y){
	s[i]+=w[j];
	e[i]=j;
      }else{
	i++;
	s[i]=w[j];
	b[i]=j;
	e[i]=j;
	if(i==m)
	  break;	
      }
    }
    if(j!=n){
      for(;;){
	wmn=y;
	for(i=0;i<m;i++){
	  if(s[i]+w[b[i+1]]-y<wmn){
	    wmn=s[i]+w[b[i+1]]-y;
	    bmn=i;
	  }
	}
	y+=wmn;
	i=bmn;
	j=e[bmn];
	for(j++;j<n;j++){
	  if(s[i]+w[j]<=y){
	    s[i]+=w[j];
	    e[i]=j;
	  }else{
	    i++;
	    s[i]=w[j];
	    b[i]=j;
	    e[i]=j;
	    if(i==m)
	      break;	  
	  }
	}
	if(j==n)
	  break;
      }
    }
    cout<<y<<endl;
  }
  return 0;
}    