String LD

No attempts yetTime limit1sMemory limit128 MB

Problem

Stringld (left delete) takes a string and removes its leftmost character. For example, Stringld("acm") returns "cm".

You are given a list of distinct words. In one step you apply Stringld once to every word in the list. Write a program that finds how many steps you can apply before at least one of the two conditions below becomes true.

  1. Some word becomes the empty string.
  2. Two or more words become identical.

For example, take the list aab, abac, caac. Applying the function once gives ab, bac, aac. Applying it again gives b, ac, ac, and because ac appears twice, condition 2 is true. The answer is 1. The step that made the condition true is not counted.

Input

The input holds several test cases. The first line of each test case has the number of words nn (1n1001 \le n \le 100). Each of the next nn lines has one word of at most 100 lowercase letters. Inside one test case all words are different. The input ends with a line holding a single 0.

Output

For each test case, print on one line the largest number of times Stringld can be called.