#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string s[n];
  int minCost = INT_MAX;
  for (int i = 0; i < n; i++) cin >> s[i];
  for (int i = 0; i < n; i++) {
    int curr = 0;
    for (int j = 0; j < n; j++) {
      if (j != i) {
        string temp = s[j];
        bool flag = false;
        int count = 0;
        for (int k = 0; k < s[j].size(); k++) {
          if (temp == s[i]) {
            flag = true;
            break;
          }
          count++;
          temp = temp.substr(1) + temp[0];
        }
        if (!flag) {
          cout << -1 << endl;
          return 0;
        }
        curr += count;
      }
    }
    minCost = min(minCost, curr);
  }
  cout << minCost << endl;
}
