// Nadeem Mohsin
// Problem B - Containers
// 2007 World Finals

import java.util.*;
import java.io.*;

public class containers
{
    public static void main(String[] args) throws Exception
    {
        new containers();
    }

    public containers() throws Exception
    {
        Scanner sc = new Scanner(System.in);
        for(int k = 1; ; k++)
        {
            String s = sc.next();
            if(s.equals("end")) break;

            int N = s.length();
            int[] nums = new int[N+1];
            s += (char)('Z' + 1);

            // This problem basically asks for the minimum partition of a partially
            // ordered set into chains. By Dilworth's theorem, this is equal
            // to the length of the maximal antichain, which amounts to finding
            // the longest increasing subsequence.
            // There is a simple greedy algorithm as well - see the C++ solution
            // for that.
            int[] best = new int[N+1];
            for(int i = 0; i <= N; i++)
            {
                best[i] = 1;
                for(int j = 0; j < i; j++)
                    if(s.charAt(i) > s.charAt(j))
                        best[i] = Math.max(best[i], best[j]+1);
            }

            System.out.printf("Case %d: %d\n", k, best[N]-1);
        }
    }
}

