#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200;
const int INF = 0x3f3f3f3f;
int cnt[MAXN];
int cnt_[MAXN];
string s[MAXN];
int main(int argc, const char* argv[]) {
  int n;
  cin >> n;
  cin >> s[0];
  for (int i = 0; i < s[0].length(); i++) {
    cnt[s[0][i]]++;
  }
  for (int i = 1; i < n; i++) {
    cin >> s[i];
    memset(cnt_, 0, sizeof(cnt_));
    if (s[i].length() != s[0].length()) {
      cout << "-1\n";
      return 0;
    }
    for (int j = 0; j < s[i].length(); j++) {
      cnt_[s[i][j]]++;
      if (cnt_[s[i][j]] > cnt[s[i][j]]) {
        cout << "-1\n";
        return 0;
      }
    }
  }
  int res = INF;
  int flag = 0;
  for (int i = 0; i < n; i++) {
    int temp = 0;
    for (int j = 0; j < n; j++) {
      if (i == j) {
        continue;
      }
      flag = 0;
      for (int x = 0; x < s[0].length(); x++) {
        for (int k = 0; k < s[0].length(); k++) {
          if (s[i][x] == s[j][k]) {
            flag = 1;
            for (int l = 1; l < s[0].length(); l++) {
              if (s[i][(x + l) % s[0].length()] !=
                  s[j][(k + l) % s[0].length()]) {
                flag = 0;
                break;
              }
            }
          }
          if (flag) {
            temp += k - x;
            break;
          }
        }
        if (flag) {
          break;
        }
      }
    }
    res = min(res, temp);
  }
  if (res == 0 && flag == 0 && n != 1) {
    cout << -1 << '\n';
  } else {
    cout << res << '\n';
  }
  return 0;
}
