#include <bits/stdc++.h>
using namespace std;
string s[51], o;
int n, b, sum = 2e9, x, y, bo[51];
set<int> a[51];
inline int work(int i, int k) {
  int sum = 0;
  sum += i - k;
  if (i - k < 0) sum += s[1].size();
  return sum;
}
int main(void) {
  register int i, j, k;
  scanf("%d", &n);
  for (i = 1; i <= n; ++i) cin >> s[i];
  for (i = 1; i <= n; ++i) {
    if (s[i] == s[1]) a[i].insert(0), b += !bo[i], bo[i] = 1;
  }
  o = s[1];
  for (i = 1; i < s[1].size(); ++i) {
    o = o.substr(1, s[1].size() - 1) + o[0];
    for (j = 1; j <= n; ++j)
      if (o == s[j]) a[j].insert(i), b += !bo[j], bo[j] = 1;
  }
  if (b != n) {
    puts("-1");
    return 0;
  }
  for (i = 0; i < s[1].size(); ++i) {
    x = 0;
    for (j = 1; j <= n; ++j) {
      y = 2e9;
      for (set<int>::iterator k = a[j].begin(); k != a[j].end(); ++k)
        y = min(y, work(i, *k));
      x += y;
    }
    sum = min(sum, x);
  }
  printf("%d", sum);
  return 0;
}
