#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;

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

const int MAX = 1500000;

int m, n;
vector<int> book;

bool check(int v){
  int width = 0, pos = 0;
  rep(i, n){
    if(book[i] > v) return false;
    if(width + book[i] <= v) width += book[i];
    else width = 0, pos++, i--;
  }
  return pos < m;
}
    
int main(){
  while(cin >> m >> n, m|n){
    book.resize(n);
    rep(i, n) cin >> book[i];
    
    int L = 0, R = MAX;
    int M;
    while(L+1 != R){
      M = (L+R) / 2;
      if(check(M)) R = M;
      else L = M;    
    }
    cout << R << endl;
  }
  return 0;
}