#include <bits/stdc++.h>
using namespace std;
const int oo = 0x3f3f3f3f;
int main() {
  int n, sz;
  cin >> n;
  vector<string> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    sz = v[i].size();
    v[i] = v[i] + v[i];
  }
  int ans = oo;
  for (int i = 0; i < sz; i++) {
    string cur = v[0].substr(i, sz);
    int moves = i;
    for (int j = 1; j < n; j++) {
      size_t pos = v[j].find(cur);
      if (pos == string::npos) {
        moves = oo;
        break;
      }
      moves += pos;
    }
    ans = min(ans, moves);
  }
  if (ans == oo) ans = -1;
  cout << ans << '\n';
  return 0;
}
