#include <bits/stdc++.h>
using namespace std;
long long n, ans = 1e10;
string s[55][55];
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (long long i = 0; i < n; ++i) {
    cin >> s[i][0];
  }
  for (long long i = 0; i < n; ++i) {
    for (long long j = 1; j < s[0][0].length(); ++j) {
      s[i][j] = s[i][j - 1];
      for (long long k = 0; k < s[0][0].length(); ++k) {
        s[i][j][k] = s[i][j - 1][k + 1];
      }
      s[i][j][s[0][0].length() - 1] = s[i][j - 1][0];
    }
  }
  for (long long i = 0; i < n; ++i) {
    long long res = 0;
    for (long long j = 0; j < n; ++j) {
      if (i == j) continue;
      long long a = 0;
      while (s[i][0] != s[j][a]) {
        ++a;
        if (a >= s[0][0].length()) {
          cout << "-1";
          return 0;
        }
      }
      res += a;
    }
    ans = min(ans, res);
  }
  cout << ans;
  return 0;
}
