During a New Year special offer the "Sudislavl Bars" offered n promo codes. Each promo code consists of exactly six digits and gives right to one free cocktail at the bar "Mosquito Shelter". Of course, all the promocodes differ.

As the "Mosquito Shelter" opens only at 9, and partying in Sudislavl usually begins at as early as 6, many problems may arise as to how to type a promotional code without errors. It is necessary to calculate such maximum k, that the promotional code could be uniquely identified if it was typed with no more than k errors. At that, k = 0 means that the promotional codes must be entered exactly.

A mistake in this problem should be considered as entering the wrong numbers. For example, value "123465" contains two errors relative to promocode "123456". Regardless of the number of errors the entered value consists of exactly six digits.


-----Input-----

The first line of the output contains number n (1 ≤ n ≤ 1000) — the number of promocodes.

Each of the next n lines contains a single promocode, consisting of exactly 6 digits. It is guaranteed that all the promocodes are distinct. Promocodes can start from digit "0".


-----Output-----

Print the maximum k (naturally, not exceeding the length of the promocode), such that any promocode can be uniquely identified if it is typed with at most k mistakes.


-----Examples-----
Input
2
000000
999999

Output
2

Input
6
211111
212111
222111
111111
112111
121111

Output
0



-----Note-----

In the first sample k < 3, so if a bar customer types in value "090909", then it will be impossible to define which promocode exactly corresponds to it.

Difficulty: interview

Starter code:

Solutions:
n = int(input())

m = 6
arr = []
for i in range(n):
    arr.append(input())
    
for i in range(n - 1):
    for j in range(i + 1, n):
        d = 0
        for z in range(6):
            if arr[i][z] != arr[j][z]:
                d += 1
                
        if d == 6:
            m = min(m, 2)
        elif d == 5:
            m = min(m, 2)
        elif d == 4:
            m = min(m, 1)
        elif d == 3:
            m = min(m, 1)
        else:
            m = 0
            
print(m)

n = int(input())
codes = []
for i in range(n):
    codes.append(input())


def change(a, b, k):
    x = 0
    for i in range(6):
        if a[i] != b[i]:
            x += 1
        if x == k:
            return 3
    if x % 2 == 0:
        return x // 2 - 1
    return x // 2

if n == 1:
    print(6)
    return

k = 2
for i in range(n):
    for j in range(i + 1, n):
        if change(codes[i], codes[j], 2 * k + 1) < k:
            k = change(codes[i], codes[j], 2 * k + 1)
        if k == 0:
            break
print(k)

