#include <bits/stdc++.h>
using namespace std;
int INF = std::numeric_limits<int>().max();
double INFD = std::numeric_limits<double>().max();
double PI = acos(-1);
int Cost(string a, string b) {
  int i = 0;
  while (a != b && i <= b.size()) {
    a = a.substr(1) + a[0];
    i++;
  }
  if (i > b.size()) {
    return -1;
  }
  return i;
}
int main() {
  ios::sync_with_stdio(false);
  int n = 0;
  cin >> n;
  vector<string> strs(n);
  for (auto& s : strs) {
    cin >> s;
  }
  int i = 0, opt = INF;
  string target = strs[0];
  while (i < strs[0].size()) {
    int j = 0, cost = 0;
    while (j < n) {
      int c = Cost(strs[j], target);
      if (c == -1) {
        cout << -1 << endl;
        return 0;
      }
      cost += c;
      j++;
    }
    opt = min(opt, cost);
    i++;
    target = target.substr(1) + target[0];
  }
  cout << opt << endl;
  return 0;
}
