import scala.annotation.tailrec
import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer
import scala.io.StdIn._
object Main extends App {
  loop()
  @tailrec def loop(count: Int = 1): Unit = {
    val Array(n, w) = readLine.trim.split(' ').map(_.toInt)
    if (n == 0 && w == 0) return
    val memo = Array.fill(n){-1}
    val words = Array.tabulate(n){_ ⇒ readLine.trim.toInt}
    println(s"Case $count: ${solve(words, 0)(memo, w)}")
    loop(count + 1)
  }
  def solve(words: Array[Int], current: Int)(implicit memo: Array[Int], width: Int): Int = {
    if (current == words.length) 0
    else if (memo(current) >= 0) memo(current)
    else {
      var length = 0
      memo(current) = Int.MaxValue
      for (i ← current until words.length) {
        length += words(i)
        val temp = if (i != words.length - 1) solve(words, i + 1) + math.abs(width - length) else math.max(0, length - width)
        if (memo(current) > temp) memo(current) = temp
      }
      memo(current)
    }
  }
}
