#include <bits/stdc++.h>
using namespace std;
vector<int> v[57][57];
char a[57][57];
int main() {
  int m;
  scanf("%d", &m);
  int i, j, r, rr;
  for (i = 0; i < m; i++) scanf("%s", a[i]);
  int lm = strlen(a[0]);
  int lt;
  for (i = 0; i < lm; i++) {
    for (j = 1; j < m; j++) {
      for (r = 0; r < lm; r++) {
        lt = 0;
        for (rr = 0; rr < lm; rr++) {
          if (a[0][(i + rr) % lm] != a[j][(r + rr) % lm]) {
            lt = 1;
            break;
          }
        }
        if (!lt) v[i][j].push_back(r);
      }
    }
  }
  int ans = 1e9;
  for (i = 0; i < lm; i++) {
    int anss = 0;
    for (j = 1; j < m; j++) {
      if (v[i][j].empty()) break;
      int tem = 1e9;
      for (r = 0; r < v[i][j].size(); r++) tem = min(tem, v[i][j][r]);
      anss = anss + tem;
    }
    if (j != m) anss = 1e9;
    ans = min(anss + i, ans);
  }
  if (ans == 1e9) ans = -1;
  printf("%d\n", ans);
  return 0;
}
