#include <bits/stdc++.h>
using namespace std;
int main() {
  int cnt, n, ans = 100000;
  string a[55], temp;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) {
    cnt = 0;
    for (int j = 0; j < n; j++) {
      temp = a[j] + a[j];
      if (temp.find(a[i]) == string::npos) {
        cout << -1 << endl;
        return 0;
      } else
        cnt += temp.find(a[i]);
    }
    ans = min(ans, cnt);
  }
  cout << ans << endl;
}
