#include <bits/stdc++.h>
using namespace std;
const int N = 100;
string s[N];
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    cin >> s[i];
  }
  int z = 1e9;
  for (int i = 0; i < t; i++) {
    int ans = 0, flag = 0;
    for (int j = 0; j < t; j++) {
      int y = 100, cnt = 0;
      string tmp = s[j];
      while (y--) {
        if (s[j] != s[i]) {
          char ch = s[j][0];
          s[j].erase(s[j].begin());
          s[j] += ch;
        } else {
          flag++;
          ans += cnt;
          break;
        }
        cnt++;
      }
      s[j] = tmp;
    }
    if (flag == t) z = min(z, ans);
  }
  if (z == 1e9)
    cout << -1;
  else
    cout << z << endl;
}
