#include<bits/stdc++.h>
using namespace std;

#define reps(i,f,n) for(int i=f;i<int(n);i++)
#define rep(i,n) reps(i,0,n)

int n,m;
vector<int> book;

void init(){
  book.clear();
}

bool input(){
  cin>>m>>n;
  if(n==0)return false;
  rep(i,n){
    int a;
    cin>>a;
    book.push_back(a);
  }
  return true;
}

bool ok(int h){
  int len = 0;
  int sum = 0;
  rep(i,book.size()){
    if(len+book[i]<=h)len += book[i];
    else{
      len = 0;
      sum++;
      i--;
    }

    if(sum>=m)return false;
  }
  return true;
}

int solve(){
  int left = 0;
  int right = 1500000;

  while(1){
    int h = (left+right)/2;
    //printf("%d %d %d\n",left,h,right);
    if(ok(h)){
      right = h;
    }else{
      left = h;
    }
    if(left+1>=right)break;
  }

  return right;
}

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