#include<iostream>
#include<cstdlib>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
#define fir first
#define sec second

typedef long long ll;
const ll inf = (1LL)<<50;
const int N = 1001;

ll dp[N];
ll cost[N][N];

void pre(int n,ll *in){
  rep(i,n){
    cost[i][i]=in[i];
    REP(j,i+1,n){
      cost[i][j]=cost[i][j-1]+in[j];
    }
  }
}

ll solve(int n,ll w){
  rep(i,n+1)dp[i]=inf;
  dp[0]=0;
  REP(i,1,n+1){
    rep(j,i){
      if(i==n){
	dp[i]=min(dp[i],dp[j]+max(0LL,cost[j][i-1]-w));
      }else dp[i]=min(dp[i],dp[j]+llabs(w-cost[j][i-1]));
    }
  }
  return dp[n];
}

int main(){
  int n;ll w;
  int tc=1;
  ll in[N];
  while(cin>>n>>w && n){
    rep(i,n)cin>>in[i];
    pre(n,in);
    printf("Case %d: %lld\n",tc++,solve(n,w));
  }
}