#include <bits/stdc++.h>
using namespace std;
set<string> used;
int pos[4];
bool _free(int p, int i) {
  if (p == 0) return true;
  if (p == 1) return i != pos[0];
  if (p == 2) return i != pos[0] && i != pos[1];
  if (p == 3) return i != pos[0] && i != pos[1] && i != pos[2];
}
bool gen_impl(int errors, string& seq, int step = 0) {
  if (step == errors) {
    if (used.find(seq) != used.end()) {
      return false;
    } else {
      used.insert(seq);
      return true;
    }
  } else {
    int begin = 0;
    if (step != 0) {
      begin = pos[step - 1] + 1;
    }
    for (int i = begin; i < 6; i++) {
      pos[step] = i;
      char sv = seq[i];
      for (int j = '0'; j <= '9'; j++) {
        if (j != sv) {
          seq[i] = j;
          if (!gen_impl(errors, seq, step + 1)) {
            return false;
          }
        }
      }
      seq[i] = sv;
    }
    return true;
  }
}
bool gen(int errors, string& seq) { return gen_impl(errors, seq); }
int main() {
  ios::sync_with_stdio(false);
  int cnt;
  cin >> cnt;
  if (cnt == 1) {
    cout << 6 << endl;
    return 0;
  }
  vector<string> codes(cnt);
  for (int i = 0; i < cnt; i++) {
    string seq;
    cin >> seq;
    codes[i] = seq;
  }
  for (int i = 0; i <= 3; i++) {
    for (int j = 0; j < cnt; j++) {
      if (!gen(i, codes[j])) {
        cout << i - 1 << endl;
        return 0;
      }
    }
  }
  cout << 2 << endl;
}
