#include <iostream>
#include <cmath>

using namespace std;

int n, m;
int data[100];
int mid, l, r;

bool check(){
   int w = 0;
   for(int i=0;i<m;i++){
      int sum = 0;
      for(;w<n;w++){
         if(sum + data[w] > mid) break;
         sum += data[w];
      }
      if(w>=n) break;
   }
   if(w >= n) return true;
   return false;
}

main(){
   while(cin >> m >> n && (n || m)){
      for(int i=0;i<n;i++){
         cin >> data[i];
      }
      l = 0;
      r = 1500000;
      while(abs(r-l) > 1){
         mid = (l+r)/2;
         if(check()){
            r = mid;
         }else{
            l = mid;
         }
      }
      cout << r << endl;
   }
   return 0;
}