Amin’s Research
Amin is employed at KAIST’s network security laboratory, focusing on researching the security of the university’s network. The network has strings, denoted as , each composed of lowercase English letters.
Amin can perform a single move by selecting a string , removing its first character, and appending it to the end. For example, transforming “” to “” in one move.
The security level of the network is determined by the minimum number of moves required to make all strings identical.
Amin possesses the necessary data. Your task is to assist him by writing a program to compute the security level of the network.
Input
The first line contains integer — the number of strings.
This is followed by lines each containing a string. The -th of these lines corresponds to the string . Lengths of strings are equal. The length of each string is positive and doesn’t exceed .
Output
Print the security level of the network — the minimum number of moves Amin needs in order to make all the strings equal or if it is not possible.
Examples
Scoring
In this task, points are awarded for each correct test. The maximum score is .