#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  string arr[n];
  for (int i = 0; i < n; ++i) cin >> arr[i];
  string y = "";
  int c = 0;
  int mn = 1000000;
  for (int i = 0; i < arr[0].size(); ++i) {
    y = "";
    for (int j = i, k = 0; k < (int)arr[0].size(); ++j, ++k)
      y += arr[0][j % arr[0].size()];
    c = 0;
    for (int j = 0; j < n; ++j) {
      bool flag = true;
      for (int k = 0; k < arr[j].size(); ++k) {
        flag = true;
        for (int l = k, m = 0; m < arr[j].size(); ++l, ++m) {
          if (arr[j][l % arr[j].size()] != y[m]) {
            flag = false;
            break;
          }
        }
        if (flag) {
          c += k;
          break;
        }
      }
      if (!flag) {
        cout << -1;
        return 0;
      }
    }
    mn = min(mn, c);
  }
  cout << mn;
  return 0;
}
