#include <bits/stdc++.h>
using namespace std;
const int b[7] = {1, 10, 100, 1000, 10000, 100000, 1000000};
int i, n, W, MAX, LAB, a[1001], f[1000000];
int dfs(int x, int s) {
  if (s > MAX) return 0;
  if (W) return 1;
  for (int j, t, i = 1; i < 7; i++)
    for (j = 0; j < 10; j++) {
      t = x / b[i] * b[i] + j * b[i - 1] + x % b[i - 1];
      if (f[t] && f[t] != LAB) return W = 1;
      f[t] = LAB, dfs(t, s + 1);
    }
  return W;
}
int check() {
  for (LAB = 1; LAB <= n; LAB++)
    if (W = 0, dfs(a[LAB], 1)) return 1;
  return 0;
}
int main() {
  scanf("%d", &n);
  if (n == 1) return puts("6"), 0;
  for (i = 1; i <= n; f[a[i]] = i++) scanf("%d", &a[i]);
  for (i = 1; i < 6; i++)
    if (MAX = i, check()) break;
  printf("%d", i - 1);
}
