#include<iostream>
using namespace std;
int main(){
  int m,n;
  while(cin >> m >> n){
    if(m==0&&n==0) break;
    int index[n];
    int max = 1500000;
    int min = 0;
    for(int i=0;i<n;i++){
      cin >>  index[i];
      min = index[i] > min ? index[i] : min;
    }
    int tyuou = 0;
    while(min!=max){
      tyuou = (max + min) / 2;
      int sum = 0;
      int count = 1;
      for(int i=0;i<n;i++){
        if(sum+index[i]>tyuou){
          count++;
          sum = index[i];
        } else {
          sum += index[i];
        }
      }
      if(count>m){
        min = tyuou + 1;
      } else {
        max = tyuou;
      }
    }
    cout << max << endl;
  }
}

