#include<iostream>
using namespace std;

int m,n;
int a[100];

bool check(int x){
  int b[20];
  int i,j=0;
  for(i=0;i<m;i++)b[i] = x;
  for(i=0;i<n;i++){
    if(b[j]>=a[i])b[j] -= a[i];
    else {
      j++;
      i--;
      if(j==m)break;
    }
  }
  if(i==n)return true;
  return false;
}

int main(){
  int l,r,mid;

  while(1){
    cin >> m >> n;
    if(!m && !n)break;

    for(int i=0;i<n;i++)cin >> a[i];

    l = 0;r = 1500000;

    while(l+1<r){
      mid = (l+r)/2;
      if(check(mid))r = mid;
      else l = mid;
    }

    cout << r << endl;
  }
}