#include<iostream>
#include<vector>
using namespace std;
int main(){
  int n,m;
  while(cin >>n>>m,n||m){
    vector<int> book;
    int x,ans = 0;
    for(int i=0; i<m; i++){
      cin >>x;
      book.push_back(x);
      if(ans<x){ans = x;}
    }
    for(int i;;ans++){
      int last = ans,l = n;
      for(i=0; i<m; i++){
	if(last < book[i]){
	  last = ans;
	  l--;
	  if(l == 0){break;}
	  last-=book[i];
	}
	else{last-=book[i];}
      }
      if(i == m){cout <<ans<<endl;break;}
    }
  }
  return 0;
}