#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string s[n];
  int c = 0;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    if (i != 0 && s[i].compare(s[i - 1]) != 0) c++;
  }
  int len = s[0].length();
  int ma = INT_MAX;
  for (int i = 0; i < n; i++) {
    int ans = 0;
    for (int j = 0; j < n; j++) {
      if (i != j) {
        string x = s[j];
        int k;
        int flag = 0;
        for (k = 0; k < len; k++) {
          if (s[i].compare(x) == 0) {
            ans += k;
            flag = 1;
            break;
          } else {
            x = x.substr(1, len - 1) + x[0];
          }
        }
        if (flag == 0) {
          cout << "-1";
          return 0;
        }
      }
    }
    ma = min(ma, ans);
  }
  cout << ma;
}
