#include <bits/stdc++.h>
using namespace std;
string star[55], str, str1, str2;
int main() {
  int n, a;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> star[i];
  }
  str = star[0];
  int ans = 100000000;
  for (int i = 0; i < str.length(); i++) {
    bool f = 1;
    a = 0;
    for (int j = 0; j < n; j++) {
      str1 = star[j];
      while (str1 != str) {
        str1 += str1[0];
        str1.erase(str1.begin());
        a++;
        if (str1 == star[j]) break;
      }
      if (str1 != str) {
        f = 0;
        break;
      }
    }
    if (f) ans = min(ans, a);
    str += str[0];
    str.erase(str.begin());
  }
  if (ans == 100000000) ans = -1;
  cout << ans;
  return 0;
}
