#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<climits>
using namespace std;



int m;
vector<int> cost;
void init(){
  cost.clear();
}

bool input(){
  int n;
  cin>>m>>n;
  if(n==0&&m==0)return 0;
  for(int i=0;i<n;i++){
    int tmp;
    cin>>tmp;
    cost.push_back(tmp);
  }
  return 1;
}


bool judge(long long w){
  long long tmp_w=0;
  long long tmp_m=1;
  for(int i=0;i<cost.size();i++){
    if(tmp_w+cost[i]>w){
      tmp_w=0;
      tmp_m++;
      i--;
      if(tmp_m>m){
        return false;
      }
    }else{
      tmp_w+=cost[i];
    }
  }
  return true;
}

int binary_serch(long long t_min,long long t_max){
  if(t_min>=t_max)return t_max;
  long long c=(t_min+t_max)/2;
  if(judge(c)){
    return binary_serch(t_min,c);
  }else{
    return binary_serch(c+1,t_max);
  }
}

int solve(){
  return binary_serch(0,1500000); 
}


int main(){
  while(init(),input()){
    cout<<solve()<<endl;
  }
}