#include <bits/stdc++.h>
using namespace std;
bool isMatched(string sortedStr, string str) {
  string tmp = str;
  sort(tmp.begin(), tmp.end());
  return tmp == sortedStr;
}
long long getOffset(string s1, string s2) {
  int size = s1.size();
  string s2Tmp(s2);
  s2 += s2;
  int n = s2.find(s1);
  return n;
}
int main() {
  int n;
  cin >> n;
  string arr[n];
  string line;
  getline(cin, line);
  getline(cin, line);
  string sortedStr = line;
  sort(sortedStr.begin(), sortedStr.end());
  arr[0] = line;
  for (int i = 1; i < n; ++i) {
    getline(cin, line);
    arr[i] = line;
    if (!isMatched(sortedStr, line)) {
      cout << "-1\n";
      return 0;
    }
  }
  int res = 1000000;
  for (int i = 0; i < n; ++i) {
    int sum = 0;
    for (int j = 0; j < n; ++j) {
      if (i == j) continue;
      int offset = getOffset(arr[i], arr[j]);
      if (offset == -1) {
        cout << "-1\n";
        return 0;
      }
      sum += offset;
    }
    res = min(res, sum);
  }
  cout << res << "\n";
  return 0;
}
