#include <bits/stdc++.h>
using namespace std;
int n;
int f(char[], char[]);
int main() {
  cin >> n;
  char s[50][50 + 1];
  int num[50];
  for (int i = 0; i < n; i++) scanf("%s", s[i]);
  num[0] = 0;
  for (int i = 1; i < n; i++) {
    num[i] = f(s[0], s[i]);
    if (num[i] == -1) {
      cout << "-1" << endl;
      return 0;
    }
  }
  int ans = INT_MAX;
  for (int i = 0; i < n; i++) {
    int k = 0;
    for (int j = 0; j < n; j++) k += f(s[i], s[j]);
    if (k < ans) ans = k;
  }
  cout << ans << endl;
  return 0;
}
int f(char ori[], char fin[]) {
  int len = (int)strlen(ori);
  for (int i = 0; i < len; i++) {
    bool same = true;
    for (int j = 0; j < len; j++)
      if (ori[j] != fin[(i + j) % len]) {
        same = false;
        break;
      }
    if (same) return i;
  }
  return -1;
}
