/* Problem 3--Alphabetic Exclusion
   This is a good example of dynamic programming.  As we visit each word
   in sequence, we attach it to the longest list we can. */

import java.io.*;
import java.util.*;

public class prob3 {

 public static Scanner in=null;
 public static PrintWriter out=null;

 public static void main (String[] args) throws Exception {

  in = new Scanner (new File ("prob3.in"));
  out = new PrintWriter ("prob3.out");
  int cs=1;
  int sz=0;
  while ((sz=in.nextInt())>0) {
   String[] A = new String[sz];
   for (int i=0; i < sz; i++) A[i] = in.next();
   int[] ct = new int[sz];
   for (int i=0; i < sz; i++) ct[i] = 1; //each word is on its own list
   for (int i=1; i < sz; i++)            //of size 1
    for (int j=0; j < i; j++) //We try to attach to each previous word
     if (A[i].compareTo(A[j]) >= 0) ct[i] = Math.max (ct[i],ct[j]+1);
   int max = ct[0]; // keeping track of the largest list.
   for (int i=1; i < sz; i++) max = Math.max (max,ct[i]);
   out.println ("Case "+(cs++)+": You only need to remove "+(sz-max)+
                " word(s)!"); // finally obtaining the longest list
  }
  in.close();
  out.close();
 }
}
