n = int(input())
s = [input().strip() for i in range(n)]
ss = [si+si for si in s] # save strings concatenated to themselves
best = 10**9
T = s[0] # initially target string is s[0]
for i in range(len(T)):
total_steps = 0
for S in ss:
steps = S.find(T) # finds occurence of T in S
if steps==-1: # not found, hence impossible
best = -1
break
total_steps += steps
if best==-1: # impossible
break
best = min(total_steps, best)
T = T[1:]+T[:1] # cyclic shift T to get next rotation
print(best)
biA9IGludChpbnB1dCgpKQpzID0gW2lucHV0KCkuc3RyaXAoKSBmb3IgaSBpbiByYW5nZShuKV0KCnNzID0gW3NpK3NpIGZvciBzaSBpbiBzXQkjIHNhdmUgc3RyaW5ncyBjb25jYXRlbmF0ZWQgdG8gdGhlbXNlbHZlcwpiZXN0ID0gMTAqKjkKVCA9IHNbMF0JIyBpbml0aWFsbHkgdGFyZ2V0IHN0cmluZyBpcyBzWzBdCmZvciBpIGluIHJhbmdlKGxlbihUKSk6Cgl0b3RhbF9zdGVwcyA9IDAKCWZvciBTIGluIHNzOgoJCXN0ZXBzID0gUy5maW5kKFQpCSMgZmluZHMgb2NjdXJlbmNlIG9mIFQgaW4gUwoJCWlmIHN0ZXBzPT0tMToJCSMgbm90IGZvdW5kLCBoZW5jZSBpbXBvc3NpYmxlCgkJCWJlc3QgPSAtMQoJCQlicmVhawoJCXRvdGFsX3N0ZXBzICs9IHN0ZXBzCglpZiBiZXN0PT0tMToJIyBpbXBvc3NpYmxlCgkJYnJlYWsKCWJlc3QgPSBtaW4odG90YWxfc3RlcHMsIGJlc3QpCglUID0gVFsxOl0rVFs6MV0JCSMgY3ljbGljIHNoaWZ0IFQgdG8gZ2V0IG5leHQgcm90YXRpb24KCnByaW50KGJlc3Qp