#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int MAXN = 100;
string s[MAXN];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> s[i];
  int m = s[0].length();
  int ans = INF;
  for (int k = 0; k < m; k++) {
    int t = 0;
    for (int i = 0; i < n; i++) {
      bool good = false;
      for (int j = 0; j < m; j++) {
        bool ok = true;
        for (int g = 0; g < m; g++) {
          ok &= (s[0][(k + g) % m] == s[i][(j + g) % m]);
        }
        if (ok) {
          good = true;
          t += j;
          break;
        }
      }
      if (!good) {
        cout << -1 << endl;
        return 0;
      }
    }
    ans = min(ans, t);
  }
  cout << ans << endl;
  return 0;
}
