#include<iostream>
using namespace std;
int n, m;

bool isIn(int w, int* width){
  int sum = 0, step = 1;
  for (int i = 0; i < n; i++) {
    if(sum + width[i] > w){
      sum = 0;
      step++;
    }
    sum += width[i];
  }
  if(step > m)
    return false;
  return true;
}

int bs(int* width){
  int begin =  0, end = 1500000;
  for (int i = 0; i < n; i++) {
    if(begin < width[i])
      begin = width[i];
  }
  int mid = (begin + end) / 2;
  while(begin < mid){
    if(isIn(mid, width)){
      end = mid;
    }else{
      begin = mid;
    }
    mid = (begin + end) / 2;
  }
  if(isIn(mid, width)){
    return mid;
  }else{
    return mid + 1;
  }
}


int main(int argc, char *argv[]){
  while(cin >> m >> n, n){
    int width[n];
    for (int i = 0; i < n; i++) {
      cin >> width[i];
    }
    std::cout << bs(width) << std::endl;
  }
  return 0;
}