#include <bits/stdc++.h>
using namespace std;
int n, num[64];
string s[64];
int number(string s1, string s2) {
  if (s1 == s2) return 0;
  for (int i = 1; i < s1.length(); i++) {
    string tail = s1.substr(0, i);
    string head = s1.substr(i, s1.length() - i);
    if (head + tail == s2) return i;
  }
  return -1;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> s[i];
  int mn = 2e9;
  for (int i = 1; i <= n; i++) {
    int ans = 0;
    for (int j = 1; j <= n; j++) {
      int num = number(s[j], s[i]);
      if (num == -1) {
        cout << -1;
        return 0;
      }
      ans += num;
    }
    mn = min(mn, ans);
  }
  cout << mn;
}
