#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
deque<char> s[55];
inline int circular(deque<char> s1, deque<char> s2) {
  int i = 0;
  while (i < s1.size()) {
    if (s1 == s2) return i;
    s1.push_back(s1.front());
    s1.pop_front();
    i++;
  }
  return -1;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, m;
  cin >> n;
  if (n == 1) {
    cout << "0";
    return 0;
  }
  for (int i = 0; i < n; i++) {
    string t;
    cin >> t;
    for (int j = 0; j < t.size(); j++) s[i].push_back(t[j]);
  }
  int res = (1 << 30);
  deque<char> tmp = s[0];
  for (int i = 0; i < tmp.size(); i++) {
    int ans = 0;
    for (int j = 0; j < n; j++) {
      int x = circular(s[j], tmp);
      if (x == -1) {
        cout << "-1";
        return 0;
      }
      ans += x;
    }
    res = min(res, ans);
    tmp.push_back(tmp.front());
    tmp.pop_front();
  }
  cout << res;
  return 0;
}
