#include<iostream>
#include<vector>

#define UP_LIMIT 1
#define DOWN_LIMIT 2

using namespace std;

int solve(int limit, const vector<int> &book){
  int ret;
  int pre_w = -1;
  int l = 0;
  int r = 4000000;

  ret = r;
  while(true){
    int st = -1;
    int w = (r+l)/2;
    int maxsw = 0;
    int sw = 0;
    int stair = 0;

    if( w == pre_w )break;

    for(int i = 0; i < book.size(); ++i){
      maxsw = max( maxsw, sw );
      if( sw + book[i] <= w ){
	sw += book[i];
      }else if( stair < limit ){
	sw = book[i];
	stair++;
      }else{
	st = UP_LIMIT;
      }
    }
    maxsw = max( maxsw, sw );

    //cout << "R,L : " << r << ' ' << l << "STAIR : " << stair << " MAXSW : " << maxsw << endl;

    if( st == UP_LIMIT || stair >= limit ){
      l = w;
    }else if( st == -1 ){
      ret = min( ret, maxsw );
      r = w;
    }
    
    pre_w = w;
  }
  return ret;
}

int main(){
  while(true){
    int m,n;
    vector<int> books;

    cin >> m >> n;
    if(m==0&&n==0)break;
    for(int i = 0; i < n; ++i){
      int t;
      cin >> t;
      books.push_back(t);
    }

    cout << solve( m, books ) << endl;

  }
  return 0;
}