#include <bits/stdc++.h>
using namespace std;
long long l1;
long long num(string s, string t) {
  long long cnt = 0;
  while (s != t) {
    t.push_back(t[0]);
    t.erase(t.begin());
    cnt++;
    if (cnt > l1) {
      return -1;
    }
  }
  return cnt;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  t = 1;
  while (t--) {
    long long n;
    cin >> n;
    string s1;
    cin >> s1;
    l1 = s1.length();
    set<char> st1;
    map<char, long long> m1;
    for (long long i = 0; i < l1; i++) {
      m1[s1[i]]++;
      st1.insert(s1[i]);
    }
    long long ndc = st1.size();
    vector<string> a(n);
    a[0] = s1;
    long long flag = 0;
    for (long long i = 0; i < n - 1; i++) {
      string s;
      cin >> s;
      a[i + 1] = s;
      map<char, long long> m;
      long long l = s.length();
      if (l != l1) {
        cout << "-1";
        break;
      }
      for (long long i = 0; i < l; i++) {
        m[s[i]]++;
      }
      long long f = 0;
      for (auto it = st1.begin(); it != st1.end(); it++) {
        if (m1[*it] != m[*it]) {
          f = 1;
          break;
        }
      }
      if (f) {
        flag = 1;
        cout << "-1";
        break;
      }
    }
    if (flag) break;
    long long ans = LLONG_MAX;
    long long v[n][n];
    long long flag2 = 0;
    for (long long i = 0; i < n; i++) {
      long long c = 0;
      for (long long j = 0; j < n; j++) {
        v[i][j] = num(a[i], a[j]);
        if (v[i][j] == -1) {
          flag2 = 1;
          break;
        }
        c += v[i][j];
      }
      if (flag2) {
        ans = -1;
        break;
      }
      ans = min(ans, c);
    }
    cout << ans;
  }
  cerr << endl
       << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC
       << "ms\n";
  return 0;
}
