
#include<iostream>
#include<vector>
using namespace std;
int main()
{
  int m,n;
  int low,high,medi;
  int column,breadth;
  int i;
  bool f;
  while(cin>>m>>n,m,n){
    vector<int>v(n);
    for(i=low=0;i<n;i++){cin>>v[i];low+=v[i];}
    low/=m;
    high=1500000;
    int j=0;
    while(j++<100){
      medi=(low+high)/2;
      breadth=column=f=0;
      for(i=0;i<n;i++){
	if(medi<v[i]){f=1;break;}
	if(breadth+v[i]<=medi){
	  breadth+=v[i];
	}else{
	  breadth=v[i];
	  column++;
	  if(column==m){f=1;break;}
	}
      }
      if(f)low=medi;
      else high=medi;
    }
    cout<<high<<endl;
  }
}