#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 77;
string s[55];
int n, m, k, ans = 9999999;
map<string, bool> all;
map<string, int> mp[55];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < (int)(n); ++i) cin >> s[i];
  m = (int)s[0].size();
  all[s[0]] = true;
  string t;
  for (int i = 0; i < (int)(m); ++i) {
    t = "";
    char c = s[0][i];
    for (int j = i + 1; j < m; j++) {
      t.push_back(s[0][j]);
    }
    for (int j = 0; j < i; j++) {
      t.push_back(s[0][j]);
    }
    t.push_back(c);
    all[t] = true;
  }
  for (int k = 0; k < (int)(n); ++k) {
    mp[k][s[k]] = 1;
    for (int i = 0; i < (int)(m - 1); ++i) {
      t = "";
      char c = s[k][i];
      for (int j = i + 1; j < m; j++) {
        t.push_back(s[k][j]);
      }
      for (int j = 0; j < i; j++) {
        t.push_back(s[k][j]);
      }
      t.push_back(c);
      if (!mp[k][t]) mp[k][t] = i + 2;
    }
    if (mp[k].size() != all.size()) {
      return cout << "-1" << endl, 0;
    }
    for (auto v : mp[k]) {
      if (!all[v.first]) return cout << "-1" << endl, 0;
    }
  }
  for (auto v : all) {
    int cur = 0;
    for (int k = 0; k < (int)(n); ++k) {
      cur += mp[k][v.first] - 1;
    }
    ans = min(ans, cur);
  }
  cout << ans << endl;
  return 0;
}
