#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string arr[n + 1];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  int h[200] = {0};
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < arr[i].length(); j++) {
      h[arr[i][j]]++;
    }
  }
  for (int i = 97; i <= 122; i++) {
    if (h[i] % n != 0 && h[i] != 0) {
      cout << -1 << endl;
      return 0;
    }
  }
  int ans = INT_MAX;
  int flag = 0;
  for (int i = 0; i < n; i++) {
    int cnt = 0;
    string tmp1 = arr[i];
    for (int j = 0; j < n; j++) {
      string tmp2 = arr[j];
      while (tmp2 != tmp1) {
        cnt++;
        tmp2 += tmp2[0];
        tmp2.erase(tmp2.begin());
        if (tmp2 == arr[j]) {
          flag = 1;
          break;
        }
      }
    }
    if (flag) {
      cout << -1 << endl;
      return 0;
    }
    ans = min(ans, cnt);
  }
  cout << ans << endl;
}
