#include<iostream>
#include<cstdio>
using namespace std;

int m, n;
int a[110];

int chk(int w){
  int ind = 0;
  for(int i=0; i<m; i++){
    int t = 0;
    for(;;){
      if(ind==n) break;
      if(t+a[ind]>w) break;
      
      t += a[ind];
      ind++;
    }
  }
  if(ind==n) return 1;
  else return 0;
  
}

int main(){
  for(;;){
    cin >> m >> n;
    if(m==0 && n==0) break;
    
    for(int i=0; i<n; i++) cin >> a[i];
    
    int il = 0, ir = 1500001;
    while(ir-il>1){
      int mid = (il+ir)/2;
      if(chk(mid)){
        ir = mid;
      }else{
        il = mid;
      }
    }
    cout << il+1 << endl;
  }
  return 0;
}