#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  char a[55][110], b[55][110];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int len = strlen(a[0]);
  memset(b, '\0', sizeof(b));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < len; j++) {
      b[i][j] = b[i][len + j] = a[i][j];
    }
  }
  int num[55][55];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      num[i][j] = strstr(b[j], a[i]) - b[j];
      if (num[i][j] < 0) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  int minn = 0x3f3f3f3f;
  for (int i = 0; i < n; i++) {
    int sum = 0;
    for (int j = 0; j < n; j++) {
      sum += num[i][j];
    }
    minn = min(minn, sum);
  }
  cout << minn << endl;
  return 0;
}
