#include <bits/stdc++.h>
const int INF = 2147483647;
const int MOD = 1000000007;
const long long INF64 = 9223372036854775807;
const long double EPS = 1e-7;
using namespace std;
int check(const vector<int> &a, const vector<int> &b) {
  int cur = 0;
  for (int i = 0; i < 6; i++) cur += (a[i] == b[i]);
  return max(0, (6 - cur) / 2 + (6 - cur) % 2 - 1);
}
int main() {
  int n, t;
  scanf("%d", &n);
  vector<int> a[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", &t);
    int k = 100000;
    while (k) {
      a[i].push_back(t / k);
      t %= k;
      k /= 10;
    }
  }
  int ans = 6;
  for (int i = 0; i < n; i++)
    for (int j = i + 1; j < n; j++) ans = min(ans, check(a[i], a[j]));
  printf("%d\n", ans);
  return 0;
}
