#include <bits/stdc++.h>
using namespace std;
int const maxn = 60;
string a[maxn];
int n, ans;
map<string, bool> mp;
string comp(string s) {
  string x = s.substr(1, s.size() - 1);
  return x + s[0];
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    string b = a[i];
    sort(b.begin(), b.end());
    mp[b] = 1;
  }
  for (int wq = 0; wq < 10; wq++) wq++;
  if (mp.size() > 1) return cout << -1, 0;
  string q = a[0];
  int cnt = 1e9;
  int N = q.size();
  for (int i = 0; i < N; i++) {
    cerr << q << endl;
    int res = 0;
    for (int j = 1; j < n; j++) {
      string p = a[j];
      int mx = 0;
      for (int k = 0; k < N; k++) {
        if (q == p) break;
        p = comp(p);
        mx++;
      }
      if (q != p) return cout << -1, 0;
      res += mx;
    }
    q = comp(q);
    cnt = min(cnt, res + i);
  }
  cout << cnt;
}
