#include <bits/stdc++.h>
using namespace std;
int f(string s1, string s2) {
  int k = 0;
  while (s2 != s1) {
    s2 += s2[0];
    s2 = s2.substr(1);
    k++;
    if (k > s2.length()) return 1000000;
  }
  return k;
}
int main() {
  int n;
  cin >> n;
  vector<string> V(n);
  for (int i = 0; i < n; i++) cin >> V[i];
  int MIN = 1000000, ans;
  for (int i = 0; i < n; i++) {
    ans = 0;
    for (int j = 0; j < n; j++)
      if (j != i) ans += f(V[i], V[j]);
    if (ans < MIN) MIN = ans;
  }
  if (MIN == 1000000)
    cout << -1 << endl;
  else
    cout << MIN << endl;
  return 0;
}
