#include <bits/stdc++.h>
using byte = char;
using llong = long long;
using namespace std;
int find_shift(string& a, string& b) {
  if (a.length() != b.length()) {
    return -1;
  }
  for (int i = 0; i < a.length(); ++i) {
    bool eq = true;
    for (int j = 0; j < a.length(); ++j) {
      if (a[j] != b[(i + j) % a.length()]) {
        eq = false;
        break;
      }
    }
    if (eq) {
      return i;
    }
  }
  return -1;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<string> s(n);
  for (auto&& str : s) {
    cin >> str;
  }
  vector<int> num_moves(n);
  for (int i = 0; i < n; ++i) {
    int entire_shift = 0;
    for (int j = 0; j < n; ++j) {
      int shift = find_shift(s[i], s[j]);
      if (shift == -1) {
        cout << -1 << '\n';
        return 0;
      }
      entire_shift += shift;
    }
    num_moves[i] = entire_shift;
  }
  cout << *min_element(num_moves.begin(), num_moves.end()) << '\n';
  return 0;
}
