#include <bits/stdc++.h>
using namespace std;
const long long int inf = (long long int)1e18 + 19;
const long long int mod = (long long int)1e9 + 7;
void cazz() {
  long long int t = 1, i = 0, j, n;
  while (t--) {
    cin >> n;
    vector<string> s(n);
    for (long long int i = 0; i < n; i++) cin >> s[i];
    vector<string> dp[n];
    long long int ans = inf, f = 0, k;
    string st = s[0];
    for (long long int i = 0; i < n; i++) {
      for (long long int j = 0; j < s[0].length(); j++) {
        dp[i].push_back(s[i]);
        rotate(s[i].begin(), s[i].begin() + 1, s[i].end());
      }
    }
    for (long long int i = 0; i < dp[0].size(); i++) {
      long long int cnt = 0, cnt1 = 0;
      for (long long int j = 0; j < n; j++) {
        for (long long int k = 0; k < dp[0].size(); k++) {
          if (dp[0][i] == dp[j][k]) {
            cnt += k;
            cnt1 += 1;
            break;
          }
        }
      }
      if (cnt1 != n) {
        f = 1;
        break;
      }
      ans = min(ans, cnt);
    }
    if (f) {
      cout << -1 << "\n";
      continue;
    }
    cout << ans << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  cazz();
  return 0;
}
