#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, res = 0, RES = 99999999;
  cin >> n;
  string s[n];
  for (int a = 0; a < n; a++) {
    cin >> s[a];
  }
  string s1, s2;
  bool ANS = true;
  for (int b = 0; b < n; b++) {
    s1 = s[b];
    s1 = s1 + s1;
    res = 0;
    for (int a = 0; a < n; a++) {
      s2 = s[a];
      bool ans = false;
      int agregar;
      for (int c = 0; c <= s1.size() / 2; c++) {
        if (s1.substr(c, s2.size()) == s2) {
          agregar = s2.size() - c;
          if (c == 0) agregar = 0;
          ans = true;
        }
      }
      res += agregar;
      if (!ans) ANS = false;
    }
    RES = min(res, RES);
  }
  if (ANS)
    cout << RES << endl;
  else
    cout << -1 << endl;
  return 0;
}
