#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

bool valid(const vector<int> b, int m, int w) {
  int sum = 0;
  for (int book : b) {
    if (book > w) return false;
    if (sum + book > w) {
      sum = 0;
      --m;
    }
    sum += book;
  }
  return m > 0;
}

int main() {
  while(1){
    int m,n;
    cin>>m>>n;
    if(!m) break;
    vector<int> b(n);
    REP(i,n) cin>>b[i];
    int i = 1 << 27;
    int j = 0;
    while(i > 0) {
      if(!valid(b,m,i+j)) {
        j += i;
      }
      i/=2;
    }
    cout << (j+1) << endl;
  }
  return 0;
}