#include <bits/stdc++.h>
using namespace std;
long long t, n, m, k, c, l, x, y, z;
const int N = 2e5 + 500;
const long long mod = 1e9 + 7;
const long long INF = 1LL << 57;
long long arr[N];
string str, ss;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  vector<string> v1;
  for (int i = 0; i < n; i++) {
    cin >> str;
    v1.push_back(str);
  }
  long long ans = 100000000;
  int flag = 0;
  for (vector<string>::iterator it = v1.begin(); it != v1.end(); it++) {
    string temp = *it;
    long long count = 0;
    for (vector<string>::iterator it2 = v1.begin(); it2 != v1.end(); it2++) {
      string t2 = *it2;
      long long t5 = count;
      while (t2 != temp) {
        count++;
        t2 = t2.substr(1) + t2.at(0);
        if (count - t5 > t2.length()) {
          flag = 1;
          break;
        }
      }
      if (flag == 1) {
        break;
      }
    }
    if (flag == 1) {
      break;
    }
    if (ans > count) {
      ans = count;
    }
  }
  if (flag == 1) {
    cout << -1;
  } else {
    cout << ans;
  }
  return 0;
}
