#include <bits/stdc++.h>
using namespace std;
const int N = 50;
char w[N + 1];
vector<pair<string, int> > g[N];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%s", w);
    string s = w;
    g[i].push_back(make_pair(s, 0));
    for (int j = 1; j < s.size(); ++j) {
      char f = s[0];
      s.erase(0, 1);
      s += f;
      g[i].push_back(make_pair(s, j));
    }
    sort(g[i].begin(), g[i].end());
  }
  int res = 1e9;
  for (int i = 0; i < g[0].size(); ++i) {
    int need = g[0][i].second, ok = 1;
    for (int j = 1; j < n; ++j) {
      int k =
          lower_bound(g[j].begin(), g[j].end(), make_pair(g[0][i].first, -1)) -
          g[j].begin();
      if (k != g[j].size() && g[j][k].first == g[0][i].first) {
        ++ok;
        need += g[j][k].second;
      }
    }
    if (ok == n) res = min(res, need);
  }
  if (res == 1e9) res = -1;
  printf("%d\n", res);
  return 0;
}
