#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T getNext() {
  T s = 1, x = 0, c = getc(stdin);
  while (c <= 32) c = getc(stdin);
  if (c == '-') s = -1, c = getc(stdin);
  while ('0' <= c && c <= '9') x = x * 10 + c - '0', c = getc(stdin);
  return x * s;
}
const double eps = 1e-9;
const int MAXN = (int)(2e6) + 256;
const long long INFLL = 1e15;
const long long INF = 1e9;
const int MOD = (int)(1e9) + 7;
inline bool pal(string s) {
  string t = s;
  reverse(t.begin(), t.end());
  return s == t;
}
int n;
string s[100];
inline int check(string t) {
  int res = 0;
  for (int i = 0; i < n; ++i) {
    string e = s[i] + s[i];
    size_t pos = e.find(t);
    if (pos == string ::npos) return INT_MAX;
    res += pos;
  }
  return res;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> s[i];
  }
  int res = INT_MAX;
  for (int i = 0; i < n; ++i) {
    res = min(res, check(s[i]));
  }
  if (res == INT_MAX) res = -1;
  cout << res;
  return 0;
}
