#include <bits/stdc++.h>
using namespace std;
int n;
vector<string> v;
string move(string str) {
  char tmp = str[0];
  str.erase(str.begin());
  str += tmp;
  return str;
}
int f(string str, string s) {
  for (int i = 0; i < str.size(); ++i) {
    if (str == s) return i;
    str = move(str);
    if (str == s) return i + 1;
  }
  return -1;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    string str;
    cin >> str;
    v.push_back(str);
  }
  int sol = 10000000;
  string ss = "A";
  for (int i = 0; i <= v[0].size(); ++i) {
    int res = i;
    for (int j = 1; j < v.size(); ++j) {
      int tmp = f(v[j], v[0]);
      if (tmp == -1) {
        res = -1;
        break;
      }
      res += tmp;
    }
    if (res != -1) {
      ss = v[0];
      sol = min(sol, res);
    }
    v[0] = move(v[0]);
  }
  if (sol != 10000000)
    cout << sol;
  else
    cout << -1;
  return 0;
}
