#include <bits/stdc++.h>   using namespace std;   const int MAXN = 3e5 + 7;   const int inf = 1e9;   char s[60][60];   char s1[60];   int l;   int n;   int num[60];   int check(char *s) {     for (int i = 0; i < l; ++i) {       int j;       for (j = 0; j < l; ++j) {         if (s1[j] != s[(j + i) % l]) break;       }       if (j >= l) return i;     }     return -1;   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) scanf( %s , s[i]);     l = strlen(s[0]);     int ans = inf;     for (int i = 0; i < l; ++i) {       int sum = 0;       for (int j = 0; j < l; ++j) s1[j] = s[0][(j + i) % l];       for (int j = 0; j < n; ++j) {         int t = check(s[j]);         if (t == -1) {           puts( -1 );           return 0;         }         sum += t;       }       ans = min(ans, sum);     }     printf( %d n , ans);     return 0;   }   