#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int main() {
  int n;
  cin >> n;
  vector<string> v(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  int mn = 1e8;
  for (int i = 0; i < n; i++) {
    int res = 0;
    for (int j = 0; j < n; j++) {
      string s = v[j];
      if (s == v[i]) continue;
      int cnt = 0;
      while (s != v[i]) {
        s.push_back(s.front());
        s.erase(s.begin());
        ++cnt;
        if (cnt > s.length()) return puts("-1"), 0;
      }
      res += cnt;
    }
    mn = min(mn, res);
  }
  cout << mn << endl;
  return 0;
}
