#include <bits/stdc++.h>
using namespace std;
const long long int N = 1e5;
string s;
string rotate(string second) {
  second = second + second[0];
  second = second.erase(0, 1);
  return second;
}
int main() {
  long long int n, i = 0, c = 0, ans = INT_MAX;
  cin >> n;
  string a[n];
  for (i = 0; i < n; i++) cin >> a[i];
  s = a[0];
  for (long long int i = 0; i < s.size(); i++) {
    c = 0;
    for (long long int j = 0; j < n; j++) {
      long long int temp = -1, l = 0;
      for (long long int k = 0; k < a[j].size(); k++) {
        if (s == a[j] && l == 0) {
          temp = k;
          l = 1;
        }
        a[j] = rotate(a[j]);
      }
      c += temp;
      if (temp == -1) {
        cout << -1;
        return 0;
      }
    }
    s = rotate(s);
    ans = min(ans, c);
  }
  cout << ans;
}
