#include <bits/stdc++.h>
using namespace std;
long long GCD(long long n1, long long n2) {
  if (n2 != 0)
    return GCD(n2, n1 % n2);
  else
    return n1;
}
long long LCM(long long n1, long long n2) {
  long long m;
  m = n1 * n2 / GCD(n1, n2);
  return m;
}
unsigned long long choose(unsigned long long n, unsigned long long k) {
  if (k > n) {
    return 0;
  }
  unsigned long long r = 1;
  for (unsigned long long d = 1; d <= k; ++d) {
    r *= n--;
    r /= d;
  }
  return r;
}
bool isprime(int x) {
  if (x == 1) return 0;
  for (int i = 2; i * i < x; i++) {
    if (x % i == 0) return 0;
  }
  return 1;
}
long long che(string a, string b) {
  long long d = 0, c = 0;
  char e;
  while (d < b.size()) {
    if (a == b) {
      return c;
    }
    c++;
    e = b[0];
    b.erase(0, 1);
    b += e;
    d++;
  }
  return -1;
}
string arr[52], m;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long c, d, f;
  char e;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  long long mn = 1e18;
  for (int i = 0; i < n; i++) {
    m = arr[i];
    c = 0;
    d = 0;
    while (d < m.size()) {
      bool da = 1;
      long long g = 0;
      for (int j = 0; j < n; j++) {
        if (j != i)
          f = che(m, arr[j]);
        else
          f = 0;
        if (f == -1) {
          da = 0;
          break;
        } else {
          g += f;
        }
      }
      e = m[0];
      m.erase(0, 1);
      m += e;
      if (da) {
        mn = min(mn, c + g);
      }
      c++;
      d++;
    }
  }
  if (mn != 1e18)
    cout << mn << endl;
  else
    cout << -1 << endl;
  return 0;
}
