#include <bits/stdc++.h>
using namespace std;
string str[60], ot, po;
int rev[100];
int n, i, j, k, minn, u, q, rest;
int main() {
  scanf("%d", &n);
  for (i = 0; i < n; i++) cin >> str[i];
  minn = int(1e10);
  po = str[0];
  po += str[0];
  bool fg = false;
  for (i = 1; i < n; i++) {
    u = po.find(str[i]);
    if (u < 0) fg = true;
  }
  if (fg) {
    puts("-1");
    return 0;
  }
  for (i = 0; i < n; i++) {
    rest = 0;
    for (j = 0; j < n; j++) {
      if (i == j) continue;
      po = str[j] + str[j];
      u = po.find(str[i]);
      rest += (u);
    }
    minn = min(rest, minn);
  }
  cout << minn;
}
