#include <bits/stdc++.h>
using namespace std;
vector<int> cnt[55];
int main() {
  int n;
  cin >> n;
  string a;
  cin >> a;
  int f = 0;
  for (int i = 0; i < n - 1; ++i) {
    string b;
    cin >> b;
    for (int j = 0; j < b.length(); ++j) {
      if (a == b.substr(j, b.length()) + b.substr(0, j)) {
        cnt[i].push_back(j);
      }
    }
  }
  for (int i = 0; i < n - 1; ++i)
    if (cnt[i].empty()) {
      puts("-1");
      return 0;
    }
  int ans = 1e9;
  for (int i = 0; i < a.length(); ++i) {
    int t = (a.length() - i) % a.length();
    for (int j = 0; j < n - 1; ++j) {
      int tt = 1e9;
      for (int k = 0; k < cnt[j].size(); ++k) {
        if (cnt[j][k] >= i)
          tt = min(tt, cnt[j][k] - i);
        else
          tt = min(tt, ((int)a.length() - (i - cnt[j][k])));
      }
      t += tt;
    }
    ans = min(t, ans);
  }
  cout << ans;
}
