#include <bits/stdc++.h>
using namespace std;
int n;
string s[55];
string S;
inline string yee(int L) {
  string S2;
  for (int i = 0; i < s[0].size(); i++) S2 += s[0][(i + L) % s[0].size()];
  return S2;
}
inline int yee2(int index) {
  int L = 0;
  bool flag;
  for (; L < s[index].size(); L++) {
    flag = true;
    for (int i = 0; i < s[index].size(); i++)
      if (s[index][(i + L) % s[index].size()] != S[i]) {
        flag = false;
        break;
      }
    if (flag) return L;
  }
  return -1;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> s[i];
  int ans = 87000000;
  for (int i = 0; i < s[0].size(); i++) {
    S = yee(i);
    int cnt = 0;
    bool flag = true;
    for (int i = 0; i < n; i++) {
      int tem = yee2(i);
      if (tem == -1) {
        flag = false;
        break;
      } else
        cnt += yee2(i);
    }
    if (flag) ans = min(ans, cnt);
  }
  if (ans != 87000000)
    cout << ans << endl;
  else
    cout << "-1" << endl;
  return 0;
}
