#include <bits/stdc++.h>
using namespace std;
vector<int *> promo;
int cnt(int a, int b) {
  int ans = 0;
  for (int i = 0; i < 6; ++i) {
    if (promo[a][i] == promo[b][i]) {
      ans++;
    }
  }
  return ans;
}
int main() {
  int n;
  cin >> n;
  int ans = 6;
  for (int i = 0; i < n; ++i) {
    int *mas = new int[6];
    char a;
    for (int j = 0; j < 6; ++j) {
      cin >> a;
      mas[j] = a - '0';
    }
    promo.push_back(mas);
  }
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      int cntod = cnt(i, j);
      ans = min(ans, (int)((5 - cntod) / 2));
    }
  }
  cout << ans << endl;
  return 0;
}
