#include <bits/stdc++.h>
using namespace std;
int solve(string a, string b) {
  vector<char> v;
  for (int i = 0; i < b.size(); i++) v.push_back(b[i]);
  for (int i = 0; i < b.size(); i++) v.push_back(b[i]);
  int n = b.size();
  string s;
  int ans;
  for (int i = 0; i < b.size(); i++) {
    s = "";
    for (int j = i; j < i + n; j++) {
      s += v[j];
    }
    if (s == a) {
      ans = i;
      break;
    } else
      ans = 1e9;
  }
  return ans;
}
int main() {
  int n;
  cin >> n;
  string s;
  vector<string> v;
  for (int i = 1; i <= n; i++) {
    cin >> s;
    v.push_back(s);
  }
  int ans = 1e9, c, cnt = 0;
  for (int i = 0; i < n; i++) {
    cnt = 0;
    for (int j = 0; j < n; j++) {
      c = solve(v[i], v[j]);
      if (c == 1e9) {
        cout << -1;
        return 0;
      } else
        cnt += c;
    }
    ans = min(ans, cnt);
  }
  cout << ans;
}
