#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int N = 50;
string s[N];
map<string, int> c[N];
map<string, int> get_cyclic(string w) {
  int n = w.size();
  map<string, int> res;
  res[w] = 0;
  for (int i = 0; i < n - 1; ++i) {
    w.push_back(w[i]);
    string x;
    for (int(j) = (i + 1); (j) <= (w.size() - 1); ++j) {
      x += w[j];
    }
    auto it = res.find(x);
    if (it == res.end() || i + 1 < it->second) {
      res[x] = i + 1;
    }
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  for (int(i) = 0; (i) < (n); ++(i)) cin >> s[i];
  for (int(i) = 0; (i) < (n); ++(i)) {
    c[i] = get_cyclic(s[i]);
  }
  int res = INF;
  for (auto it = c[0].begin(); it != c[0].end(); ++it) {
    int tmp = it->second;
    bool fail = 0;
    for (int j = 1; j < n; ++j) {
      auto it2 = c[j].find(it->first);
      if (it2 == c[j].end()) {
        fail = 1;
        break;
      }
      tmp += it2->second;
    }
    if (fail) continue;
    (res) = min((res), (tmp));
    ;
  }
  cout << (res == INF ? -1 : res) << endl;
  return 0;
}
