#include <bits/stdc++.h>
using namespace std;
const int inf = 1 << 30;
char str[55][55];
void caozuo(char a[55]) {
  char c = a[0];
  int len = strlen(a);
  for (int i = 0; i < len - 1; i++) {
    a[i] = a[i + 1];
  }
  a[len - 1] = c;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s", str[i]);
  }
  int ma = inf;
  int len = strlen(str[0]);
  for (int i = 0; i < n; i++) {
    int sum = 0;
    for (int j = 0; j < n; j++) {
      if (i == j) continue;
      int k = 0;
      char b[55];
      strcpy(b, str[j]);
      while (strcmp(str[i], b) != 0) {
        caozuo(b);
        k++;
        if (k > len) {
          printf("-1\n");
          return 0;
        }
        sum++;
      }
    }
    ma = min(ma, sum);
  }
  printf("%d\n", ma);
  return 0;
}
