#include <bits/stdc++.h>
using namespace std;
template <class T>
T emin(T &a, T b) {
  if (a > b) a = b;
  return a;
}
template <class T>
T emax(T &a, T b) {
  if (a < b) a = b;
  return a;
}
string s[100];
int nr, mx = 2e9, n;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> s[i];
  for (int i = 1; i <= n; i++) {
    int curr = 0;
    for (int j = 1; j <= n; j++) {
      if (i == j) continue;
      int z = 0;
      string p = s[j];
      while (p != s[i] && z < s[i].size()) {
        char c = p[0];
        p.erase(p.begin());
        p += c;
        z++;
        curr++;
      }
      if (z == s[i].size()) return cout << "-1", 0;
    }
    mx = min(curr, mx);
  }
  cout << mx;
}
