#include<bits/stdc++.h>
using namespace std;
int m,n;
int book[101];
bool check(int width){
  int j=0;
  int sum=0;
  
  for(int i=0;i<n;i++){
    if(book[i] > width){
      return false;
    }
    
    sum += book[i];
    
    if(sum > width){
      j++;
      i--;
      sum = 0;
    }
    if(j == m){
      return false;
    }
  }
  return true;
}
int main(){
  while(1){
    cin>>m>>n;
    if(m == 0 && n == 0) break;
    
    for(int i=0;i<n;i++){
      cin>>book[i];
    }
    
    int left=0,right=1500000;
    while(right - left > 0) {
      int mid = (left + right) / 2;
      if(check(mid)) right = mid;
      else left = mid + 1;
    }
    
    cout<<right<<endl;
  }
}