Amin's Research#11681

Amin's Research

1 second
128 megabytes
Medium

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 s_1, s_2, ..., s_n, each composed of lowercase English letters.

Amin can perform a single move by selecting a string s_i, 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 n~(1 \le n \le 50) — the number of strings.

This is followed by lines each containing a string. The -th of these lines corresponds to the string s_i. 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

Example 1

Loading
Loading

Example 2

Loading
Loading

Example 3

Loading
Loading

Scoring

In this task, points are awarded for each correct test. The maximum score is .