#include <bits/stdc++.h>
using namespace std;
const int N = 55;
char a[1][N];
void move1(int n) {
  char s = a[0][0];
  for (int i = 1; i < n; i++) {
    a[0][i - 1] = a[0][i];
  }
  a[0][n - 1] = s;
  a[0][n] = '\0';
}
int main() {
  char s[N][N];
  int n;
  scanf("%d", &n);
  getchar();
  for (int i = 0; i < n; i++) {
    gets(s[i]);
  }
  int ans = 0x3f3f3f3f;
  int flag = 0;
  {
    for (int i = 0; i < n; i++) {
      int cnt = 0;
      for (int j = 0; j < n; j++) {
        strcpy(a[0], s[j]);
        int k = 0;
        while (strcmp(s[i], a[0]) != 0) {
          move1(strlen(s[i]));
          cnt++;
          k++;
          if (k > strlen(s[i])) {
            i = n;
            flag = 1;
            break;
          }
        }
      }
      ans = min(ans, cnt);
    }
  }
  if (flag)
    cout << -1 << endl;
  else
    cout << ans << endl;
  return 0;
}
