#include <bits/stdc++.h>
using namespace std;
int n, fi[60], res = INT_MAX;
string a[60], t, ta;
int aa[200], bb[200];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  int x = a[1].length() - 1;
  for (int i = 0; i <= x; i++) aa[a[1][i]]++;
  for (int i = 2; i <= n; i++) {
    memset(bb, 0, sizeof(bb));
    for (int j = 0; j <= x; j++) bb[a[i][j]]++;
    for (int j = 'a'; j <= 'z'; j++)
      if (aa[j] != bb[j]) {
        cout << -1;
        return 0;
      }
  }
  for (int i = 1; i <= n; i++) {
    fi[i] = 0;
    for (int j = 1; j <= n; j++) {
      if (i == j) continue;
      t = a[j];
      if (t == a[i]) continue;
      for (int k = 0; k < a[j].length(); k++) {
        fi[i]++;
        char x = t[0];
        t.erase(0, 1);
        t += x;
        if (t == a[i]) break;
      }
      if (t != a[i]) fi[i] = INT_MAX;
    }
  }
  for (int i = 1; i <= n; i++) res = min(res, fi[i]);
  if (res == INT_MAX)
    cout << -1;
  else
    cout << res;
}
