#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  while(1){
    int n,m;
    cin >> m >> n;
    if(n==0 && m==0){
      return 0;
    }
    int w[110],i;
    for(i=0;i<n;i++){
      cin >> w[i];
    }
    int min=0,max=1500001;
    while(abs(min-max)>1){
      int sum=0,sum1=0,mid=(min+max)/2;
      for(i=0;i<n;i++){
        if(w[i]>mid){
          sum1=100;
          break;
        }
        else if(sum+w[i]<=mid){
          sum+=w[i];
        }
        else{
          sum=w[i],sum1++;
        }
      }
      sum1++;
      if(sum1<=m){
        max=mid;
      }
      else{
        min=mid;
      }
    }
    cout << max << endl;
  }
}
