#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  bool is_end = false;
  vector<string> vec;
  for (int i = 0; i < n; ++i) {
    string second;
    cin >> second;
    if (second.empty()) is_end = true;
    vec.push_back(second);
  }
  if (is_end) {
    cout << "-1\n";
    return 0;
  }
  int answer = 1e9;
  for (int i = 0; i < n; i++) {
    auto now_str = vec[i];
    int tmp_answer = 0;
    for (int j = 0; j < n; ++j) {
      auto proc_str = vec[j];
      auto tmp_var = 0;
      if (i == j) {
        continue;
      } else {
        while (proc_str != now_str && tmp_var < proc_str.size()) {
          proc_str.push_back(proc_str[0]);
          proc_str.erase(proc_str.begin());
          tmp_var++;
        }
        if (tmp_var == proc_str.size()) {
          cout << "-1\n";
          return 0;
        } else {
          tmp_answer += tmp_var;
        }
      }
    }
    answer = min(answer, tmp_answer);
  }
  if (answer == 1e9) {
    cout << "-1\n";
  } else {
    cout << answer << endl;
  }
  return 0;
}
