#include <bits/stdc++.h>
using namespace std;
int check(string a, string b) {
  int cn = 0;
  if (a == b) return cn;
  int l = b.length() - 1;
  for (int i = 0; i < b.length(); i++) {
    char x = b[0];
    for (int j = 1; j < b.length(); j++) {
      b[j - 1] = b[j];
    }
    b[l] = x;
    cn++;
    if (a == b) return cn;
  }
  return 99999;
}
int main() {
  char s[100][100];
  string ss, tt;
  int a, b, c, d, e, f, j, k, l, m, n, o;
  while (cin >> n) {
    int hi = 99999;
    for (int i = 0; i < n; i++) cin >> s[i];
    ss = s[0];
    l = ss.length() - 1;
    for (int i = 0; i < ss.length(); i++) {
      int cn = 0;
      char x = ss[0];
      for (int j = 1; j < ss.length(); j++) {
        ss[j - 1] = ss[j];
      }
      ss[l] = x;
      for (int i = 0; i < n; i++) {
        cn = cn + check(ss, s[i]);
      }
      hi = min(hi, cn);
    }
    if (hi >= 99999)
      cout << "-1" << endl;
    else
      cout << hi << endl;
  }
  return 0;
}
