#include <bits/stdc++.h>
using namespace std;
const int INF = INT_MAX;
const long long INFL = LLONG_MAX;
const long double pi = acos(-1);
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
vector<string> v;
int ch(string t) {
  int ct = 0;
  for (int(i) = 0; (i) < (int((v).size())); (i)++) {
    string z = v[i];
    if (z == t) {
      continue;
    } else {
      int ct1 = 0, f = 0;
      string zz = v[i];
      for (int j = 1; j <= (int)int((v[i]).size()) - 1; j++) {
        string uff = "";
        int nnn = int((v[i]).size());
        uff = zz.substr(1, nnn - 1);
        uff += zz[0];
        ct1++;
        zz = uff;
        if (uff == t) {
          f = 1;
          ct += ct1;
          break;
        }
      }
      if (!f) return INF;
    }
  }
  return ct;
}
int main() {
  ios_base::sync_with_stdio(0);
  cout.precision(15);
  cout << fixed;
  cout.tie(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int(i) = 0; (i) < (n); (i)++) {
    string s;
    cin >> s;
    v.push_back(s);
  }
  int ans = INF;
  int nn = int((v[0]).size());
  string mo = v[0];
  for (int(i) = 0; (i) < (nn); (i)++) {
    if (i) {
      string ss = "";
      ss = mo.substr(1, nn - 1);
      ss += mo[0];
      mo = ss;
    }
    int p = ch(mo);
    if (p != INF) ans = min(ans, p);
  }
  if (ans != INF)
    cout << ans << '\n';
  else
    cout << -1 << '\n';
}
