#include <bits/stdc++.h>
using namespace std;
string arr[100];
string dop[100];
int ans, res = 1e9;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> arr[i];
  for (int i = 0; i < n; i++) {
    ans = 0;
    for (int j = 0; j < n; j++) {
      dop[j] = arr[j];
      int z = 0;
      while (dop[j] != arr[i] and z < arr[i].size()) {
        for (int k = 1; k < dop[j].size(); k++) {
          swap(dop[j][k], dop[j][k - 1]);
        }
        z++;
        ans++;
      }
      if (arr[i] != dop[j]) {
        cout << -1;
        return 0;
      }
    }
    res = min(res, ans);
  }
  cout << res;
  return 0;
}
