#include <bits/stdc++.h>
using namespace std;
int n, dp[51][51], ans = 1e9;
string s[51];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> s[i];
  int k = s[1].size();
  for (int i = 1; i <= n; i++)
    for (int j = 0; j < k; j++) dp[i][j] = 1e9;
  for (int i = 0; i < k; i++) dp[1][i] = i;
  for (int i = 1; i <= n; i++) s[i] = s[i] + s[i];
  for (int i = 2; i <= n; i++) {
    for (int j = 0; j < k; j++)
      for (int pre = 0; pre < k; pre++)
        if (s[i].substr(j, k) == s[i - 1].substr(pre, k)) {
          dp[i][j] = min(dp[i][j], dp[i - 1][pre] + j);
        }
  }
  for (int i = 0; i < k; i++) ans = min(ans, dp[n][i]);
  if (ans == 1e9)
    cout << -1;
  else
    cout << ans;
}
