#include <bits/stdc++.h>
using namespace std;
int ara[50];
int main() {
  int n;
  bool oka = true;
  cin >> n;
  string str[n];
  for (int i = 0; i < n; i++) {
    cin >> str[i];
  }
  int len = str[0].size();
  for (int i = 0; i < n; i++) {
    int c = 0;
    for (int j = 0; j < n; j++) {
      int hmt = 0;
      if (str[i] != str[j]) {
        string a = str[i];
        string b = str[j];
        while (hmt <= len + 3 && a != b) {
          hmt++;
          char ch = b[0];
          for (int k = 0; k < len - 1; k++) {
            b[k] = b[k + 1];
          }
          b[len - 1] = ch;
        }
        if (a != b) {
          oka = false;
          cout << (-1) << endl;
          return 0;
        }
      }
      c += hmt;
    }
    ara[i] = c;
  }
  int mini = INT_MAX;
  for (int i = 0; i < n; i++) {
    mini = min(mini, ara[i]);
  }
  cout << mini << endl;
  return 0;
}
