#include <bits/stdc++.h>
using namespace std;
const int N = 55;
const int inf = 1e9;
int main() {
  int n;
  string s[N], mp[N];
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    mp[i] = s[i] + s[i];
  }
  int flag = 0, sum = 0, ans = inf;
  for (int i = 0; i < n; i++) {
    sum = 0;
    for (int j = 0; j < n; j++) {
      if (mp[j].find(s[i]) == string::npos) {
        flag = 1;
        break;
      } else
        sum += mp[j].find(s[i]);
    }
    if (flag) break;
    ans = min(ans, sum);
  }
  if (flag)
    printf("-1\n");
  else
    printf("%d\n", ans);
  return 0;
}
