#include <bits/stdc++.h>
using namespace std;
string str[55];
string s, tmp;
int main() {
  int n;
  while (scanf("%d", &n) != EOF) {
    for (int i = 0; i < n; i++) {
      cin >> str[i];
    }
    int sum;
    int ans = 1 << 30;
    int ok = 1;
    for (int i = 0; i < n; i++) {
      s = str[i];
      sum = 0;
      for (int j = 0; j < n; j++) {
        tmp = str[j];
        int cnt = 0;
        while (s != tmp) {
          tmp = tmp.substr(1) + tmp[0];
          sum++;
          cnt++;
          if (cnt > s.length()) {
            ok = 0;
            break;
          }
        }
      }
      ans = min(ans, sum);
    }
    if (ok)
      cout << ans << endl;
    else
      cout << -1 << endl;
  }
}
