#include <bits/stdc++.h>
using namespace std;
struct Matrix {
  vector<vector<int>> data;
  int r, c;
  Matrix(int row, int col, bool identity = false) : r(row), c(col) {
    data.assign(row, vector<int>(col, 0));
    if (identity) {
      for (int i = 0; i < r; ++i) {
        data[i][i] = 1;
      }
    }
  }
  Matrix operator*(Matrix& other) {
    int m = r, n = c, p = other.c;
    Matrix res(m, p);
    for (int i = 0; i < m; ++i) {
      for (int j = 0; j < p; ++j) {
        for (int k = 0; k < n; ++k) {
          res.data[i][j] += data[i][k] * other.data[k][j];
        }
      }
    }
    return res;
  }
};
vector<int> extendGcd(int a, int b) {
  if (b == 0) {
    return {a, 1, 0};
  } else {
    vector<int> tmp = extendGcd(b, a % b);
    return {tmp[0], tmp[2], tmp[1] - (a / b) * tmp[2]};
  }
}
Matrix matrix_power(Matrix base, long long exp) {
  int n = base.r;
  Matrix res(n, n, true);
  while (exp) {
    if (exp & 1) {
      res = res * base;
    }
    base = base * base;
    exp >>= 1;
  }
  return res;
}
long long power_mod(long long base, int exp) {
  long long res = 1;
  while (exp) {
    if (exp & 1) res = res * base % 1000000007;
    base = base * base % 1000000007;
    exp >>= 1;
  }
  return res;
}
long long power(long long base, int exp) {
  long long res = 1;
  while (exp) {
    if (exp & 1) res *= base;
    base *= base;
    exp >>= 1;
  }
  return res;
}
long long inv(long long a) { return power_mod(a, 1000000007 - 2); }
long long fac[100010];
void initFac() {
  fac[0] = 1;
  for (int i = 1; i < 100010; ++i) {
    fac[i] = i * fac[i - 1] % 1000000007;
  }
}
long long Combine(long long a, long long b) {
  return (fac[a] * inv(fac[b]) % 1000000007) * inv(fac[a - b]) % 1000000007;
}
string foo[55];
int solve(string s1, string s2) {
  for (int i = 0; i < s1.length(); ++i) {
    if (s1 == s2.substr(i) + s2.substr(0, i)) {
      return i;
    }
  }
  return -1;
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> foo[i];
  int res = INT_MAX;
  for (int s = 0; s < foo[0].length(); ++s) {
    int sum = s;
    for (int i = 1; i < n; ++i) {
      int tmp = solve(foo[0].substr(s) + foo[0].substr(0, s), foo[i]);
      if (tmp == -1) {
        cout << -1;
        return 0;
      }
      sum += tmp;
    }
    res = min(res, sum);
  }
  cout << res;
  return 0;
}
