#include <bits/stdc++.h>
using namespace std;
int diff(string a, string b, int n) {
  int c = 0;
  for (long long int(i) = (0); (i) < (n); (i)++) {
    if (a == b)
      return c;
    else {
      b = b.substr(1) + b[0];
      c++;
    }
  }
  return -1;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  int n;
  cin >> n;
  string ar[n];
  for (long long int(i) = (0); (i) < (n); (i)++) cin >> ar[i];
  int len = ar[0].length();
  int c = 0;
  int ans = INT_MAX;
  int flag = 1;
  string s = ar[0];
  for (long long int(i) = (0); (i) < (len); (i)++) {
    c = i;
    for (long long int(j) = (1); (j) < (n); (j)++) {
      string temp = ar[j];
      if (diff(s, temp, len) == -1) {
        flag = 0;
      }
      c += diff(s, temp, len);
    }
    s = s.substr(1) + s[0];
    ans = min(ans, c);
  }
  if (flag)
    cout << ans << "\n";
  else
    cout << "-1\n";
}
