#include <bits/stdc++.h>
using namespace std;
const int N = 100;
vector<string> v(N);
int sz;
int check(string a, string b) {
  if (a == b) {
    return 0;
  }
  int x = 0, y = 0;
  for (int k = 0; k < sz; ++k) {
    int j = 0, i = k;
    while (i < sz && j < sz && a[j] == b[i]) {
      ++i;
      ++j;
    }
    if (i == sz || j == sz) {
      x = k;
      y = j;
      break;
    }
  }
  if (x == 0 || y == 0) {
    return (int)1e4;
  }
  int as = 0;
  for (int i = 0; i < x && y < sz; ++i, ++y) {
    if (a[y] != b[i]) {
      return (int)1e4;
    } else
      ++as;
  }
  return as;
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    cin >> v[i];
  }
  sz = v[0].size();
  int ans = 1e9;
  for (int i = 0; i < n; ++i) {
    int tmp = 0;
    for (int j = 0; j < n; ++j) {
      int res = check(v[i], v[j]);
      tmp += res;
    }
    ans = min(ans, tmp);
  }
  ans >= (int)1e4 ? puts("-1") : printf("%d\n", ans);
  return 0;
}
