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

