#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int test_case;
  test_case = 1;
  while (test_case--) {
    long long int n;
    cin >> n;
    string s[n];
    for (long long int i = 0; i < n; i++) {
      cin >> s[i];
    }
    long long int mi = INT_MAX, k = s[1].size();
    for (long long int i = 0; i < n; i++) {
      long long int sum = 0;
      string q = s[i];
      for (long long int i = 0; i < n; i++) {
        string f = s[i];
        long long int h = 0;
        while (q != f && h < k) {
          char ui = f[0];
          f.erase(0, 1);
          f.push_back(ui);
          h++;
          sum++;
        }
        if (h == k) {
          cout << -1 << endl;
          return 0;
        }
      }
      mi = min(mi, sum);
    }
    cout << mi << endl;
  }
  return 0;
}
