Mike has *n* strings *s*<sub class="lower-index">1</sub>, *s*<sub class="lower-index">2</sub>, ..., *s*<sub class="lower-index">*n*</sub> each consisting of lowercase English letters. In one move he can choose a string *s*<sub class="lower-index">*i*</sub>, erase the first character and append it to the end of the string. For example, if he has the string "coolmike", in one move he can transform it into the string "oolmikec".

Now Mike asks himself: what is minimal number of moves that he needs to do in order to make all the strings equal?
The first line contains integer *n* (1 ≤ *n* ≤ 50) — the number of strings.

This is followed by *n* lines which contain a string each. The *i*-th line corresponding to string *s*<sub class="lower-index">*i*</sub>. Lengths of strings are equal. Lengths of each string is positive and don't exceed 50.
In the first sample testcase the optimal scenario is to perform operations in such a way as to transform all strings into "zwoxz".
4
xzzwo
zwoxz
zzwox
xzzwo
5
2
molzv
lzvmo
2
3
kc
kc
kc
0
3
aa
aa
ab
-1
3
kwkb
kbkw
bkwk
3
1
a
0
2
njtazaab
abnjtaza
2
38
kmlzdcnm
mlzdcnmk
lzdcnmkm
kmlzdcnm
lzdcnmkm
zdcnmkml
zdcnmkml
mlzdcnmk
zdcnmkml
mlzdcnmk
lzdcnmkm
zdcnmkml
kmlzdcnm
lzdcnmkm
zdcnmkml
mlzdcnmk
kmlzdcnm
mkmlzdcn
lzdcnmkm
nmkmlzdc
zdcnmkml
nmkmlzdc
kmlzdcnm
mlzdcnmk
mkmlzdcn
dcnmkmlz
cnmkmlzd
cnmkmlzd
mkmlzdcn
cnmkmlzd
dcnmkmlz
kmlzdcnm
nmkmlzdc
nmkmlzdc
kmlzdcnm
kmlzdcnm
lzdcnmkm
zdcnmkml
104
4
xwppaubrphxjwmwfwypvwwjzotyobpiynyka
ubrphxjwmwfwypvwwjzotyobpiynykaxwppa
wjzotyobpiynykaxwppaubrphxjwmwfwypvw
tyobpiynykaxwppaubrphxjwmwfwypvwwjzo
41
15
gnizfqwqmimtgmtf
mtgmtfgnizfqwqmi
gmtfgnizfqwqmimt
zfqwqmimtgmtfgni
zfqwqmimtgmtfgni
fqwqmimtgmtfgniz
imtgmtfgnizfqwqm
fgnizfqwqmimtgmt
gmtfgnizfqwqmimt
mtgmtfgnizfqwqmi
qwqmimtgmtfgnizf
izfqwqmimtgmtfgn
mtfgnizfqwqmimtg
tgmtfgnizfqwqmim
mtfgnizfqwqmimtg
89
33
nkgcmrfvxe
vxenkgcmrf
rfvxenkgcm
vxenkgcmrf
xenkgcmrfv
enkgcmrfvx
enkgcmrfvx
nkgcmrfvxe
kgcmrfvxen
cmrfvxenkg
cmrfvxenkg
xenkgcmrfv
rfvxenkgcm
rfvxenkgcm
nkgcmrfvxe
xenkgcmrfv
rfvxenkgcm
xenkgcmrfv
xenkgcmrfv
gcmrfvxenk
mrfvxenkgc
fvxenkgcmr
vxenkgcmrf
enkgcmrfvx
cmrfvxenkg
cmrfvxenkg
mrfvxenkgc
kgcmrfvxen
vxenkgcmrf
enkgcmrfvx
cmrfvxenkg
cmrfvxenkg
gcmrfvxenk
135
11
xdngtxuqjalamqvotuhx
otuhxxdngtxuqjalamqv
gtxuqjalamqvotuhxxdn
dngtxuqjalamqvotuhxx
votuhxxdngtxuqjalamq
xxdngtxuqjalamqvotuh
alamqvotuhxxdngtxuqj
uqjalamqvotuhxxdngtx
qjalamqvotuhxxdngtxu
hxxdngtxuqjalamqvotu
jalamqvotuhxxdngtxuq
79
2
oiadfnwpdcxxhbwwqbrcdujcusgtkqdjmintwjlb
brcdujcusgtkqdjmintwjlboiadfnwpdcxxhbwwq
17
20
cynedh
nedhcy
hcyned
cynedh
ynedhc
ynedhc
nedhcy
nedhcy
nedhcy
hcyned
nedhcy
hcyned
nedhcy
dhcyne
ynedhc
edhcyn
dhcyne
ynedhc
cynedh
cynedh
34
9
rgycrkgcjktfdjkffcnlnhiawq
awqrgycrkgcjktfdjkffcnlnhi
rkgcjktfdjkffcnlnhiawqrgyc
jktfdjkffcnlnhiawqrgycrkgc
cjktfdjkffcnlnhiawqrgycrkg
fdjkffcnlnhiawqrgycrkgcjkt
ffcnlnhiawqrgycrkgcjktfdjk
ktfdjkffcnlnhiawqrgycrkgcj
wqrgycrkgcjktfdjkffcnlnhia
76
2
dzlisvouhbqogzusikmkuvkql
qogzusikmkuvkqldzlisvouhb
10
2
sfotivvfgbdfcnvaybxhstavaoktatflelpyi
sfotivvfgbdfcnvaybxhstavaoktatflelpyi
0
1
umwnrjtcytnquvdmqfiqt
0
4
zumixjfqhbkeg
kegzumixjfqhb
hbkegzumixjfq
gzumixjfqhbke
9
12
ktwwduoopsnkhfklrskdxakbmqhl
lktwwduoopsnkhfklrskdxakbmqh
duoopsnkhfklrskdxakbmqhlktww
klrskdxakbmqhlktwwduoopsnkhf
oopsnkhfklrskdxakbmqhlktwwdu
opsnkhfklrskdxakbmqhlktwwduo
kbmqhlktwwduoopsnkhfklrskdxa
lrskdxakbmqhlktwwduoopsnkhfk
wduoopsnkhfklrskdxakbmqhlktw
klrskdxakbmqhlktwwduoopsnkhf
hfklrskdxakbmqhlktwwduoopsnk
dxakbmqhlktwwduoopsnkhfklrsk
121
12
aaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaa
0
15
kknrrejishjz
hilbaftsfcaq
lncsgtjqgwjz
athvctulbhmb
nfvsjyiulmmr
hxjnvumwnwtr
rncsxqvkvqeg
qoabapuhodxk
ylinhbhyqjsn
cnzxgdgytgav
xufmacyangpv
hwvzionkdmjl
spklymjxiolk
qjkfrccaayak
onwrbgfvxrjx
-1
2
adam
mdaa
-1
2
aabc
acab
-1
2
abc
cba
-1
5
aaaa
aaaa
aaaa
aaaa
aaaa
0
2
a
b
-1
2
abab
aabb
-1
2
bac
abc
-1
2
aabb
abab
-1
3
aa
aa
aa
0
2
abc
acb
-1
3
aaaa
aaaa
aaaa
0
2
aa
aa
0
2
ab
aa
-1
2
xyxy
xxyy
-1
2
abc
bac
-1
2
aaabb
baaba
-1
2
abcde
dcabe
-1
2
abcd
bdca
-1
5
aaaaa
aabaa
aaaaa
aaaaa
aaaaa
-1
3
aab
abb
bab
-1
2
nzxv
zvnx
-1
10
ab
bc
cd
de
ef
gh
hi
ij
ik
mn
-1
3
aaa
aaa
aaa
0
2
ac
bb
-1
2
abcd
bdac
-1
2
abcabc
cabcab
1
7
aaa
aab
aba
abb
baa
bab
bba
-1
4
aa
aa
bb
bb
-1
2
abcd
cabd
-1
4
abcabcabc
bcabcabca
cabcabcab
cabcabcab
3
3
abcabc
bcabca
bcabca
1
2
abbc
abcc
-1
2
aaabb
ababa
-1
3
aabbbaba
abaabbab
bbbaaaba
-1
2
aabaab
baabaa
1
def troca(palavra):
    primeira_letra = palavra[0]
    palavra = palavra + primeira_letra
    palavra = palavra[1:]
    return palavra

def main():
    n = int(input(''))
    nomes = list()

    for i in range(0,n):
        nome = input('')
        nomes.append(nome)
    
    flag_iguais = True
    
    # verificar se sao iguais
    nomes_ordenados = nomes.copy()
    for i in range(0,n):
        nomes_ordenados[i] = sorted(nomes_ordenados[i])
    for i in range(0,n):
        for j in range(0,n):
            '''verifica se tem um diferente'''
            if nomes_ordenados[i] != nomes_ordenados[j]:
                print(-1)
                return
            
            '''verifica se eh tudo igual'''
            if nomes[i] != nomes[j]:
                flag_iguais = False
    
    if flag_iguais:
        print(0)
        return
    
    palavra_inicial = nomes[0]
    capicoins = int(0)

    i = 0
    while(1):
        if len(nomes) == 0:
            break
        
        for i in range(0,int(len(nomes))):
            if palavra_inicial == nomes[i]:
                nomes.remove(palavra_inicial)
                break
        
        capicoins += 1
        palavra_inicial = troca(palavra_inicial)

    
    print(capicoins-1)

if __name__ == '__main__':
    main()
	 	 	 				  		    		  	 		    	