#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
using ll = long long;
using lld = long double;
const int oo = 0x3f3f3f3f;
const ll MOD = 1000000007;
const int N = 100;
string ar[N];
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> ar[i];
  int ans = oo;
  for (int i = 0; i < n; i++) {
    int moves = 0;
    for (int j = 0; j < n; j++) {
      string tmp = ar[j];
      bool found = 0;
      for (int k = 0; k < tmp.size(); k++) {
        if (tmp == ar[i]) {
          moves += k;
          found = 1;
          break;
        }
        std::rotate(tmp.begin(), tmp.begin() + 1, tmp.end());
      }
      if (!found) {
        cout << "-1\n";
        return 0;
      }
    }
    ans = min(ans, moves);
  }
  cout << ans << '\n';
  return 0;
}
