#include <bits/stdc++.h>
using namespace std;
char a[55][55];
int ans[55];
char save[55][55];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%s", a[i]);
  int len = strlen(a[1]);
  strcpy(save[0], a[1]);
  for (int i = 1; i < len; ++i) {
    strcpy(save[i], save[i - 1] + 1);
    save[i][len - 1] = save[i - 1][0];
    save[i][len] = '\0';
  }
  int Ans = 99999;
  for (int h = 0; h < len; h++) {
    ans[1] = h;
    for (int k = 2; k <= n; k++) {
      bool flag;
      int i;
      for (i = 0; i < len; i++) {
        flag = true;
        for (int j = 0; j < len; j++) {
          if (save[h][j] != a[k][(j + i + len) % len]) {
            flag = false;
            break;
          }
        }
        if (flag) {
          ans[k] = i;
          break;
        }
      }
      if (i == len && flag == false) {
        printf("-1\n");
        return 0;
      }
    }
    for (int i = 0; i <= len - 1; i++) {
      int num = 0;
      for (int j = 1; j <= n; j++) {
        ans[j] = (ans[j] + 1) % len;
        num += ans[j];
      }
      if (Ans > num) Ans = num;
    }
  }
  printf("%d\n", Ans);
  return 0;
}