n = int(input())
codes = [input() for i in range(n)]
def dist(w1, w2):
    assert len(w1) == len(w2)
    d = 0
    for i in range(len(w1)):
        if w1[i] != w2[i]: d += 1
    return max(0, (d-1)//2)
d = 6
for i in range(n):
    for j in range(i+1, n):
        d = min(d, dist(codes[i], codes[j]))
print(d)



count = int(input())

if count == 1:
    print('6')
else:
    hamming = 6
    codes = []
    for _ in range(count):
        new_code = input()
        for code in codes:
            distance = 0
            distance += 0 if new_code[0] == code[0] else 1
            distance += 0 if new_code[1] == code[1] else 1
            distance += 0 if new_code[2] == code[2] else 1
            distance += 0 if new_code[3] == code[3] else 1
            distance += 0 if new_code[4] == code[4] else 1
            distance += 0 if new_code[5] == code[5] else 1

            hamming = min(hamming, distance)

        codes.append(new_code)

    print(int(hamming/2 - 0.5))


def func(a,b):
    t = 0
    for i in range(6):
        if a[i] != b[i]:
            
            t+=1
    return t
n = int(input())
A = [0] * n
for i in range(n):
    A[i] = input()
per = 10
for i in range(0, n-1):
    for j in range(i+1, n):
        per = min(per, func(A[i], A[j]))
if n == 1:
    print(6)
else:
    
    if per in (5,6):
        print(2)
    elif per in (3,4):
        print(1)
    elif per in (0,1,2):
        print(0)

n = int(input())

s = [''] * (n)
for i in range(n):
    s[i] = input()

if (n == 1):
    print(6)
else:
    diff = 6
    
    for u in s:
        for v in s:
            kol = 0    
            for i in range(6):
                if u[i] != v[i]:
                    kol += 1
            if kol > 0:
                diff = min(diff, kol)
                
    diff = max(0, diff - 1)
    print(diff // 2)

import sys

def distance(s, t):
    ans = 0
    for (x, y) in zip(s, t):
        ans += (x != y)
    return ans

def min_distance(n):
    codes = [line.rstrip() for line in sys.stdin]
    m = 6
    for i in range(n):
        for j in range(i+1, n):
            d = distance(codes[i], codes[j])
            if m > d:
                m = d
                if d < 3:
                    return 1
    return m

n = int(input())
if n == 1:
    print(6)
else:
    print((min_distance(n) + 1) // 2 - 1)


3

def dist(str1, str2):
	k = 0
	for i in range(6):
		if str1[i] != str2[i]:
			k += 1

	return k

def solve(promos):
	n = len(promos)

	dist_list = [0,0,0,1,1,2,2]
	min_k = 6

	for i in range(n):
		for j in range(i+1, n):
			d = dist(promos[i], promos[j])

			k = dist_list[d]
			if k < min_k: min_k = k
			if k == 0: break

	return min_k


def test():
	import random
	import string
	import time

	while True:
		n = 1000
		promos = []
		for i in range(n):
			promo = ''.join([random.choice(string.digits) for i in range(6)])
			promos.append(promo)

		if len(set(promos)) == n:
			break

	start = time.clock()
	k = solve(promos)
	print(k)
	end = time.clock()

	print('Time: {} sec'.format(end-start))


def main():
	n = int(input())
	promos = [None]*n
	for i in range(n):
		promos[i] = input()

	k = solve(promos)

	print(k)


def __starting_point():
	# test()
	main()

__starting_point()

n = int(input())
arr = []
for i in range(n):
    line = int(input())
    arr.append(line)
m = 6
for i in range(n):
    for j in range(i+1, n):
        t1 = arr[i]
        t2 = arr[j]
        tm = 0
        for k in range(6):
            if t1 % 10 != t2 % 10: tm += 1
            t1 //= 10
            t2 //= 10
        if tm < m: m = tm
if m % 2 == 0: m -= 1
m //= 2
if m < 0: m = 0
if n == 1: m = 6
print(m)



def cmp(o1, o2):
    result = 0
    for i in range(6):
        if o1[i] != o2[i]:
            result += 1
    return result

count = int(input())
lst = []
for i in range(count):
    lst += [str(input())]
if count == 1:
    print(6)
    return

div = 6
for n in range(1, count):
    for i in range(n-1, -1, -1):
        div = min(div, cmp(lst[n], lst[i]))
        if div <= 2:
            print(0)
            return
if div >= 5:
    print(2)
elif div >= 3:
    print(1)



# import time
# start = time.time()
n = int(input())
codes = [input() for i in range(n)]
mindist = 6
for i in range(n-1):
    for j in range(i+1, n):
        d = sum([x!=y for x,y in zip(codes[i], codes[j])])
        # for k in range(6):
            # d += codes[i][k] != codes[j][k]
        if mindist > d:
            mindist = d
if (n == 1):
    print(6)
else:
    print(max(0, (mindist-1)//2))
# print(time.time()-start)
# print(mindist)


n = int(input())
codes = [tuple(input()) for i in range(n)]
mind = 13 #Dirty hack for n=1
for i in range(n-1):
    for j in range(i+1, n):
        d = sum(x!=y for x,y in zip(codes[i], codes[j]))
        if d<mind:
            mind = d
print((mind-1)//2)

import operator
import itertools
n = int(input())
strings = [input() for i in range(n)]
if n == 1:
   print(6)
else:
   minDiff = 6;
   for a, b in itertools.combinations(strings, 2):
      minDiff = min(minDiff, list(map(operator.eq, a, b)).count(False))
   print(int((minDiff - 1) / 2))

import math
def fnd(a,m,key):  #next
    f1=[0,1][key]
    f2=[lambda m:math.floor(m),lambda m:math.ceil(m)][key]
    if type(m)==int:
        return -1
    if m[0] > a:
        return -1
    if m[-1] < a:
        return -1
    if len(m)== 2:
        return(m[f1])

    r= list([m for m in [fnd(a,m[len(m)//2:],key),fnd(a,m[:len(m)//2+1],key)] if m!= -1])
    if len(r) == 0:
        return m[f2(len(m)/2)]
    return r[0]

def F(a,m,key=True):
    if (m[0] > a) and key: return m[0]
    if (m[-1] < a) and not key: return m[-1]
    return fnd(a,m,key)

def distance(a, b):
    c=0
    for i in range(len(a)):
        if a[i]!=b[i]:
            c+=1
    return c
n=int(input())
promos=[]
for i in range(n):
    promos+=[input()]
if  len(promos) == 1:
    print(6)
    return
#print([(x,y) for x in promos for y in promos if x!=y])
a=min([distance(promos[x],promos[y]) for x in range(len(promos)) for y in range(x+1,len(promos))])
r=[x for x in range(a+1) if x != a/2]
print(F(a/2,r,False))


def main():
    n, l, k = int(input()), [], 0
    if n < 2:
        print(6)
        return
    for _ in range(n):
        a = input()
        for b in l:
            x = sum(u == v for u, v in zip(a, b))
            if k < x:
                k = x
                if k > 4:
                    print(0)
                    return
        l.append(a)
    print(2 - k // 2)


def __starting_point():
    main()

__starting_point()

def main():
    from operator import eq
    n, l, k = int(input()), [], 0
    if n < 2:
        print(6)
        return
    for _ in range(n):
        a = input()
        for b in l:
            x = sum(map(eq, a, b))
            if k < x:
                k = x
                if k > 4:
                    print(0)
                    return
        l.append(a)
    print(2 - k // 2)


def __starting_point():
    main()

__starting_point()

def main():
    from operator import eq
    n, l, k = int(input()), [], 0
    if n < 2:
        print(6)
        return
    for _ in range(n):
        a = tuple(input())
        for b in l:
            x = sum(map(eq, a, b))
            if k < x:
                k = x
                if k > 4:
                    print(0)
                    return
        l.append(a)
    print(2 - k // 2)


def __starting_point():
    main()

__starting_point()

n=int(input())
l=[input() for i in range(n)]
def d(a,b): return sum(1 for k in range(6) if l[a][k]!=l[b][k])-1
print(min({d(i,j) for i in range(n) for j in range(i+1,n)}|{12})//2)

n=int(input())
l=[input() for i in range(n)]
print(min([sum(1 for k in range(6) if l[i][k]!=l[j][k])-1 for i in range(n) for j in range(i+1,n)]+[12])//2)

n=int(input())
l=[input() for i in range(n)]
print(min([sum(a!=b for a,b in zip(l[i],l[j]))-1 for i in range(n) for j in range(i+1,n)]+[12])//2)

n=int(input())
l=[input() for i in range(n)]
print(min([sum(a!=b for a,b in zip(l[i],l[j]))-1 for i in range(n) for j in range(i+1,n)]+[12])//2)

n=int(input())
l=[];s=12
for i in range(n):
 y=input()
 s=min({sum(a!=b for a,b in zip(x,y))-1 for x in l}|{s})
 l+=[y]
print(s//2)

l=[];s=12
for i in range(int(input())):
 y=input()
 s=min({sum(a!=b for a,b in zip(x,y))-1 for x in l}|{s})
 l+=[y]
print(s//2)

l=[];s=12
for i in range(int(input())):
 y=input()
 s=min({sum(a!=b for a,b in zip(x,y))-1 for x in l}|{s})
 l+=[y]
print(s//2)