Code
题号:NC237538
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 512 M,其他语言1024 M
64bit IO Format: %lld

题目描述

Lucy is studying coding algorithm , but she doesn't study well .

According to what she learned, she constructed a coding table for the character set with length n .

For example , , she constructed the coding table like this : .

Then , she used the table to compress data .

For example : .

But in some cases, her code will be ambiguous . Such as 01 can decoding as both ``ab'' or ``c'' .

Her physical education teacher found this problem and told her , but she didn't think so .

Now please help her physical education teacher find the minimum length of 01 string , which has at least two decoding methods .

输入描述:

The first line contains one integer  , indicates the size of character set .

Then n lines , the i-th line contains a 01 string s_i, represents the code of the i-th character .

The sum of will not exceed 5000 , for every pair , .

输出描述:

If the answer exists , print the answer , otherwise print -1 instead .

示例1

输入

复制
3
0
1
01

输出

复制
2
示例2

输入

复制
4
00
01
11
10

输出

复制
-1