#include <bits/stdc++.h>
using namespace std;
const int N = 10000;
int n, len, f = 1;
string s[N], c[N];
long long a[N];
long long sum, ans = 1e8, st;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> c[i];
  }
  len = c[1].length();
  for (int i = 2; i <= n; i++) {
    int line;
    line = c[i].length();
    if (line != len) {
      f = 0;
      break;
    }
  }
  if (f == 0) {
    cout << -1;
    return 0;
  }
  s[1] = c[1];
  for (int j = 1; j <= len; j++) {
    s[1] += s[1][0];
    s[1].erase(0, 1);
    st++;
    if (st == len) st = 0;
    for (int i = 2; i <= n; i++) {
      s[i] = c[i];
    }
    for (int i = 1; i <= n; i++) {
      while (s[i] != s[1]) {
        s[i] += s[i][0];
        s[i].erase(0, 1);
        a[i]++;
        if (a[i] > len) {
          f = 0;
          break;
        }
      }
      if (f == 0) {
        break;
      }
    }
    if (f == 0) {
      break;
    }
    sum = st;
    for (int i = 1; i <= n; i++) {
      sum += a[i];
    }
    memset(a, 0, sizeof(a));
    ans = min(ans, sum);
  }
  if (f == 0) {
    cout << -1;
    return 0;
  }
  cout << ans;
  return 0;
}
