#include <bits/stdc++.h>
using namespace std;
char s[55][55];
int a[55];
void work(int k, int t, int len) {
  for (int i = 0; i <= len - 1; ++i) {
    int flag = 1;
    for (int j = 0; j <= len - 1; ++j) {
      if (s[k][j] != s[t][(i + j) % (len)]) {
        flag = 0;
        break;
      }
    }
    if (flag) {
      a[t] = i;
      return;
    }
  }
  a[t] = -1;
  return;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%s", s[i]);
  int len = strlen(s[1]);
  int ans = 1e9;
  for (int k = 1; k <= n; ++k) {
    a[k] = 0;
    for (int i = 1; i <= n; ++i) {
      if (i == k) continue;
      work(k, i, len);
      if (a[i] == -1) {
        printf("-1");
        return 0;
      }
    }
    int tmp = 0;
    for (int i = 0; i <= len - 1; ++i) {
      tmp = 0;
      for (int j = 1; j <= n; ++j) {
        if (a[j] >= i)
          tmp += a[j] - i;
        else
          tmp += len + a[j] - i;
      }
      if (tmp < ans) ans = tmp;
    }
  }
  printf("%d", ans);
  return 0;
}
