import java.io.*; import java.util.*; public class TextJustification { private static final Scanner cin = new Scanner(System.in); public static void main(String[] args) { for(int iCase = 1; ; iCase++) { int n = cin.nextInt(); int w = cin.nextInt(); if(n == 0 && w == 0) { break; } int[] a = new int[n+1]; int[] c = new int[n+1]; c[0] = 0; for(int i = 1; i <= n; i++) { a[i] = cin.nextInt(); c[i] = Integer.MAX_VALUE; int k = a[i]; for(int j = i - 1; j >= 0; j--) { if(i == n) { c[i] = Math.min(c[i], c[j] + Math.max(0, k - w)); } else { c[i] = Math.min(c[i], c[j] + Math.abs(k - w)); } k += a[j]; } } System.out.println("Case " + iCase + ": " + c[n]); } } }