#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0 ; i < n ; i++ )
#define INF ( 1 << 30 )
int book[100],dp[20][100],m,n;
int solve(int index,int dan,int maxsize,int nowsize){
  if(index == n) return maxsize;
  if(dp[dan][index] < maxsize) return dp[dan][index];
  int res = INF;
  res = min( res, solve( index+1, dan, max(maxsize, nowsize + book[index]),nowsize+book[index]));
  if(dan+1 != m)
    res = min( res, solve( index+1, dan+1, max(maxsize,nowsize + book[index]), 0));
  return dp[dan][index] = res;
}
int main(){
  while(cin >> m >> n , m){
    fill_n(dp[0],20*100,INF);
    rep(i,n) cin >> book[i];
    cout << solve(0,0,0,0) << endl;
  }
}