#include <bits/stdc++.h>
using namespace std;
int n;
string s[55], ss[55];
int mike(string str) {
  int x = str.size(), rslt = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < x; j++) {
      string sm = "";
      for (int k = j, m = 0; m < x; m++, k++) {
        if (k >= x) k = 0;
        sm += s[i][k];
      }
      if (sm == str) {
        rslt += j;
        if (i == n - 1) return rslt;
        break;
      }
      if (j == x - 1) return 100000000;
    }
  }
  return rslt;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> s[i];
  int x = s[0].size();
  for (int i = 0; i < x; i++) {
    for (int j = i, k = 0; k < x; k++, j++) {
      if (j >= x) j = 0;
      ss[i] += s[0][j];
    }
  }
  int rslt = mike(ss[0]);
  for (int i = 1; i < x; i++) {
    rslt = min(rslt, mike(ss[i]));
  }
  if (rslt == 100000000)
    puts("-1");
  else
    cout << rslt << endl;
}
