#include <bits/stdc++.h>
using namespace std;
long long a, b, z, ans(100000), sum;
string s[55], t, w, g;
bool f;
vector<long long> v;
int main() {
  cin >> a >> t;
  b = t.length();
  s[0] = t;
  for (int i = 1; i < b + 1; i++) {
    w = s[i - 1].substr(1, b - 1);
    s[i] = w + s[i - 1][0];
    if (s[i] == t) {
      z = i;
      break;
    }
  }
  v.push_back(0);
  for (int i = 1; i < a; i++) {
    f = false;
    cin >> g;
    for (int j = 0; j < z; j++) {
      if (s[j] == g) {
        f = true;
        v.push_back(j);
        break;
      }
    }
    if (f == false) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 0; i < v.size(); i++) {
    sum = 0;
    for (int j = 0; j < i; j++) {
      if (v[j] > v[i]) {
        sum += z - v[j] + v[i];
      } else {
        sum += v[i] - v[j];
      }
    }
    for (int j = i + 1; j < v.size(); j++) {
      if (v[j] > v[i]) {
        sum += z - v[j] + v[i];
      } else {
        sum += v[i] - v[j];
      }
    }
    ans = min(ans, sum);
  }
  cout << ans << endl;
}
