Amin is employed at KAIST’s network security laboratory, focusing on researching the security of the university’s network. The network has n strings, denoted as s1,s2,...,sn, each composed of lowercase English letters.
Amin can perform a single move by selecting a string si, removing its first character, and appending it to the end. For example, transforming “iddacup” to “ddacupi” 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.
The first line contains integer n (1≤n≤50) — the number of strings.
This is followed by n lines each containing a string. The i-th of these lines corresponds to the string si. Lengths of strings are equal. The length of each string is positive and doesn’t exceed 50.
Print the security level of the network — the minimum number of moves Amin needs in order to make all the strings equal or −1 if it is not possible.
In this task, points are awarded for each correct test. The maximum score is 100.