#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

int m,n;
vector<int>v;

bool C(int x){

  int cnt=0,sum=0;
  for(int i=0;i<n;i++){
    if(sum+v[i]>x)cnt++,sum=v[i];
    else sum+=v[i];
  }
  return m>=cnt+1;
}

int main(void){

  while(cin >> m >> n,m|n){
    v.clear();
    m=min(m,n);
    int l=0,r=0,a;
    for(int i=0;i<n;i++){
      cin >> a;
      r+=a;
      v.push_back(a);
    }
    
    int mid=(l+r)/2+1;
    while(r-l>1){
      if(C(mid))r=mid;
      else l=mid;
      mid=(l+r)/2;
    }
    cout << r << endl;
  }

  return 0;
}