#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, i, j, t = 0, ans = 1e10;
  cin >> n;
  string s[n], temp;
  for (i = 0; i < n; i++) cin >> s[i];
  for (i = 0; i < n; i++) {
    t = 0;
    for (j = 0; j < n; j++) {
      temp = s[j] + s[j];
      if (temp.find(s[i]) == string::npos) {
        cout << "-1";
        return 0;
      }
      t += temp.find(s[i]);
    }
    ans = min(t, ans);
  }
  cout << ans;
}
