#include <bits/stdc++.h>
using namespace std;
const int MaxN = 1e5;
const int Inf = 1 << 30;
vector<string> num;
int main() {
  int n;
  string s;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> s;
    num.push_back(s);
  }
  string p, t;
  int res, flag = 1;
  int ans = Inf;
  for (int i = 0; i < n; i++) {
    p = num[i];
    res = 0;
    for (int j = 0; j < n; j++) {
      if (j == i) continue;
      t = num[j];
      t += t;
      int k = t.find(p);
      if (k == -1) {
        flag = 0;
        break;
      } else {
        res += k;
      }
    }
    if (!flag) break;
    ans = min(ans, res);
  }
  if (!flag)
    cout << -1 << endl;
  else
    cout << ans << endl;
  return 0;
}
