#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, res = 10005, flag = 0;
  string s[64];
  cin >> n;
  for (int i = 0; i < n; i++) cin >> s[i];
  for (int i = 0; i < n; i++) {
    int ans = 0;
    for (int j = 0; j < n; j++) {
      string temp;
      int k;
      for (k = 0; k < s[j].length(); k++) {
        temp = s[j].substr(k) + s[j].substr(0, k);
        if (temp.compare(s[i]) == 0) {
          ans += k;
          break;
        }
      }
      if (k == s[j].length()) flag = 1;
      if (flag == 1) break;
    }
    if (flag == 1) break;
    res = min(ans, res);
  }
  if (flag == 1)
    cout << -1 << endl;
  else
    cout << res << endl;
  return 0;
}
