#include <bits/stdc++.h>
using namespace std;
int main() {
  string a[100];
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  int result = 99999999;
  int dem = 0, kkkk = 0;
  bool upp = false;
  for (int i = 0; i < n; i++) {
    string s = a[i];
    for (int j = 0; j < n; j++) {
      string t = a[j];
      if (i != j && t != s) {
        dem++;
        kkkk = 0;
        bool stt = false;
        while (stt == false) {
          string p = "";
          p += t.substr(1, t.size()) + t[0];
          if (p != s) {
            dem++;
            kkkk++;
            t = p;
          } else
            stt = true;
          if (kkkk > t.size()) {
            upp = true;
            break;
          }
        }
        if (upp == true) break;
      }
      if (upp == true) break;
    }
    result = min(result, dem);
    dem = 0;
    if (upp == true) break;
  }
  if (upp == true)
    cout << -1 << endl;
  else
    cout << result << endl;
  return 0;
}
