#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
  int m,n,w[101],l,r,mid,cnt,dan;
  while(scanf("%d %d",&m,&n),m!=0||n!=0){
    l = 0;
    r = 0;
    for(int i=0;i<n;i++){
      scanf("%d",&w[i]);
      l = max(l,w[i]);
      r += w[i];
    }
    while(l < r){
      mid = (l+r-1)/2;
      cnt = 0;
      dan = 1;
      for(int i=0;i<n;i++){
	if(cnt+w[i] > mid){
	  cnt = 0;
	  dan++;
	}
	cnt += w[i];
      }
      
      if(dan > m) l = mid+1;
      else r = mid;
      
    }
    printf("%d\n",mid);
  }
  return(0);
}

