#include <bits/stdc++.h>
using namespace std;
map<string, pair<int, int> > idx;
map<string, pair<int, int> >::iterator iter;
void proc(string s) {
  idx[s].first++;
  int n = s.size() - 1;
  map<string, int> cur;
  cur[s]++;
  for (int i = 0; i < n; i++) {
    string t = s.substr(1, s.size() - 1);
    t += s[0];
    if (cur[t] == 0) {
      idx[t].first++;
      idx[t].second += i + 1;
      cur[t]++;
    }
    s = t;
  }
}
int main() {
  int n;
  cin >> n;
  int i;
  for (i = 0; i < n; i++) {
    string s;
    cin >> s;
    proc(s);
  }
  int ans = 1e9;
  bool exist = false;
  for (iter = idx.begin(); iter != idx.end(); iter++) {
    if (iter->second.first >= n) {
      ans = min(ans, iter->second.second);
      exist = true;
    }
  }
  if (exist) {
    cout << ans;
  } else {
    cout << -1;
  }
  return 0;
}
