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: MEDIUM

Solutions:
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)
elif per in (5, 6):
	print(2)
elif per in (3, 4):
	print(1)
elif per in (0, 1, 2):
	print(0)


from sys import stdin
n = int(input())
if n == 1:
	print(6)
	exit()
arr = stdin.read().strip().splitlines()
ans = 6
i = 0
while i < n:
	j = i + 1
	while j < n:
		(s, k) = (0, 0)
		while k < 6:
			if arr[i][k] == arr[j][k]:
				s += 1
			k += 1
		if s < 2:
			ans = min(ans, 2)
		elif s < 4:
			ans = 1
		elif s < 6:
			print(0)
			exit()
		j += 1
	i += 1
print(ans)


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)
main()


def checcker(x, y):
	p = 0
	for mkT in range(6):
		if x[mkT] == y[mkT]:
			p = p + 1
		if p >= 4:
			break
	return p

def viewer_finish(x, k):
	if x != 1:
		if k >= 4:
			print('0')
		elif k == 3 or k == 2:
			print('1')
		elif k == 1 or k == 0:
			print('2')
	else:
		print(6)

def checcker_main(kList, x):
	k = 0
	for fmN in range(x - 1):
		for KKT in range(fmN + 1, x):
			p = checcker(kList[fmN], kList[KKT])
			if p > k:
				k = p
			if k >= 4:
				break
		if k >= 4:
			break
	return k

def main():
	kList = []
	x = int(input())
	for i in range(x):
		kList.append(input())
	k = checcker_main(kList, x)
	viewer_finish(x, k)
main()


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)


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)


n = int(input())
codes = [tuple(input()) for i in range(n)]
mind = 13
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)


ans = 12
l = [input() for i in range(int(input()))]
for i in range(len(l)):
	for j in range(i + 1, len(l)):
		d = 0
		for w in range(6):
			d += l[i][w] != l[j][w]
		ans = min(d - 1, ans)
print(ans // 2)


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)


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():
	main()
__starting_point()


def C():
	answer_dict = {6: 2, 5: 2, 4: 1, 3: 1, 2: 0, 1: 0, 0: 0}
	n = int(input())
	if n == 1:
		return 6
	promocodes = [str(input()) for i in range(n)]
	min_diff = 6
	for i in range(len(promocodes) - 1):
		for j in range(i + 1, len(promocodes)):
			count_diff = 0
			for (r, k) in zip(promocodes[i], promocodes[j]):
				if r != k:
					count_diff += 1
			if count_diff < min_diff:
				min_diff = count_diff
	return answer_dict[min_diff]
print(C())


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)
	exit()
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)
			exit()
if div >= 5:
	print(2)
elif div >= 3:
	print(1)


def main():
	minEr = 6
	a = eval(input())
	promocodes = [input() for i in range(a)]
	for i in range(len(promocodes)):
		for j in range(i):
			cnt = 0
			for k in range(6):
				if promocodes[i][k] != promocodes[j][k]:
					cnt += 1
			minEr = min(minEr, (cnt - 1) // 2)
	print(minEr)
main()


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from bisect import bisect_left
from collections import Counter
n = int(input())
ls = [input() for i in range(n)]
m = 6
if n == 1:
	print(6)
	exit()
for i in range(n):
	for j in range(i + 1, n):
		cnt = 0
		for k in range(6):
			if ls[i][k] != ls[j][k]:
				cnt += 1
		m = min(m, cnt)
		if m == 1 or m == 2 or m == 0:
			print(0)
			exit()
if m == 3 or m == 4:
	print(1)
if m >= 5:
	print(2)


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))


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((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)


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))