cho.sh
Notes
Loading...

Distinguishing Files

Time limit

2s

Memory limit

128 MB

Problem

There are N files stored in memory. In this problem, each file is treated as a sequence of natural numbers. To check whether two files are different, one could read them to the end, but here we want to distinguish files by reading only the first K numbers from the front.

If a file is shorter than K, compare it as if enough zeros were appended to its end to make its length K. In other words, each file is compared by the length-K sequence formed from its first K values.

Find the minimum value of K such that the length-K prefix sequences of all files are pairwise different.

Input

The first line contains the number of files N (1 ≤ N ≤ 100).

Each of the next N lines contains the natural numbers that represent one file, in order, and ends with -1. No two files have both the same length and the same contents. Each number in a file is a natural number not greater than 2^31 - 1.

Output

Print the minimum K that makes it possible to distinguish every file.