#include <bits/stdc++.h>
using namespace std;
void err(istream_iterator<string> it) { cout << endl; }
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << ' ';
  err(++it, args...);
}
int dx[8] = {1, 0, -1, 0, -1, -1, 1, 1};
int dy[8] = {0, 1, 0, -1, -1, 1, -1, 1};
int ini() {
  int x;
  scanf("%d", &x);
  return x;
}
long long inl() {
  long long x;
  scanf("%lld", &x);
  return x;
}
int set_1(int n, int pos) { return n = (n | (1 << pos)); }
int reset_0(int n, int pos) { return n = n & ~(1 << pos); }
bool check_bit(int n, int pos) { return n = n & (1 << pos); }
const int N = (int)1e6 + 5;
const int M = (int)1e9 + 7;
const double pi = 2 * acos(0.0);
string s[N];
int fun(string x, string y) {
  int pos = (y + y).find(x);
  if (pos == string::npos) return 1e9;
  return pos;
}
int main() {
  int n = ini();
  for (int i = 1; i <= n; i++) cin >> s[i];
  long long res = 1e9;
  for (int i = 1; i <= n; i++) {
    long long c = 0;
    for (int j = 1; j <= n; j++) {
      if (s[i] != s[j]) {
        c += fun(s[i], s[j]);
      }
    }
    res = min(res, c);
  }
  if (res >= 1e9) res = -1;
  cout << res << endl;
  return 0;
}
