#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
bool C(vector<int>& v, int w, int m){
  int index = 0;
  for(int i = 0; i < m && index < v.size(); i++){
    int count = 0;
    while(index < v.size() && count + v[index] <= w){
      count += v[index++];
    }
  }
  if(index == v.size()) return true;
  else return false;
}

int main(){
  int m,n;
  while(cin>>m>>n,m){
    vector<int> thick(n);
    REP(i,n)cin>>thick[i];
    int up = 15000000;
    int lw = 1;
    while(up - lw > 0){
      int mid = (up + lw) /2;
      if(C(thick,mid,m)){
        up = mid;
      }else{
        lw = mid + 1;
      }
    }
    cout<<up<<endl;
  }
  return 0;
}