#include <bits/stdc++.h>

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
ll const inf = 1LL<<55;

ll dp[1010];
ll sumw[1010];

int main() {

  int N; ll W;
  int tc = 1;
  for(; cin >> N >> W && (N || W); tc++) {

//    watch(N)   watch(W)

    rep(i, 1001) dp[i] = inf;
    dp[0] = 0;

    sumw[0] = 0;
    rep(i, N) {
      int P; cin >> P;
      sumw[i + 1] = sumw[i] + P;
    }

    sumw[N + 1] = inf;

//    rep(i, N + 2) {     cout << sumw[i] << " ";   }cout << endl;

    ll ans = inf;

    if(N == 0) {
      ans = 0;
    }
    else if(N == 1) {
      ans = max(0LL, sumw[1] - W);
    }
    else {
      rep(i, N) {
        int nextidx = upper_bound(sumw, sumw + N, sumw[i] + W) - sumw - 1;
  //      watch(i); watch(nextidx); watch(sumw[nextidx]);
        if(nextidx == N) {
          dp[nextidx] = dp[i] + max(0LL, sumw[nextidx] - sumw[i] - W);
        }
        else {
          dp[nextidx] = min(dp[nextidx], dp[i] + abs(sumw[nextidx] - sumw[i] - W));
          int nextidx2 = nextidx + 1;
          if(nextidx2 == N) {
            dp[nextidx2] = min(dp[nextidx2], dp[i] + max(0LL, sumw[nextidx2] - sumw[i] - W));
          }
          else {
            dp[nextidx2] = min(dp[nextidx2], dp[i] + abs(sumw[nextidx2] - sumw[i] - W));
          }
        }
      }
      ans = dp[N];
    }
    cout << "Case " << tc << ": " << ans << endl;
  }

  return 0;
}