#include <bits/stdc++.h>
using namespace std;
int main() {
  string text[55];
  int n, i, j, k, t, k1, sum, mn, mn_sum = 1e9;
  char c;
  bool no;
  cin >> n;
  for (i = 0; i < n; i++) cin >> text[i];
  t = text[0].size();
  for (i = 1; i <= t; i++) {
    c = text[0][0];
    for (k = 1; k < t; k++) text[0][k - 1] = text[0][k];
    text[0][t - 1] = c;
    sum = i % t;
    for (j = 1; j < n; j++) {
      no = 1;
      mn = t;
      for (k = 1; k <= t; k++) {
        c = text[j][0];
        for (k1 = 1; k1 < t; k1++) text[j][k1 - 1] = text[j][k1];
        text[j][t - 1] = c;
        if (text[j] == text[0]) {
          no = 0;
          mn = min(mn, k % t);
        }
      }
      if (no) break;
      sum += mn;
    }
    if (no) break;
    mn_sum = min(mn_sum, sum);
  }
  if (n == 1)
    cout << 0 << endl;
  else if (no)
    cout << -1 << endl;
  else
    cout << mn_sum << endl;
  return 0;
}
