#include <bits/stdc++.h>
using namespace std;
char a[55][55];
int num[55][55];
int b[55];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    getchar();
    scanf("%s", a[i]);
  }
  int len = strlen(a[1]);
  bool pd = 0;
  for (int l = 1; l <= n; l++) {
    for (int i = 1; i <= n; i++) {
      if (l == i) continue;
      for (int j = 0; j < len; j++) {
        bool flag = 0;
        for (int k = 0; k < len; k++) {
          if (a[i][(k + j) % len] == a[l][k])
            continue;
          else {
            flag = 1;
            break;
          }
        }
        if (flag == 0) {
          num[l][i] = j;
          break;
        }
        if (flag == 1 && j == len - 1) {
          pd = 1;
          break;
        }
      }
      if (pd) break;
    }
  }
  if (pd) {
    printf("-1\n");
    return 0;
  }
  int ans = 0x3f3f3f3f;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      b[i] += num[i][j];
    }
  }
  for (int i = 1; i <= n; i++) {
    ans = min(ans, b[i]);
  }
  printf("%d\n", ans);
  return 0;
}
