#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, ans = -1;
  cin >> n;
  string s[n];
  for (int i = 0; i < n; i++) cin >> s[i];
  for (int i = 0; i < s[0].size(); i++) {
    for (int j = 1; j < n; j++)
      if (s[j][i] != s[0][i]) {
        ans = i;
        break;
      }
    if (ans > -1) break;
  }
  cout << ans << "\n";
}
