#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n, m, ans = INT_MAX;
  cin >> n;
  string second[n];
  for (int i = 0; i < n; i++) {
    cin >> second[i];
    second[i] = second[i] + second[i];
  }
  m = second[0].length() / 2;
  long long dp[n][m];
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) dp[i][j] = INT_MAX;
  for (int i = 0; i < m; i++) dp[0][i] = i;
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < m; j++) {
      for (int k = 0; k < m; k++) {
        if (second[i].substr(j, m) == second[i - 1].substr(k, m))
          dp[i][j] = min(dp[i][j], dp[i - 1][k] + j);
      }
    }
  }
  for (int i = 0; i < m; i++) ans = min(ans, dp[n - 1][i]);
  if (ans == INT_MAX)
    cout << -1;
  else
    cout << ans;
  return 0;
}
