#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, j, sz, c, Count, Min = 99999999;
  cin >> n;
  getchar();
  string s[n], a, b;
  for (i = 0; i < n; i++) {
    cin >> s[i];
  }
  sz = s[0].size();
  for (i = 0; i < n; i++) {
    Count = 0;
    for (j = 0; j < n; j++) {
      a = s[j];
      if (i == j) continue;
      c = 0;
      while (a != s[i] && c <= sz) {
        a += a[0];
        a.erase(a.begin());
        c++;
        Count++;
      }
      if (c > sz) {
        cout << -1 << endl;
        return 0;
      }
    }
    Min = min(Min, Count);
  }
  cout << Min << endl;
  return 0;
}
