#include <bits/stdc++.h>
using namespace std;
string str[300];
int n, m, x, y, z;
string tmp1[300];
int ans = 10000000;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> str[i];
  }
  int len = str[1].size();
  for (int i = 1; i <= n; i++) {
    string tmp = str[i];
    for (int j = 0; j < len; j++) {
      tmp1[j].clear();
      tmp1[j].resize(len);
      int l = 0;
      int k;
      for (k = j, l = 0; k < len; k++, l++) {
        tmp1[j][l] = str[i][k];
      }
      for (k = 0; l < len; k++, l++) {
        tmp1[j][l] = str[i][k];
      }
    }
    int ppp = 0;
    bool arektaflg = 0;
    for (int j = 1; j <= n; j++) {
      bool flg = 0;
      if (str[j] == tmp1[0]) continue;
      for (int k = len - 1; k >= 0; k--) {
        if (str[j] == tmp1[k]) {
          if (k != 0) k = len - k;
          ppp += k;
          flg = 1;
          break;
        }
      }
      if (flg == 0) {
        arektaflg = 1;
        break;
      }
    }
    ans = min(ans, ppp);
    if (arektaflg) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << ans << endl;
  return 0;
}
