#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)

int main(){
  int m,n;
  while(cin>>m>>n,m){
    vector<int> thick(n);
    REP(i,n)cin>>thick[i];
    int ans = 0;
    REP(i,n){
      ans += thick[i];
      int nowbook = i + 1;
      int shelf = m - 1;
      while(nowbook < n && shelf > 0){
        int width = 0;
        while(nowbook < n && width + thick[nowbook] <= ans) {
          width += thick[nowbook++];
        }
        shelf--;
      }
      if(nowbook == n){
        cout<<ans<<endl;
        goto END;
      }
    }
END:;
  }
  return 0;
}