Absent-minded Masha got set of n cubes for her birthday.

At each of 6 faces of each cube, there is exactly one digit from 0 to 9. Masha became interested what is the largest natural x such she can make using her new cubes all integers from 1 to x.

To make a number Masha can rotate her cubes and put them in a row. After that, she looks at upper faces of cubes from left to right and reads the number.

The number can't contain leading zeros. It's not required to use all cubes to build a number.

Pay attention: Masha can't make digit 6 from digit 9 and vice-versa using cube rotations.


-----Input-----

In first line integer n is given (1 ≤ n ≤ 3) — the number of cubes, Masha got for her birthday.

Each of next n lines contains 6 integers a_{i}_{j} (0 ≤ a_{i}_{j} ≤ 9) — number on j-th face of i-th cube.


-----Output-----

Print single integer — maximum number x such Masha can make any integers from 1 to x using her cubes or 0 if Masha can't make even 1.


-----Examples-----
Input
3
0 1 2 3 4 5
6 7 8 9 0 1
2 3 4 5 6 7

Output
87
Input
3
0 1 3 5 6 8
1 2 4 5 7 8
2 3 4 6 7 9

Output
98


-----Note-----

In the first test case, Masha can build all numbers from 1 to 87, but she can't make 88 because there are no two cubes with digit 8.

Difficulty: EASY

Solutions:
cubes = int(input())
exists = []
for _ in range(cubes):
	exists.append([False] * 10)
for i in range(cubes):
	for s in input().split():
		side = int(s)
		exists[i][side] = True
p = []
from itertools import permutations
for c in range(cubes):
	p.append(permutations([x for x in range(cubes)], c + 1))
perms = []
for pe in p:
	perms.append([])
	for i in pe:
		perms[-1].append(i)
max = 0
for i in range(1, 999):
	number = i
	digits = []
	while number > 0:
		digits.append(number % 10)
		number //= 10
	found = False
	for p in perms[len(digits) - 1]:
		all_digits = True
		for d in range(len(digits)):
			if not exists[p[d]][digits[d]]:
				all_digits = False
				break
		if all_digits:
			found = True
			break
	if found:
		max = i
	else:
		break
print(max)


import itertools

def possible(cubes, n):
	s = str(n)
	if len(cubes) < len(s):
		return False
	for p in itertools.permutations(range(len(cubes))):
		ok = True
		for i in range(len(s)):
			if int(s[i]) not in cubes[p[i]]:
				ok = False
		if ok:
			return True
	return False
n = int(input())
cubes = []
for i in range(n):
	cubes.append(list(map(int, input().split())))
for i in range(1, 1001):
	if not possible(cubes, i):
		print(i - 1)
		break


n = int(input())
a = [None] * n
for i in range(n):
	a[i] = list(map(int, input().split()))
if n == 1:
	for i in range(1, 8):
		if i not in a[0]:
			print(i - 1)
			exit()
	else:
		print(0)
		exit()
elif n == 2:
	for i in range(1, 100):
		if i < 10:
			if i not in a[0] and i not in a[1]:
				print(i - 1)
				exit()
		else:
			(first, last) = map(int, str(i))
			if first in a[0] and last in a[1] or (first in a[1] and last in a[0]):
				continue
			else:
				print(i - 1)
				exit()
	else:
		print(0)
		exit()
else:
	for i in range(1, 100):
		if i < 10:
			if i not in a[0] and i not in a[1] and (i not in a[2]):
				print(i - 1)
				exit()
		else:
			(first, last) = map(int, str(i))
			if first in a[0] and last in a[1] or (first in a[1] and last in a[0]) or (first in a[1] and last in a[2]) or (first in a[2] and last in a[1]) or (first in a[2] and last in a[0]) or (first in a[0] and last in a[2]):
				continue
			else:
				print(i - 1)
				exit()
	else:
		print(0)


q = int(input())
l = [list(map(int, input().split())) for _ in range(q)]
k = []
if q == 3:
	for j in l[0]:
		for n in l[1]:
			for h in l[2]:
				k.append(h)
				k.append(n)
				k.append(j)
				k.append(int(str(h) + str(n)))
				k.append(int(str(n) + str(h)))
				k.append(int(str(j) + str(h)))
				k.append(int(str(h) + str(j)))
				k.append(int(str(j) + str(n)))
				k.append(int(str(n) + str(j)))
elif q == 2:
	for j in l[0]:
		for n in l[1]:
			k.append(n)
			k.append(j)
			k.append(int(str(j) + str(n)))
			k.append(int(str(n) + str(j)))
else:
	for j in l[0]:
		k.append(j)
for n in range(1, 100):
	if n not in k:
		print(n - 1)
		quit()


import itertools
n = int(input())
cubes = []
possible = [False] * 999
for i in range(n):
	cubes.append(list(map(int, input().split())))
for vals1 in itertools.permutations(list(range(n))):
	cur_cubes = []
	for val in vals1:
		cur_cubes.append(cubes[val])
	for vals in itertools.product(*cur_cubes):
		for x in range(len(vals) + 1):
			for chosen_vals in itertools.combinations(vals, x):
				s = ''.join(map(str, chosen_vals))
				if s:
					possible[int(s) - 1] = True
print(possible.index(False))


n = int(input())
c = []
for i in range(n):
	c.append([int(item) for item in input().split()])
cb = [[0] * 10 for i in range(6)]
for i in range(n):
	for j in range(6):
		cb[i][c[i][j]] = 1

def verify(x, y, z, cb):
	if x == 0:
		if y == 0:
			return cb[0][z] or cb[1][z] or cb[2][z]
		return cb[0][y] and cb[1][z] or (cb[1][y] and cb[0][z]) or (cb[0][y] and cb[2][z]) or (cb[2][y] and cb[0][z]) or (cb[1][y] and cb[2][z]) or (cb[2][y] and cb[1][z])
	return cb[0][x] and cb[1][y] and cb[2][z] or (cb[1][x] and cb[0][y] and cb[2][z]) or (cb[0][x] and cb[2][y] and cb[1][z]) or (cb[2][x] and cb[0][y] and cb[1][z]) or (cb[1][x] and cb[2][y] and cb[0][z]) or (cb[2][x] and cb[1][y] and cb[0][z])
for i in range(1, 1000):
	(x, y, z) = (i // 100, i // 10 % 10, i % 10)
	if not verify(x, y, z, cb):
		print(i - 1)
		break


n = int(input())
if n == 1:
	a = list(map(int, input().split()))
	l = ['False'] * 10
	for i in a:
		l[i] = 'True'
	for i in range(len(l)):
		if l[0] == 'False' and i == 0:
			c = 1
		elif l[i] != 'True':
			print(i - 1)
			break
if n == 2:
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	l = ['False'] * 100
	for i in a:
		l[i] = 'True'
		for j in b:
			l[j] = 'True'
			l[i * 10 + j] = 'True'
			l[j * 10 + i] = 'True'
	for i in range(len(l)):
		if l[0] == 'False' and i == 0:
			pass
		elif l[i] != 'True':
			print(i - 1)
			break
if n == 3:
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = list(map(int, input().split()))
	l = ['False'] * 1000
	for i in a:
		l[i] = 'True'
		for j in b:
			l[j] = 'True'
			l[i * 10 + j] = 'True'
			l[j * 10 + i] = 'True'
			for k in c:
				l[k] = 'True'
				l[i * 100 + j * 10 + k] = 'True'
				l[i * 100 + k * 10 + j] = 'True'
				l[j * 100 + i * 10 + k] = 'True'
				l[j * 100 + k * 10 + i] = 'True'
				l[k * 100 + j * 10 + i] = 'True'
				l[k * 100 + i * 10 + j] = 'True'
				l[j * 10 + k] = 'True'
				l[k * 10 + j] = 'True'
				l[k * 10 + i] = 'True'
				l[i * 10 + k] = 'True'
	for i in range(len(l)):
		if l[i] == 'False' and i == 0:
			pass
		elif l[i] != 'True':
			print(i - 1)
			break


n = int(input())
cubes = [list(map(int, input().split())) for _ in range(n)] + [[], []]
for i in range(1, 1000):
	for (a, b, c) in [(1, 2, 0), (1, 0, 2), (2, 1, 0), (2, 0, 1), (0, 1, 2), (0, 2, 1)]:
		if len(str(i)) == 1:
			if i in cubes[a]:
				break
		elif len(str(i)) == 2:
			if int(str(i)[0]) in cubes[a] and int(str(i)[1]) in cubes[b]:
				break
		elif int(str(i)[0]) in cubes[a] and int(str(i)[1]) in cubes[b] and (int(str(i)[2]) in cubes[c]):
			break
	else:
		print(max(i - 1, 0))
		exit()


def gen(a, b):
	ans = []
	for i in a:
		for j in b:
			ans.append(i * 10 + j)
			ans.append(j * 10 + i)
	return ans
n = int(input())
(a, p) = ([], [])
for i in range(n):
	a.append(list(map(int, input().split())))
if n == 1:
	p.extend(a[0])
if n == 2:
	p.extend(a[0])
	p.extend(a[1])
	p.extend(gen(a[0], a[1]))
if n == 3:
	p.extend(a[0])
	p.extend(a[1])
	p.extend(a[2])
	p.extend(gen(a[0], a[2]))
	p.extend(gen(a[0], a[1]))
	p.extend(gen(a[1], a[2]))
	for i in a[0]:
		for j in a[1]:
			for k in a[2]:
				p.append(i * 100 + j * 10 + k)
				p.append(i * 100 + k * 10 + j)
				p.append(j * 100 + i * 10 + k)
				p.append(j * 100 + k * 10 + i)
				p.append(k * 100 + j * 10 + i)
				p.append(k * 100 + i * 10 + j)
pl = {i: 1 for i in p}
for i in range(1, 1001):
	if not i in pl.keys():
		print(i - 1)
		break


from itertools import permutations as perms
read = lambda : tuple(map(int, input().split()))
n = read()[0]
cbs = []
for i in range(n):
	cbs += [read()]
for i in range(1, 10000):
	ds = str(i)
	ch = False
	for p in perms(cbs):
		ii = []
		for k in range(len(ds)):
			for ci in range(n):
				if int(ds[k]) in p[ci] and (not ci in ii):
					ii += [ci]
					break
		if len(ii) == len(ds):
			ch = True
			break
	if not ch:
		print(i - 1)
		break


cn = int(input())
c = list(range(cn))
for i in range(cn):
	c[i] = list(map(lambda x: int(x), input().split(' ')))

def ln(i, j):
	s = 0
	(inn, jnn) = (False, False)
	for m in range(cn):
		if i in c[m] or j in c[m]:
			inn |= i in c[m]
			jnn |= j in c[m]
			s += 1
	if i > 0:
		return s > 1 and inn and jnn
	else:
		return s > 0 and jnn

def prout(i, j):
	if i == 0:
		print(str(max(0, j - 1)))
	elif j == 0:
		if i == 1:
			print(9)
		else:
			print(str(i - 1) + str(9))
	else:
		print(str(i) + str(j - 1))
	exit()
for i in range(10):
	for j in range(10):
		if i == j == 0:
			continue
		if not ln(i, j):
			prout(i, j)


num_cubes = int(input())
all_values = list()
cubes = list()
for i in range(num_cubes):
	numbers = input().split(' ')
	cubes.append(numbers)
	all_values.extend(map(int, numbers))
c1 = cubes[0]
for c in c1:
	for cube in cubes:
		if c1 == cube:
			pass
		else:
			for cc in cube:
				all_values.append(int(c + cc))
				all_values.append(int(cc + c))
if len(cubes) >= 2:
	c2 = cubes[1]
	for c in c2:
		for cube in cubes:
			if c1 == cube or c2 == cube:
				pass
			else:
				for cc in cube:
					all_values.append(int(c + cc))
					all_values.append(int(cc + c))
all_values = list(set(all_values))
all_values.sort()
index = 1
while True:
	if index in all_values:
		index += 1
	else:
		print(index - 1)
		break


n = int(input())
a = [x for x in input().split()]
b = []
c = []
if n == 3:
	b = [x for x in input().split()]
	c = [x for x in input().split()]
elif n == 2:
	b = [x for x in input().split()]
	c = []
ans = set()
for x in a + b + c:
	if x != '0':
		ans.add(int(x))
for x in a:
	if x != '0':
		for y in b:
			ans.add(int(x + y))
		for z in c:
			ans.add(int(x + z))
for x in b:
	if x != '0':
		for y in a:
			ans.add(int(x + y))
		for z in c:
			ans.add(int(x + z))
for x in c:
	if x != '0':
		for y in a:
			ans.add(int(x + y))
		for z in b:
			ans.add(int(x + z))
ans = sorted(ans)
for i in range(1, len(ans)):
	if ans[i - 1] != i:
		print(i - 1)
		break
else:
	print(ans[len(ans) - 1])


from itertools import permutations
n = int(input())
a = []
for i in range(n):
	a.append(list(input().split()))
pa = list(permutations(a))
for x in range(1, 1000):
	ds = str(x)
	for a in pa:
		for (d, c) in zip(ds, a):
			if d not in c:
				break
		else:
			break
	else:
		break
print(x - 1)


from itertools import product
from itertools import permutations
n = int(input())
s = []
for i in range(n):
	s.append(list(input().split()))
ans = []
for x in product(*s):
	for z in range(n):
		for y in list(permutations(x, z + 1)):
			ans.append(int(''.join(y)))
ans.append(0)
a = list(set(ans))
a.sort()
last = 0
for i in range(1, len(a)):
	c = a[i]
	if last == c - 1:
		last = c
	else:
		break
print(last)


import sys
import math
import bisect

def solve(A):
	n = len(A)
	s = set()
	if n >= 1:
		for i in range(n):
			for a in A[i]:
				s.add(a)
	if n >= 2:
		for i in range(n):
			for j in range(n):
				if i != j:
					for a in A[i]:
						for b in A[j]:
							s.add(a * 10 + b)
	if n == 3:
		for i in range(n):
			for j in range(n):
				for k in range(n):
					if i != j and j != k and (k != i):
						for a in A[i]:
							for b in A[j]:
								for c in A[k]:
									s.add(a * 100 + b * 10 + c)
	for i in range(1, 10 ** 18):
		if i not in s:
			return i - 1
	return -1

def main():
	n = int(input())
	A = []
	for i in range(n):
		A.append(list(map(int, input().split())))
	ans = solve(A)
	print(ans)
main()


c = [0 for i in range(1000)]
n = int(input())
cc = []
for i in range(n):
	a = list(map(int, input().strip().split(' ')))
	for j in a:
		c[j] = 1
	cc.append(a)
if n == 1:
	for i in range(1, 1000):
		if c[i] == 0:
			break
	print(i - 1)
if n == 2:
	a = cc[0]
	b = cc[1]
	for i in a:
		for j in b:
			c[i * 10 + j] = 1
			c[j * 10 + i] = 1
	for i in range(1, 1000):
		if c[i] == 0:
			break
	print(i - 1)
if n == 3:
	a = cc[0]
	b = cc[1]
	d = cc[2]
	for i in a:
		for j in b:
			c[i * 10 + j] = 1
			c[j * 10 + i] = 1
	for i in a:
		for j in d:
			c[i * 10 + j] = 1
			c[j * 10 + i] = 1
	for i in d:
		for j in b:
			c[i * 10 + j] = 1
			c[j * 10 + i] = 1
	for i in a:
		for j in b:
			for k in d:
				c[i * 100 + j * 10 + k] = 1
				c[i * 100 + k * 10 + j] = 1
				c[j * 100 + i * 10 + k] = 1
				c[j * 100 + i + k * 10] = 1
				c[k * 100 + i * 10 + j] = 1
				c[k * 100 + j * 10 + i] = 1
	for i in range(1, 1000):
		if c[i] == 0:
			break
	print(i - 1)


n = int(input())
cubes = [[int(elem) for elem in input().strip().split(' ')] for i in range(n)]

def f(cubes):
	dic = {}
	pos = {}
	for i in range(n):
		for (j, elem) in enumerate(cubes[i]):
			if elem in dic:
				dic[elem] += 1
				pos[elem].add(i)
			else:
				dic[elem] = 1
				pos[elem] = set((i,))
	for i in range(1, 10):
		if not i in dic:
			return i - 1
	if not 0 in dic:
		return 9
	for i in range(1, 10):
		for j in range(10):
			if len(pos[i].union(pos[j])) == 1:
				return 10 * i + j - 1
print(f(cubes))


n = int(input())
L = []
for i in range(n):
	L.append(list(map(int, input().split())))
for i in range(1, 100):
	t = str(i)
	b = False
	if len(t) == 1:
		for j in range(len(L)):
			if i in L[j]:
				b = True
				break
		if b == False:
			print(i - 1)
			break
	else:
		u = i % 10
		d = i // 10
		pos = []
		for j in range(len(L)):
			if u in L[j]:
				pos.append(j)
		if len(pos) == 0:
			print(i - 1)
			break
		b = False
		for o in pos:
			for k in range(len(L)):
				if k != o:
					if d in L[k]:
						b = True
						break
			if b:
				break
		if not b:
			print(i - 1)
			break


n = int(input())
cubes = []
for i in range(n):
	cubes.append(list(map(int, input().split())))
taken = []
for i in range(10000):
	taken.append(0)
res = 0
for cube in cubes:
	for face in cube:
		taken[face] += 1
for cube1 in cubes:
	for cube2 in cubes:
		if cube1 != cube2:
			for face1 in cube1:
				for face2 in cube2:
					tmp = str(face1) + str(face2)
					taken[int(tmp)] += 1
for cube1 in cubes:
	for cube2 in cubes:
		for cube3 in cubes:
			if cube1 != cube2 and cube1 != cube3 and (cube2 != cube3):
				for face1 in cube1:
					for face2 in cube2:
						for face3 in cube3:
							tmp = str(face1) + str(face2) + str(face3)
							taken[int(tmp)] += 1
iterate = 0
for i in taken:
	if i == 0 and iterate > 0:
		break
	res = iterate
	iterate += 1
print(res)


from collections import Counter
n = int(input())
cubes = []
for i in range(n):
	cubes.append(list(map(int, input().split())))
cCombos = Counter()
for i in range(100):
	cCombos[i] = 0
for cube in cubes:
	for i in cube:
		cCombos[i] += 1
		for oCube in cubes:
			if oCube != cube:
				for j in oCube:
					newNum = str(i) + str(j)
					cCombos[int(newNum)] += 1
biggestNum = 1
while cCombos[biggestNum] != 0 and biggestNum < 99:
	biggestNum += 1
biggestNum -= 1
if biggestNum < 0:
	biggestNum = 0
print(biggestNum)


n = int(input())
nums = {}
for i in range(n):
	dado = input().split(' ')
	for d in dado:
		if d not in nums:
			nums[d] = []
		nums[d].append(i + 1)
i = 1
while True:
	aux = str(i)
	dados_usados = []
	falta_numero = False
	for num in aux:
		if num in nums:
			for n in nums[num]:
				if n not in dados_usados:
					dados_usados.append(n)
		else:
			falta_numero = True
			break
	if falta_numero:
		break
	if len(aux) == 1 and len(dados_usados) <= 0:
		break
	elif len(aux) == 2 and len(dados_usados) <= 1:
		break
	elif len(aux) == 3 and len(dados_usados) <= 2:
		break
	i += 1
print(i - 1)


def cubic_nums(cubes):
	if not cubes:
		yield ''
		return
	cube = cubes.pop()
	for tail in cubic_nums(cubes):
		yield tail
		for d in cube:
			for i in range(len(tail) + 1):
				yield (tail[:i] + d + tail[i:])
n = int(input())
cubes = []
for i in range(n):
	cubes.append(input().strip().split())
all_nums = set()
for cubic_num in cubic_nums(cubes):
	if cubic_num != '':
		all_nums.add(int(cubic_num))
all_nums = [x for x in sorted(all_nums) if x != 0]
x = 0
while x < len(all_nums) and x + 1 == all_nums[x]:
	x += 1
print(x)


from itertools import permutations
n = int(input())
a = []
for i in range(n):
	x = list(map(int, input().split()))
	a.append(x)
p = list(permutations([i for i in range(n)]))
L = []

def build(i, z, val):
	if val != 0:
		L.append(val)
	if i == n:
		return
	for j in range(6):
		build(i + 1, z, val * 10 + a[z[i]][j])
for z in p:
	build(0, z, 0)
if len(L) == 0:
	print(0)
L = list(sorted(set(L)))
if L[0] != 1:
	print(0)
	exit(0)
cur = 0
for i in range(1, len(L)):
	if L[i] != L[i - 1] + 1:
		cur = i - 1
		break
	cur = i
print(L[cur])


n = int(input())
a = list(map(int, input().split(' ')))
p = True
if n == 3:
	b = list(map(int, input().split(' ')))
	c = list(map(int, input().split(' ')))
	for i in range(1, 10):
		if i not in a and i not in b and (i not in c):
			p = False
			print(i - 1)
			break
	if p:
		for i in range(10, 100):
			x = i % 10
			y = i // 10
			if x in a and (y in b or y in c):
				continue
			elif x in b and (y in a or y in c):
				continue
			elif x in c and (y in a or y in b):
				continue
			else:
				print(i - 1)
				break
elif n == 2:
	b = list(map(int, input().split(' ')))
	for i in range(1, 10):
		if i not in a and i not in b:
			p = False
			print(i - 1)
			break
	if p:
		for i in range(10, 100):
			x = i % 10
			y = i // 10
			if x in a and y in b:
				continue
			elif x in b and y in a:
				continue
			else:
				print(i - 1)
				break
else:
	for i in range(1, 7):
		if i not in a:
			print(i - 1)
			break


from itertools import chain, combinations, permutations, product
from functools import reduce
powerset = lambda xs: chain.from_iterable((combinations(xs, i) for i in range(len(xs) + 1)))
undigits = lambda xs: reduce(lambda a, b: 10 * a + b, xs, 0)
found = set()
for cs in powerset([[int(x) for x in input().split()] for i in range(int(input()))]):
	for ps in permutations(cs):
		found |= set(map(undigits, product(*ps)))
for i in sorted(found):
	if i + 1 not in found:
		print(i)
		break
else:
	print(0)


def main():
	N = int(input())
	C = tuple((tuple(input().split()) for _ in [0] * N))
	n = int('9' * N)
	cube = set()
	for i in range(1, n + 1):
		j = list(str(i))
		for k in j:
			flag = False
			for (l, c) in enumerate(C):
				if k in c:
					cube.add(l)
					flag = True
		if flag and len(str(i)) <= len(cube):
			cube.clear()
			flag = False
		else:
			break
	print(i - 1)
main()


n = int(input())
cubics = [[0 for _ in range(10)] for __ in range(n)]
for i in range(n):
	for v in [int(k) for k in input().split(' ') if k]:
		cubics[i][v] = 1
allowed = [1 for _ in range(n)]

def build(v, i=0):
	if i >= len(v):
		return 1
	for j in range(n):
		if allowed[j] and cubics[j][v[i]]:
			allowed[j] = 0
			if build(v, i + 1):
				allowed[j] = 1
				return 1
			allowed[j] = 1
	return 0
for i in range(1, 10 ** n):
	if not build([int(k) for k in str(i)]):
		print(i - 1)
		exit()
print(10 ** n - 1)


freq = []
n = int(input())

def getFreq(f):
	h = {}
	for i in range(10):
		h[str(i)] = 0
	for i in list(map(str, f.split())):
		h[i] += 1
	return h
for i in range(n):
	freq.append(getFreq(str(input())))

def check(num, fr):
	nums = str(num)
	numsarr = []
	n = len(nums)
	if n == 2:
		numsarr.append(nums)
		numsarr.append(nums[1] + nums[0])
	elif n == 3:
		numsarr.append(nums)
		numsarr.append(nums[2] + nums[1] + nums[0])
		numsarr.append(nums[0] + nums[2] + nums[1])
		numsarr.append(nums[2] + nums[0] + nums[1])
		numsarr.append(nums[1] + nums[0] + nums[2])
		numsarr.append(nums[1] + nums[2] + nums[0])
	elif n == 1:
		numsarr.append(nums)
	for nn in numsarr:
		n = len(nums)
		used = []
		for s in list(nn):
			for j in range(len(fr)):
				if j not in used:
					if fr[j][s] > 0:
						used.append(j)
						n -= 1
						break
		if n == 0:
			return True
	return False
m = 0
for i in range(1, 1000):
	if not check(i, freq):
		break
	else:
		m = i
print(m)


import math
import collections
import bisect
import heapq
import time
import random
import itertools
import sys
N = int(input())
A = []
for i in range(N):
	A.append([int(x) for x in input().split()])

def dfs(A, index, p):
	if index >= len(A):
		v = 0
		for u in p:
			v *= 10
			v += u
		return {v}
	ans = set()
	for v in A[index]:
		ans |= dfs(A, index + 1, p + [v])
	ans |= dfs(A, index + 1, p)
	return ans
allNums = set()
for a in itertools.permutations(A, len(A)):
	allNums |= dfs(a, 0, [])
ans = 0
for i in range(1, max(allNums) + 1):
	if i not in allNums:
		break
	ans = i
print(ans)


from itertools import permutations
n = int(input())
lst = list()
for i in range(n):
	lst.append(list(input().split()))
per = list(permutations(lst))
k = 0
for x in range(1, 1000):
	l = str(x)
	for i in per:
		for (d, c) in zip(l, i):
			if d not in c:
				break
		else:
			break
	else:
		break
print(x - 1)


n = int(input())
if n == 1:
	count = 0
	l = list(map(int, input().split()))
	for i in range(1, 10):
		if i in l:
			count += 1
		else:
			break
	print(count)
elif n == 2:
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	l4 = []
	count = 0
	for i in range(1, 100):
		while i != 0:
			l4.append(i % 10)
			i = i // 10
		if len(l4) == 1:
			if l4[0] in l1 or l4[0] in l2:
				count += 1
			else:
				break
		elif len(l4) == 2:
			if l4[0] in l1 and l4[1] in l2:
				count += 1
			elif l4[0] in l2 and l4[1] in l1:
				count += 1
			else:
				break
		l4 = []
	print(count)
elif n == 3:
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	l3 = list(map(int, input().split()))
	l4 = []
	count = 0
	for i in range(1, 1000):
		while i != 0:
			l4.append(i % 10)
			i = i // 10
		l4.reverse()
		if len(l4) == 1:
			if l4[0] in l1 or l4[0] in l2 or l4[0] in l3:
				count += 1
			else:
				break
		if len(l4) == 2:
			if l4[0] in l1 and l4[1] in l2:
				count += 1
			elif l4[0] in l1 and l4[1] in l3:
				count += 1
			elif l4[0] in l2 and l4[1] in l3:
				count += 1
			elif l4[0] in l2 and l4[1] in l1:
				count += 1
			elif l4[0] in l3 and l4[1] in l1:
				count += 1
			elif l4[0] in l3 and l4[1] in l2:
				count += 1
			else:
				break
		if len(l4) == 3:
			if l4[0] in l1 and l4[1] in l2 and (l4[2] in l3):
				count += 1
			else:
				break
		l4 = []
	print(count)


from itertools import permutations

def digits(i):
	D = []
	while i:
		D.append(i % 10)
		i //= 10
	return D

def buildable(C, i):
	D = digits(i)
	for P in permutations(C, r=len(D)):
		if all((D[i] in P[i] for i in range(len(D)))):
			return True
	return False

def main():
	n = int(input())
	C = [set(map(int, input().split())) for _ in range(n)]
	i = 1
	while buildable(C, i):
		i += 1
	print(i - 1)
main()


n = int(input())
cb = []
for i in range(n):
	cb.append(input().split())
cb = cb + ['*'] * (3 - len(cb))
for i in range(1, 1000):
	s = str(i)
	s = list(s)
	if len(s) == 1:
		if not s[0] in cb[0] and (not s[0] in cb[1]) and (not s[0] in cb[2]):
			print(i - 1)
			break
	elif len(s) == 2:
		if not (s[0] in cb[0] and s[1] in cb[1]):
			if not (s[0] in cb[1] and s[1] in cb[0]):
				if not (s[0] in cb[0] and s[1] in cb[2]):
					if not (s[0] in cb[2] and s[1] in cb[0]):
						if not (s[0] in cb[1] and s[1] in cb[2]):
							if not (s[0] in cb[2] and s[1] in cb[1]):
								print(i - 1)
								break
	elif len(s) == 3:
		if not (s[0] in cb[0] and s[1] in cb[1] and (s[2] in cb[2])):
			if not (s[0] in cb[0] and s[1] in cb[2] and (s[2] in cb[1])):
				if not (s[0] in cb[1] and s[1] in cb[0] and (s[2] in cb[2])):
					if not (s[0] in cb[1] and s[1] in cb[2] and (s[2] in cb[0])):
						if not (s[0] in cb[2] and s[1] in cb[0] and (s[2] in cb[1])):
							if not (s[0] in cb[2] and s[1] in cb[1] and (s[2] in cb[0])):
								print(i - 1)
								break


def f(s, i, t):
	if i >= len(s):
		return True
	if len(d[int(s[i])]) == 0:
		return False
	flag = False
	for j in range(len(d[int(s[i])])):
		if d[int(s[i])][j] not in t:
			t.add(d[int(s[i])][j])
			if f(s, i + 1, t):
				flag = True
			t.remove(d[int(s[i])][j])
	return flag
n = int(input())
d = {}
for i in range(10):
	d[i] = []
for i in range(n):
	l = list(map(int, input().split()))
	for j in range(6):
		d[l[j]].append(i)
ans = 0
flag = True
while flag:
	ans += 1
	s = str(ans)
	flag = f(s, 0, set())
	if not flag:
		ans -= 1
print(ans)


n = int(input())
cubes = []
for _ in range(n):
	cubes.append([int(i) for i in input().split()])

def permutation(result):
	if len(result) == n:
		yield result
	else:
		for num in range(n):
			if str(num) not in result:
				yield from permutation(result + str(num))
num = 1
permutations = []
for perm in permutation(''):
	permutations.append(perm)
while True:
	flag = 0
	for perm in permutations:
		counter = 0
		order_num = 0
		for ind in perm:
			ind = int(ind)
			if int(str(num)[order_num]) in cubes[ind]:
				counter += 1
				order_num += 1
			if counter == len(str(num)):
				flag = 1
				break
	if flag == 0:
		print(num - 1)
		break
	num += 1


n = int(input().strip())
sets = [set([i for i in input().strip().split()]) for j in range(n)]

def get_all_perm(kek):
	if len(kek) == 1:
		return [kek]
	ans = []
	for i in range(len(kek)):
		p = [i for i in kek]
		p.pop(i)
		for perm in get_all_perm(p):
			ans.append([kek[i]] + perm)
	return ans
answer = 0
while answer < 10 ** n:
	answer += 1
	g = list(str(answer))
	for perm in get_all_perm(sets):
		if all([g[i] in perm[i] for i in range(len(g))]):
			break
	else:
		break
print(answer - 1)


n = int(input())
dice = []
for _ in range(n):
	num = list(map(int, input().split()))
	dice.append(num)
curr = 1
flag = False
while not flag:
	digits = list(map(int, list(str(curr))))
	if len(digits) > n:
		flag = True
	elif len(digits) == 1:
		if any((digits[0] in dice[i] for i in range(n))):
			curr += 1
		else:
			flag = True
	elif len(digits) == 2:
		if any((digits[0] in dice[i] and any((digits[1] in dice[j] for j in [x for x in range(n) if x != i])) for i in range(n))):
			curr += 1
		else:
			flag = True
	elif len(digits) == 3:
		if any((digits[0] in dice[i] and any((digits[1] in dice[j] and any((digits[2] in dice[k] for k in [x for x in range(n) if x != i and x != j])) for j in [x for x in range(n) if x != i])) for i in range(n))):
			curr += 1
		else:
			flag = True
print(curr - 1)


n = int(input())
a = []
a += [list(input())]
if n > 1:
	a += [list(input())]
if n > 2:
	a += [list(input())]
i = 1
while i < 1000:
	s = list(str(i))
	if n == 1:
		if s[0] in a[0]:
			i += 1
			continue
	if n == 2:
		if len(s) == 1 and (s[0] in a[0] or s[0] in a[1]):
			i += 1
			continue
		if len(s) == 2 and (s[0] in a[0] and s[1] in a[1] or (s[0] in a[1] and s[1] in a[0])):
			i += 1
			continue
	if n == 3:
		if len(s) == 1 and (s[0] in a[0] or s[0] in a[1] or s[0] in a[2]):
			i += 1
			continue
		if len(s) == 2 and (s[0] in a[0] and s[1] in a[1] or (s[0] in a[0] and s[1] in a[2]) or (s[0] in a[1] and s[1] in a[0]) or (s[0] in a[1] and s[1] in a[2]) or (s[0] in a[2] and s[1] in a[0]) or (s[0] in a[2] and s[1] in a[1])):
			i += 1
			continue
		if len(s) == 3 and (s[0] in a[0] and s[1] in a[1] and (s[2] in a[2]) or (s[0] in a[0] and s[1] in a[2] and (s[2] in a[1])) or (s[0] in a[1] and s[1] in a[0] and (s[2] in a[2])) or (s[0] in a[1] and s[1] in a[2] and (s[2] in a[0])) or (s[0] in a[2] and s[1] in a[0] and (s[2] in a[1])) or (s[0] in a[2] and s[1] in a[1] and (s[2] in a[0]))):
			i += 1
			continue
	print(i - 1)
	break


n = int(input())
x = []

def search(s, t):
	if len(s) == 0:
		return True
	x = int(s[0])
	for i in t:
		if x in i:
			if search(s[1:], [n for n in t if n != i]):
				return True
	return False
for i in range(n):
	s = input()
	a = []
	for i in s.split(' '):
		a.append(int(i))
	x.append(tuple(a))
m = 0
for i in range(10000):
	ss = i + 1
	s = str(ss)
	if search(s, x):
		m = ss
	else:
		break
print(m)


n = int(input())
a = []
for i in range(n):
	a.append(list(map(int, input().split())))
variants2 = [12, 21]
variants3 = [123, 132, 213, 231, 312, 321]
chisla = set()
if n == 1:
	for i in a[0]:
		chisla.add(i)
elif n == 2:
	for i in variants2:
		for ch1 in a[i // 10 - 1]:
			for ch2 in a[i % 10 - 1]:
				chisla.add(ch1 * 10 + ch2)
				chisla.add(ch1)
				chisla.add(ch2)
elif n == 3:
	for i in variants3:
		for ch1 in a[i // 100 - 1]:
			for ch2 in a[i // 10 % 10 - 1]:
				for ch3 in a[i % 10 - 1]:
					chisla.add(ch1 * 100 + ch2 * 10 + ch3)
					chisla.add(ch1 * 10 + ch2)
					chisla.add(ch1)
for i in range(1, 999):
	if i not in chisla:
		ans = i - 1
		break
print(ans)


t = int(input())
l = [[0] * 10 for i in range(t)]
for i in range(t):
	num = list(map(int, input().split()))
	for x in num:
		l[i][x] += 1
n = 1
b = True
while n < 99 and b:
	a = list(map(int, str(n)))
	if t == 1:
		if len(a) == 1 and l[0][a[0]] != 0:
			n += 1
		else:
			b = False
	elif t == 2:
		if len(a) == 1 and (l[0][a[0]] != 0 or l[1][a[0]] != 0):
			n += 1
		elif len(a) == 2:
			if l[0][a[0]] != 0 and l[1][a[1]] != 0:
				n += 1
			elif l[1][a[0]] != 0 and l[0][a[1]] != 0:
				n += 1
			else:
				b = False
		else:
			b = False
	elif t == 3:
		if len(a) == 1 and (l[0][a[0]] != 0 or l[1][a[0]] != 0 or l[2][a[0]] != 0):
			n += 1
		elif len(a) == 2:
			if l[0][a[0]] != 0 and (l[1][a[1]] != 0 or l[2][a[1]] != 0):
				n += 1
			elif l[1][a[0]] != 0 and (l[0][a[1]] != 0 or l[2][a[1]] != 0):
				n += 1
			elif l[2][a[0]] != 0 and (l[1][a[1]] != 0 or l[0][a[1]] != 0):
				n += 1
			else:
				b = False
		else:
			b = False
print(n - 1)


n = int(input())
a = [[], [], []]
b = []
p = False
for i in range(n):
	t = list(map(int, input().split()))
	for j in range(10):
		a[i].append(0)
	for j in t:
		a[i][j] = 1
for i in range(1, 10):
	t = False
	for j in range(n):
		if a[j][i] == 1:
			t = True
	if t == False:
		if not p:
			print(str(i - 1))
		p = True
		break
if p == False:
	for i in range(10, 100):
		i1 = int(i / 10)
		i2 = i % 10
		if n == 1:
			if not p:
				print('9')
			p = True
			break
		elif n == 2:
			if not (a[0][i1] and a[1][i2] or (a[0][i2] and a[1][i1])):
				print(str(i - 1))
				p = True
				break
		elif not (a[0][i1] and (a[1][i2] or a[2][i2]) or (a[1][i1] and (a[0][i2] or a[2][i2])) or (a[2][i1] and (a[1][i2] or a[0][i2]))):
			if not p:
				print(str(i - 1))
			p = True
			break
if p == False:
	for i in range(100, 1000):
		i1 = int(i / 100)
		i2 = int(i % 10 / 10)
		i3 = i % 100
		if n == 2:
			if not p:
				print('99')
			p = True
			break
		elif not (a[0][i1] and a[1][i2] and a[2][i3] or (a[0][i1] and a[2][i2] and a[1][i3]) or (a[1][i1] and a[0][i2] and a[2][i3]) or (a[1][i1] and a[2][i2] and a[0][i3]) or (a[2][i1] and a[1][i2] and a[0][i3]) or (a[2][i1] and a[0][i2] and a[1][i3])):
			if not p:
				print(str(i - 1))
			break


n = int(input())
cubes = []
for _ in range(n):
	cubes.append(list(map(int, input().split())))
for i in range(1, 10 ** (n + 1)):
	digits = list(map(int, str(i)))
	use = []
	for cube in cubes:
		use.append([])
		for (rg, digit) in zip(range(10 ** (n + 1)), digits):
			if digit in cube:
				use[-1].append(rg)
	use.sort(key=lambda x: (len(x), sorted(x)))
	for rg in range(len(digits)):
		found = False
		for ui in range(len(use)):
			if rg in use[ui]:
				del use[ui]
				found = True
				break
		if not found:
			print(i - 1)
			exit(0)


n = int(input())
cubes = []
for i in range(n):
	cubes.append(list(map(int, input().split())))

def isCan(k):
	if k < 10:
		for i in range(n):
			if k in cubes[i]:
				return True
		return False
	elif k < 100:
		first = k // 10
		second = k % 10
		for i in range(n):
			for j in range(n):
				if i != j:
					if first in cubes[i] and second in cubes[j]:
						return True
		return False
	else:
		first = int(str(k)[0])
		second = int(str(k)[0])
		third = int(str(k)[0])
		for i in range(n):
			for j in range(n):
				for k in range(n):
					if i != j and j != k and (i != k):
						if first in cubes[i] and second in cubes[j] and (third in cubes[k]):
							return True
		return False
i = 1
while isCan(i):
	i += 1
if not isCan(1):
	print(0)
else:
	print(i - 1)


from itertools import product as comb
from itertools import permutations as perm
k = int(input())
cubes = [input().split(' ') for i in range(k)]
nums = set()
for n in range(1, k + 1):
	for p in perm(range(k), n):
		for c in comb(range(6), repeat=n):
			nn = ''
			for i in range(n):
				nn += cubes[p[i]][c[i]]
			nums.add(int(nn))
ans = 0
while ans + 1 in nums:
	ans += 1
print(ans)


order = ['012', '021', '102', '120', '201', '210']
cube = ['', '', '']
for _ in range(int(input())):
	cube[_] = input()
for num in range(1, 999):
	num = str(num)
	flag = 0
	for o in range(6):
		i = 0
		for ele in num:
			if ele not in cube[int(order[o][i])]:
				break
			i += 1
		else:
			flag = 1
		if flag == 1:
			break
	if not flag:
		break
print(int(num) - 1)


from itertools import permutations
n = int(input())
l = [[int(x) for x in input().split()] for _ in range(n)]
s = set()

def add(t, cur, lvl):
	for i in range(6):
		print
		cur2 = cur * 10 + l[t[lvl]][i]
		s.add(cur2)
		if lvl < n - 1:
			add(t, cur2, lvl + 1)
for t in permutations(tuple(range(n))):
	add(t, 0, 0)
a = 1
while True:
	if a in s:
		a += 1
	else:
		print(a - 1)
		break


n = int(input())
cubes = []
for i in range(n):
	cubes.append(list(map(int, input().split())))
numbers = set()
if n == 3:
	for i in range(6):
		numbers.add(cubes[0][i])
		numbers.add(cubes[1][i])
		numbers.add(cubes[2][i])
		for j in range(6):
			numbers.add(cubes[0][i] * 10 + cubes[1][j])
			numbers.add(cubes[0][i] * 10 + cubes[2][j])
			numbers.add(cubes[1][i] * 10 + cubes[0][j])
			numbers.add(cubes[1][i] * 10 + cubes[2][j])
			numbers.add(cubes[2][i] * 10 + cubes[0][j])
			numbers.add(cubes[2][i] * 10 + cubes[1][j])
			for k in range(6):
				numbers.add(cubes[0][i] * 100 + cubes[1][j] * 10 + cubes[2][k])
				numbers.add(cubes[0][i] * 100 + cubes[2][j] * 10 + cubes[1][k])
				numbers.add(cubes[1][i] * 100 + cubes[0][j] * 10 + cubes[2][k])
				numbers.add(cubes[1][i] * 100 + cubes[2][j] * 10 + cubes[0][k])
				numbers.add(cubes[2][i] * 100 + cubes[0][j] * 10 + cubes[1][k])
				numbers.add(cubes[2][i] * 100 + cubes[1][j] * 10 + cubes[0][k])
if n == 2:
	for i in range(6):
		numbers.add(cubes[0][i])
		numbers.add(cubes[1][i])
		for j in range(6):
			numbers.add(cubes[0][i] * 10 + cubes[1][j])
			numbers.add(cubes[1][i] * 10 + cubes[0][j])
if n == 1:
	for i in range(6):
		numbers.add(cubes[0][i])
ans = 0
for i in range(1, 999):
	if i not in numbers:
		break
	ans = i
print(ans)


n = int(input())
cubes = list()
S = set()
for i in range(n):
	cubes.append(set(input().split()))
	S |= set(cubes[-1])
c = 0
while True:
	c += 1
	s = str(c)
	if len(s) > n:
		print(c - 1)
		break
	elif len(s) == 1:
		if s not in S:
			print(c - 1)
			break
	elif len(s) == 2:
		if n == 3 and (not (s[0] in cubes[0] and s[1] in cubes[1] or (s[0] in cubes[0] and s[1] in cubes[2]) or (s[0] in cubes[1] and s[1] in cubes[0]) or (s[0] in cubes[1] and s[1] in cubes[2]) or (s[0] in cubes[2] and s[1] in cubes[0]) or (s[0] in cubes[2] and s[1] in cubes[1]))):
			print(c - 1)
			break
		elif n == 2 and (not (s[0] in cubes[0] and s[1] in cubes[1] or (s[0] in cubes[1] and s[1] in cubes[0]))):
			print(c - 1)
			break
	elif len(s) == 3:
		if not (s[0] in cubes[0] and s[1] in cubes[1] and (s[2] in cubes[2]) or (s[0] in cubes[0] and s[1] in cubes[2] and (s[2] in cubes[1])) or (s[0] in cubes[1] and s[1] in cubes[0] and (s[2] in cubes[2])) or (s[0] in cubes[1] and s[1] in cubes[2] and (s[2] in cubes[0])) or (s[0] in cubes[2] and s[1] in cubes[0] and (s[2] in cubes[1])) or (s[0] in cubes[2] and s[1] in cubes[1] and (s[2] in cubes[0]))):
			print(c - 1)
			break


n = int(input())
a = ['', '', '']
for i in range(n):
	l = input()
	a[i] = l.split()
	for j in range(6):
		a[i][j] = int(a[i][j])
x = 1
while x <= 9:
	it = 0
	i = 0
	while i < n:
		j = 0
		while j < 6:
			if a[i][j] == x:
				x = x + 1
				it = 1
				break
			j = j + 1
		if it == 1:
			break
		i = i + 1
	if it == 0:
		break
while 9 < x < 100:
	it = 0
	i = 0
	while i < 6:
		j = 0
		while j < 6:
			if n > 1 and a[0][i] * 10 + a[1][j] == x:
				x = x + 1
				it = 1
				break
			if n > 1 and a[1][i] * 10 + a[0][j] == x:
				x = x + 1
				it = 1
				break
			if n > 2 and a[0][i] * 10 + a[2][j] == x:
				x = x + 1
				it = 1
				break
			if n > 2 and a[2][i] * 10 + a[0][j] == x:
				x = x + 1
				it = 1
				break
			if n > 2 and a[1][i] * 10 + a[2][j] == x:
				x = x + 1
				it = 1
				break
			if n > 2 and a[2][i] * 10 + a[1][j] == x:
				x = x + 1
				it = 1
				break
			j = j + 1
		if it == 1:
			break
		i = i + 1
	if it == 0:
		break
while 99 < x < 1000:
	it = 0
	i = 0
	while i < 6:
		j = 0
		while j < 6:
			k = 0
			while k < 6:
				if n > 2 and a[0][i] * 100 + 10 * a[1][j] + a[2][k] == x:
					x = x + 1
					it = 1
					break
				k = k + 1
			if it == 1:
				break
			j = j + 1
		if it == 1:
			break
		i = i + 1
	if it == 0:
		break
print(x - 1)


n = int(input())
d = 1
e = 1
f = 1
g = 1
h = 1
k = 1
if n == 1:
	a = list(map(str, input().split()))
	for i in range(1, 10):
		j = str(i)
		if j not in a:
			print(i - 1)
			exit(0)
if n == 2:
	a = list(map(str, input().split()))
	b = list(map(str, input().split()))
	for i in range(1, 10):
		j = str(i)
		if j not in a and j not in b:
			print(i - 1)
			exit(0)
	for i in range(10, 37):
		j = str(i)
		if j[0] in a and j[1] in b:
			d = 0
		if j[0] in b and j[1] in a:
			e = 0
		if d == 1 and e == 1:
			print(i - 1)
			exit(0)
		d = 1
		e = 1
if n == 3:
	a = list(map(str, input().split()))
	b = list(map(str, input().split()))
	c = list(map(str, input().split()))
	for i in range(1, 10):
		j = str(i)
		if j not in a and j not in b and (j not in c):
			print(i - 1)
			exit(0)
	for i in range(10, 100):
		j = str(i)
		d = 1
		e = 1
		f = 1
		g = 1
		h = 1
		k = 1
		if j[0] in a and j[1] in b:
			d = 0
		if j[0] in b and j[1] in a:
			e = 0
		if j[0] in b and j[1] in c:
			f = 0
		if j[0] in c and j[1] in b:
			g = 0
		if j[0] in a and j[1] in c:
			h = 0
		if j[0] in c and j[1] in a:
			k = 0
		if d + e + f + g + h + k == 6:
			print(i - 1)
			exit(0)
	for i in range(100, 1000):
		j = str(i)
		d = 1
		e = 1
		f = 1
		g = 1
		h = 1
		k = 1
		if j[0] in a and j[1] in b and (j[2] in c):
			d = 0
		if j[0] in b and j[1] in a and (j[2] in c):
			e = 0
		if j[0] in b and j[1] in c and (j[2] in a):
			f = 0
		if j[0] in c and j[1] in b and (j[2] in a):
			g = 0
		if j[0] in a and j[1] in c and (j[2] in b):
			h = 0
		if j[0] in c and j[1] in a and (j[2] in b):
			k = 0
		if d + e + f + g + h + k == 6:
			print(i - 1)
			exit(0)


n = int(input().strip())
arrs = [[] for i in range(n)]
for _ in range(n):
	arrs[_] = [int(i) for i in input().strip().split(' ')]
h = []
for i in arrs:
	h.append(max(i))
dic = {}
for i in range(n):
	for j in arrs[i]:
		if j in dic:
			dic[j].append(i + 1)
		else:
			dic[j] = [i + 1]
highest = int(''.join([str(i) for i in sorted(h)][::-1]))
answer = 0
stop = False
for i in range(1, highest + 1):
	temp = set()
	lis = list(str(i))
	for j in lis:
		if int(j) not in dic:
			stop = True
		else:
			temp = temp.union(set(dic[int(j)]))
		if stop:
			break
	if len(temp) >= len(str(i)) and (not stop):
		answer = i
	else:
		stop = True
	if stop:
		break
print(answer)


def fun(n, l):
	if len(l) == 1:
		return n in l[0]
	elif len(l) == 2:
		if n < 10:
			return n in l[0] or n in l[1]
		elif n < 100:
			u = n % 10
			h = int(str(n)[0])
			return u in l[0] and h in l[1] or (u in l[1] and h in l[0])
		else:
			return False
	elif n < 10:
		return n in l[0] or n in l[1] or n in l[2]
	elif n < 100:
		u = n % 10
		h = int(str(n)[0])
		return fun(n, [l[0], l[1]]) or fun(n, [l[0], l[2]]) or fun(n, [l[1], l[2]])
l = []
n = int(input())
for i in range(n):
	l.append([int(j) for j in input().split()])
for i in range(1, 100):
	if not fun(i, l):
		break
print(i - 1)


import itertools
n = int(input())
cubes = []
for _ in range(n):
	cubes.append(list(map(int, input().split())))
for i in range(1, 1000):
	s = str(i)
	perms = list(itertools.permutations(cubes))
	hasPerm = False
	for perm in perms:
		good = True
		for n in range(len(s)):
			if int(s[n]) not in perm[n]:
				good = False
		if good:
			hasPerm = True
			break
	if hasPerm == False:
		print(i - 1)
		exit()


def check(s, a, used):
	if len(used) == len(s):
		return True
	n = len(a)
	index = len(used)
	for i in range(n):
		if i not in used and s[index] in a[i]:
			result = check(s, a, used.union(set([i])))
			if result:
				return True
	return False

def valid(s, a):
	if len(s) > len(a):
		return False
	return check(s, a, set())
n = int(input())
a = []
for _ in range(n):
	a.append(list(input().split()))
count = 1
while True:
	if not valid(str(count), a):
		print(count - 1)
		break
	count += 1


def can_form(i, cubes):
	digits = '{}'.format(i)
	for (index, cube) in enumerate(cubes):
		if int(digits[0]) in cube:
			if len(digits) == 1:
				return True
			else:
				rest = cubes.copy()
				del rest[index]
				if can_form(int(digits[1:]), rest):
					return True
	return False
cube_count = int(input())
cubes = []
for i in range(cube_count):
	cubes.append(set(map(int, input().split())))
for i in range(1, 1000):
	if not can_form(i, cubes):
		break
print(i - 1)


import sys
import io, os
input = sys.stdin.buffer.readline
n = int(input())
A = [list(map(int, input().split())) for i in range(n)]
import itertools
s = set()
s.add(0)
if n == 3:
	for p in itertools.permutations(range(3), 3):
		for i in range(6):
			for j in range(6):
				for k in range(6):
					t = A[p[0]][i] * 100 + A[p[1]][j] * 10 + A[p[2]][k]
					s.add(t)
	for i in range(6):
		for j in range(6):
			t = A[0][i] * 10 + A[1][j]
			s.add(t)
			t = A[1][i] * 10 + A[0][j]
			s.add(t)
	for i in range(6):
		for j in range(6):
			t = A[1][i] * 10 + A[2][j]
			s.add(t)
			t = A[2][i] * 10 + A[1][j]
			s.add(t)
	for i in range(6):
		for j in range(6):
			t = A[2][i] * 10 + A[0][j]
			s.add(t)
			t = A[0][i] * 10 + A[2][j]
			s.add(t)
	for i in range(6):
		s.add(A[0][i])
		s.add(A[1][i])
		s.add(A[2][i])
elif n == 2:
	for i in range(6):
		for j in range(6):
			t = A[0][i] * 10 + A[1][j]
			s.add(t)
			t = A[1][i] * 10 + A[0][j]
			s.add(t)
	for i in range(6):
		s.add(A[0][i])
		s.add(A[1][i])
else:
	for i in range(6):
		s.add(A[0][i])
s = list(s)
s.sort()
for i in range(len(s)):
	if s[i] != i:
		print(s[i - 1])
		exit()
else:
	print(s[-1])


def check(k, num):
	if len(num) == k:
		return True
	for i in range(n):
		if i not in vis and int(num[k]) in arr[i]:
			vis[i] = 1
			if check(k + 1, num) == True:
				return True
			del vis[i]
	return False
n = int(input())
arr = []
vis = {}
for x in range(n):
	arr.append(list(map(int, input().split())))
for x in range(10000):
	vis.clear()
	if check(0, str(x + 1)) == False:
		print(x)
		break


n = int(input())
a = []
for i in range(n):
	a.append(list(map(int, input().split())))
if n == 1:
	for i in range(1, 10):
		if i not in a[0]:
			print(i - 1)
			break
if n == 2:
	for i in range(1, 100):
		l = str(i)
		if i < 10:
			if int(l) not in a[0] and int(l) not in a[1]:
				print(i - 1)
				break
		elif i < 100:
			if i % 10 in a[0] and int(i / 10) in a[1] or (i % 10 in a[1] and int(i / 10) in a[0]):
				pass
			else:
				print(i - 1)
				break
if n == 3:
	for i in range(1, 1000):
		l = str(i)
		if i < 10:
			if int(l) not in a[0] and int(l) not in a[1] and (int(l) not in a[2]):
				print(i - 1)
				break
		elif i < 100:
			if i % 10 in a[0] and int(i / 10) in a[1] or (i % 10 in a[1] and int(i / 10) in a[0]) or (i % 10 in a[0] and int(i / 10) in a[2]) or (i % 10 in a[2] and int(i / 10) in a[0]) or (i % 10 in a[1] and int(i / 10) in a[2]) or (i % 10 in a[2] and int(i / 10) in a[1]):
				pass
			else:
				print(i - 1)
				break
		elif i < 1000:
			if int(l[0]) in a[0] and int(l[1]) in a[1] and (int(l[2]) in a[2]):
				pass
			elif int(l[0]) in a[0] and int(l[1]) in a[2] and (int(l[2]) in a[1]):
				pass
			elif int(l[0]) in a[1] and int(l[1]) in a[2] and (int(l[2]) in a[0]):
				pass
			elif int(l[0]) in a[1] and int(l[1]) in a[0] and (int(l[2]) in a[2]):
				pass
			elif int(l[0]) in a[2] and int(l[1]) in a[1] and (int(l[2]) in a[0]):
				pass
			elif int(l[0]) in a[2] and int(l[1]) in a[0] and (int(l[2]) in a[1]):
				pass
			else:
				print(i - 1)
				break


try:
	while True:
		st = set()
		n = int(input())
		L = [(i, x) for i in range(n) for x in map(int, input().split())]
		for (u, v) in L:
			st.add(v)
		if n >= 2:
			for (u1, v1) in L:
				for (u2, v2) in L:
					if u1 != u2:
						st.add(v1 * 10 + v2)
		if n == 3:
			for (u1, v1) in L:
				for (u2, v2) in L:
					for (u3, v3) in L:
						if u1 != u2 != u3 and u1 != u3:
							st.add(v1 * 100 + v2 * 10 + v3)

		def solve():
			from itertools import count
			for i in count(1, 1):
				if i not in st:
					return i - 1
		print(solve())
except:
	pass


from itertools import permutations
from math import *
n = int(input())
mat = [list(map(int, input().split())) for _ in range(n)]
mp = {}
for vk in mat:
	for el in vk:
		mp[str(el)] = True

def app(a):
	for per in permutations(a):
		if per[0] != 0:
			s = ''
			for p in per:
				s += str(p)
			mp[s] = True
			if len(s) > 2:
				mp[s[:-1]] = mp[s[1:]] = True

def rec(a, i, n):
	if i == n:
		app(a)
		return
	a.append(0)
	for j in range(len(mat[i])):
		a[-1] = mat[i][j]
		rec(a, i + 1, n)
	a.pop()
rec([], 0, n)
res = 0
for i in range(1, 1000):
	if str(i) not in mp:
		res = i - 1
		break
print(res)


n = int(input())
a = []
c = [0] * 1001
for i in range(n):
	a.append(list(map(int, input().split())))
	for j in range(6):
		c[a[i][j]] = 1
if n == 2:
	for j in range(6):
		for k in range(6):
			c[a[0][j] * 10 + a[1][k]] = 1
			c[a[0][j] + a[1][k] * 10] = 1
elif n == 3:
	for j in range(6):
		for k in range(6):
			c[a[0][j] * 10 + a[1][k]] = 1
			c[a[0][j] + a[1][k] * 10] = 1
	for j in range(6):
		for k in range(6):
			c[a[1][j] * 10 + a[2][k]] = 1
			c[a[1][j] + a[2][k] * 10] = 1
	for j in range(6):
		for k in range(6):
			c[a[0][j] * 10 + a[2][k]] = 1
			c[a[0][j] + a[2][k] * 10] = 1
	for j in range(6):
		for k in range(6):
			for i in range(6):
				c[a[0][j] * 100 + a[1][k] * 10 + a[2][i]] = 1
				c[a[0][j] * 100 + a[1][k] + a[2][i] * 10] = 1
				c[a[0][j] * 10 + a[1][k] * 100 + a[2][i]] = 1
				c[a[0][j] * 10 + a[1][k] + a[2][i] * 100] = 1
				c[a[0][j] + a[1][k] * 100 + a[2][i] * 10] = 1
				c[a[0][j] + a[1][k] * 10 + a[2][i] * 100] = 1
i = 0
if c[0] == 0:
	i = 1
while c[i] == 1:
	i += 1
print(i - 1)


class CodeforcesTask887BSolution:

	def __init__(self):
		self.result = ''
		self.n = 0
		self.cubes = []

	def read_input(self):
		self.n = int(input())
		for _ in range(self.n):
			self.cubes.append([int(x) for x in input().split(' ')])

	def process_task(self):
		nums = set()
		for first in self.cubes:
			for number in first:
				if number:
					nums.add(number)
		for x in range(self.n):
			for y in range(self.n):
				if x != y:
					for first in self.cubes[x]:
						for second in self.cubes[y]:
							if first:
								nums.add(10 * first + second)
		for x in range(self.n):
			for y in range(self.n):
				for z in range(self.n):
					if len({x, y, z}) == 3:
						for first in self.cubes[x]:
							for second in self.cubes[y]:
								for third in self.cubes[z]:
									if first:
										nums.add(100 * first + 10 * second + third)
		x = 0
		while True:
			if x + 1 in nums:
				x += 1
			else:
				break
		self.result = str(x)

	def get_result(self):
		return self.result
Solution = CodeforcesTask887BSolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


n = int(input())
aij = [list(map(str, input().split())) for i in range(n)]
numbers = [0] * 1001
numbers[0] = 1
for i in range(n):
	for j in range(6):
		numbers[int(aij[i][j])] = 1
if n == 2:
	for i in range(6):
		for j in range(6):
			numbers[int(aij[0][i] + aij[1][j])] = 1
			numbers[int(aij[1][j] + aij[0][i])] = 1
if n == 3:
	for i in range(6):
		for j in range(6):
			numbers[int(aij[0][i] + aij[1][j])] = 1
			numbers[int(aij[1][j] + aij[0][i])] = 1
	for i in range(6):
		for j in range(6):
			numbers[int(aij[1][i] + aij[2][j])] = 1
			numbers[int(aij[2][j] + aij[1][i])] = 1
	for i in range(6):
		for j in range(6):
			numbers[int(aij[0][i] + aij[2][j])] = 1
			numbers[int(aij[2][j] + aij[0][i])] = 1
	for i in range(6):
		for j in range(6):
			for z in range(6):
				numbers[int(aij[0][i] + aij[1][j] + aij[2][z])] = 1
				numbers[int(aij[0][i] + aij[2][z] + aij[1][j])] = 1
				numbers[int(aij[1][j] + aij[0][i] + aij[2][z])] = 1
				numbers[int(aij[1][j] + aij[2][z] + aij[0][i])] = 1
				numbers[int(aij[2][z] + aij[1][j] + aij[0][i])] = 1
				numbers[int(aij[2][z] + aij[0][i] + aij[1][j])] = 1
ans = -1
for i in range(1001):
	if numbers[i] == 0:
		break
	ans += 1
print(ans)


cubes = [input().split() for _ in range(int(input()))]

def canMake(s):
	if len(s) == 1:
		for cube in cubes:
			if s in cube:
				return True
		return False
	elif len(s) == 2:
		for (i, cube1) in enumerate(cubes):
			if s[0] in cube1:
				for (j, cube2) in enumerate(cubes):
					if i != j and s[1] in cube2:
						return True
		return False
	elif len(s) == 3:
		for (i, cube1) in enumerate(cubes):
			if s[0] in cube1:
				for (j, cube2) in enumerate(cubes):
					if i != j and s[1] in cube2:
						for (k, cube3) in enumerate(cubes):
							if i != k and j != k and (s[2] in cube3):
								return True
		return False
if not canMake('1'):
	print(0)
else:
	for i in range(1, 1000):
		if not canMake(str(i)):
			print(i - 1)
			break


n = int(input())
s = []
for i in range(n):
	s.append(set([int(i) for i in input().split()]))
x = 1
while x < 1000:
	if x < 10:
		for z in range(len(s)):
			if x in s[z]:
				x += 1
				break
		else:
			break
	elif x < 100:
		(e1, e2) = (x // 10, x % 10)
		(se1, se2) = ([], [])
		for z in range(len(s)):
			if e1 in s[z]:
				se1.append(z)
			if e2 in s[z]:
				se2.append(z)
		if len(se1) >= 2 and len(se2) >= 1 or (len(se2) >= 2 and len(se1) >= 1):
			x += 1
		elif len(se1) >= 1 and len(se2) >= 1:
			if se1 != se2:
				x += 1
			else:
				break
		else:
			break
print(x - 1)


a = []
num = []
n = int(input())
for i in range(n):
	a.append(input().strip(' '))
for i in range(10):
	num.append(0)
	for j in range(n):
		if str(i) in a[j]:
			num[i] += 1
go = True
for i in range(1, 10):
	if num[i] == 0:
		print(i - 1)
		go = False
		break
i = 10
while go:
	x = str(i)
	found = False
	if n == 3:
		for j in range(n):
			if x[0] in a[j] and x[1] in a[(j + 1) % 3] + a[(j + 2) % 3]:
				found = True
				break
			if x[1] in a[j] and x[0] in a[(j + 1) % 3] + a[(j + 2) % 3]:
				found = True
				break
	elif n == 2:
		for j in range(n):
			if x[0] in a[j] and x[1] in a[(j + 1) % 2]:
				found = True
				break
			if x[1] in a[j] and x[0] in a[(j + 1) % 2]:
				found = True
				break
	if not found:
		print(i - 1)
		go = False
	i += 1


n = int(input())
l = [[], [], []]
for i in range(n):
	l[i] = list(map(int, input().split()))
tmp = ['012', '021', '102', '120', '201', '210']
ans = 0
for i in range(1, 1000):
	check = 0
	for j in tmp:
		tm = i
		ch = 1
		yoyo = 0
		while tm > 0:
			r = tm % 10
			if r in l[int(j[yoyo])]:
				yoyo -= -1
				tm //= 10
				continue
			else:
				ch = 0
				break
		if ch:
			check = 1
			break
	if check == 0:
		break
	ans = i
print(ans)


import sys
import copy
list = []
dice = {str(i): [] for i in range(0, 10)}
i = -1
for line in sys.stdin:
	i += 1
	if i == 0:
		n = int(line)
	else:
		list_new = line.split()
		for j in list_new:
			if i not in dice[j]:
				dice[j].append(i)
if n == '0':
	print('0')
	exit()
x = 1
while True:
	y = str(x)
	choice = []
	for k in y:
		choice.append(copy.deepcopy(dice[k]))
	if len(choice) < len(y):
		print(x)
		exit()
	while choice != []:
		if choice[0] == []:
			print(x - 1)
			exit()
		else:
			hash = []
			for r in choice[0]:
				h = 0
				for g in range(1, len(choice)):
					if r in choice[g]:
						h += 1
				hash.append((r, h))

			def by_name(t):
				return t[1]
			digit = sorted(hash, key=by_name)[0][0]
			for g in range(1, len(choice)):
				if digit in choice[g]:
					choice[g].remove(digit)
			choice.remove(choice[0])
	x += 1


def inside(ans, a, used=set(), now=0):
	global isFind
	if isFind:
		return 0
	if now == len(ans):
		isFind = True
		return 0
	for j in range(len(a)):
		if j not in used and ans[now] in a[j]:
			nused = used.copy()
			nused.add(j)
			inside(ans, a, nused, now + 1)
n = int(input())
a = []
for i in range(n):
	a.append(set())
for i in range(n):
	for k in input().split():
		a[i].add(k)
ans = 0
isFind = True
while isFind:
	if isFind:
		ans += 1
		isFind = False
		inside(str(ans), a)
print(ans - 1)


n = int(input())
dice = []
for i in range(n):
	dice.append([int(i) for i in input().split()])
h = [0] * 100000
for i in dice[0]:
	h[i] += 1
	if len(dice) > 1:
		for j in dice[1]:
			h[j] += 1
			num = i * 10 + j
			h[num] += 1
			num = j * 10 + i
			h[num] += 1
			if len(dice) > 2:
				for k in dice[2]:
					h[k] += 1
					num = i * 10 + k
					h[num] += 1
					num = k * 10 + i
					h[num] += 1
					num = k * 10 + j
					h[num] += 1
					num = j * 10 + k
					h[num] += 1
					num = i * 100 + j * 10 + k
					h[num] += 1
					num = i * 100 + k * 10 + j
					h[num] += 1
					num = k * 100 + i * 10 + j
					h[num] += 1
					num = k * 100 + j * 10 + i
					h[num] += 1
					num = j * 100 + i * 10 + k
					h[num] += 1
					num = j * 100 + k * 10 + i
					h[num] += 1
h = h[1:]
print(len(h[:h.index(0)]))


n = int(input())
lst = []
for i in range(n):
	a = list(map(int, input().split()))
	lst.append(a)
cnt = 0
ans = 0
if n == 1:
	i = 1
	while 1:
		if i == 10:
			break
		if i in lst[0]:
			i += 1
		else:
			print(i - 1)
			break
elif n == 2:
	i = 1
	f = 0
	while 1:
		if i == 10:
			break
		if i in lst[0] or i in lst[1]:
			i += 1
		else:
			print(i - 1)
			f = 1
			break
	if f == 0:
		i = 10
		while 1:
			n1 = int(str(i)[0])
			n2 = int(str(i)[1])
			if i == 100:
				break
			if n1 in lst[0] and n2 in lst[1] or (n1 in lst[1] and n2 in lst[0]):
				i += 1
			else:
				break
		print(i - 1)
else:
	i = 1
	f = 0
	while 1:
		if i == 10:
			break
		if i in lst[0] or i in lst[1] or i in lst[2]:
			i += 1
		else:
			print(i - 1)
			f = 1
			break
	if f == 0:
		i = 10
		while 1:
			n1 = int(str(i)[0])
			n2 = int(str(i)[1])
			if i == 100:
				print('1')
				break
			if n1 in lst[0] and n2 in lst[1] or (n1 in lst[1] and n2 in lst[0]) or (n1 in lst[0] and n2 in lst[2]) or (n1 in lst[1] and n2 in lst[2]) or (n1 in lst[2] and n2 in lst[1]) or (n1 in lst[2] and n2 in lst[0]) or (n1 in lst[2] and n2 in lst[0]):
				i += 1
			else:
				print(i - 1)
				f = 1
				break
	if f == 0:
		i = 100
		while 1:
			n1 = int(str(i)[0])
			n2 = int(str(i)[1])
			n3 = int(str(i)[2])
			if i == 1000:
				break
			if n1 in lst[0] and n2 in lst[1] and (n3 in lst[2]) or (n1 in lst[1] and n2 in lst[0] and (n3 in lst[2])) or (n1 in lst[1] and n2 in lst[2] and (n3 in lst[0])) or (n1 in lst[2] and n2 in lst[1] and (n3 in lst[0])) or (n1 in lst[2] and n2 in lst[0] and (n3 in lst[1])) or (n1 in lst[0] and n2 in lst[2] and (n3 in lst[1])):
				i += 1
			else:
				break
		print(i - 1)


n = int(input())
a = sorted([list(map(int, input().split())) for i in range(n)])
import itertools
for x in range(1, 10 ** n):
	good = False
	s = str(x)
	for p in itertools.permutations(a, len(s)):
		good |= all([int(s[i]) in v for (i, v) in enumerate(p)])
	if not good:
		print(x - 1)
		exit(0)
print(10 ** n - 1)


n = int(input())
m = n
a = []
while n > 0:
	l = list(map(int, input().split()))
	l.append(-1)
	a.append(l)
	n -= 1
n = m
vis = [0 for i in range(1000)]
if n == 1:
	for x in a[0]:
		if x >= 0:
			vis[x] += 1
elif n == 2:
	l = [(x, y) for x in a[0] for y in a[1]]
	for (x, y) in l:
		if x >= 0 and y >= 0:
			vis[10 * x + y] = 1
			vis[10 * y + x] = 1
		if x >= 0:
			vis[x] = 1
		if y >= 0:
			vis[y] = 1
else:
	l = [(x, y, z) for x in a[0] for y in a[1] for z in a[2]]
	for (x, y, z) in l:
		if x >= 0 and y >= 0 and (z >= 0):
			vis[100 * x + 10 * y + z] = 1
			vis[100 * x + 10 * z + y] = 1
			vis[100 * y + 10 * x + z] = 1
			vis[100 * y + 10 * z + x] = 1
			vis[100 * z + 10 * x + y] = 1
			vis[100 * z + 10 * y + x] = 1
		if x >= 0 and y >= 0:
			vis[10 * x + y] = 1
			vis[10 * y + x] = 1
		if y >= 0 and z >= 0:
			vis[10 * y + z] = 1
			vis[10 * z + y] = 1
		if x >= 0 and z >= 0:
			vis[10 * x + z] = 1
			vis[10 * z + x] = 1
		if x >= 0:
			vis[x] = 1
		if y >= 0:
			vis[y] = 1
		if z >= 0:
			vis[z] = 1
i = 1
while vis[i]:
	i += 1
	if i == 1000:
		break
print(i - 1)


n = int(input())
if n == 3:
	a = set(map(int, input().split()))
	b = set(map(int, input().split()))
	c = set(map(int, input().split()))
	for i in range(1, 10):
		if not (i in a or i in b or i in c):
			print(i - 1)
			exit(0)
	for i in range(10, 100):
		d = i // 10
		e = i % 10
		if not (d in a and e in b or (d in a and e in c) or (d in b and e in a) or (d in b and e in c) or (d in c and e in a) or (d in c and e in b)):
			print(i - 1)
			exit(0)
	for i in range(100, 1000):
		s = i // 100
		d = i % 100 // 10
		e = i % 10
		if not (s in a and d in b and (e in c) or (s in a and d in c and (e in b)) or (s in b and d in a and (e in c)) or (s in b and d in c and (e in a)) or (s in c and d in a and (e in b)) or (s in c and d in b and (e in a))):
			print(i - 1)
			exit(0)
	print(999)
if n == 2:
	a = set(map(int, input().split()))
	b = set(map(int, input().split()))
	for i in range(1, 10):
		if not (i in a or i in b):
			print(i - 1)
			exit(0)
	for i in range(10, 100):
		d = i // 10
		e = i % 10
		if not (d in a and e in b or (d in b and e in a)):
			print(i - 1)
			exit(0)
	print(99)
if n == 1:
	a = set(map(int, input().split()))
	for i in range(1, 10):
		if not i in a:
			print(i - 1)
			exit(0)
	print(9)


from itertools import permutations

def find(perms, num):
	num_str = [char for char in str(num)]
	good = False
	for cubes in perms:
		if find2(cubes, num_str):
			good = True
	return good

def find2(cube_list, num_str):
	if len(num_str) > len(cube_list):
		return False
	for i in range(len(num_str)):
		if num_str[i] not in cube_list[i]:
			return False
	return True
n = int(input())
list1 = [input().split(' ') for x in range(n)]
perm = list(permutations(list1))
i = 1
while find(perm, i):
	i += 1
print(i - 1)


def isPossible(l1, l2, l3, num):
	froml1 = (num - num % 100) // 100
	froml2 = (num % 100 - num % 100 % 10) // 10
	froml3 = num % 10
	if num < 10:
		return l3[froml3] == 1
	if num < 100:
		return l3[froml3] == 1 and l2[froml2] == 1
	else:
		return l3[froml3] == 1 and l2[froml2] == 1 and (l1[froml1] == 1)
	return False
n = int(input())
cubes = []
for i in range(n):
	cube = list(map(int, input().split()))
	cubes.append(cube)
lists = [[0 for i in range(10)] for j in range(n)]
for i in range(n):
	for j in cubes[i]:
		lists[i][j] = 1
for i in range(1, 10 ** n):
	if n == 3:
		if isPossible(lists[0], lists[1], lists[2], i) or isPossible(lists[1], lists[0], lists[2], i) or isPossible(lists[1], lists[2], lists[0], i) or isPossible(lists[2], lists[1], lists[0], i) or isPossible(lists[0], lists[2], lists[1], i) or isPossible(lists[2], lists[0], lists[1], i):
			continue
		else:
			print(i - 1)
			break
	if n == 2:
		if isPossible(None, lists[0], lists[1], i) or isPossible(None, lists[1], lists[0], i):
			continue
		else:
			print(i - 1)
			break
	if n == 1:
		if isPossible(None, None, lists[0], i):
			continue
		else:
			print(i - 1)
			break


n = int(input())
a = []
used = []
for i in range(n):
	x = list(input().split())
	a.append(x)
	for _ in range(6):
		used.append(x[_])
if n == 2:
	for z in range(6):
		for k in range(6):
			s = a[0][z] + a[1][k]
			if s not in used:
				used.append(s)
				used.append(s[::-1])
if n > 2:
	for z in range(3):
		for g in range(6):
			for v in range(6):
				s = a[z][g] + a[(z + 1) % 3][v]
				if s not in used:
					used.append(s)
					used.append(s[::-1])
	for j in range(6):
		for k in range(6):
			for p in range(6):
				s = a[0][j] + a[1][k] + a[2][p]
				if s not in used:
					used.append(s)
					used.append(s[::-1])
used = sorted(list(set(map(int, used))))
if 0 in used:
	del used[used.index(0)]
if used.count(1) > 0:
	for q in range(len(used)):
		if used[q] != q + 1:
			print(q)
			exit()
	print(used[-1])
else:
	print(0)


from collections import deque
from math import log, sqrt, ceil

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().strip().split(' '))

def li():
	return list(mi())
n = ii()
if n == 1:
	a = li()
	for i in range(1, 8):
		if not i in a:
			print(i - 1)
			break
elif n == 2:
	a = li()
	b = li()
	f = 0
	for i in range(1, 10):
		if i not in a + b:
			print(i - 1)
			f = 1
			break
	if f == 0:
		if 0 not in a + b:
			print('9')
			f = 1
	if f == 0:
		m = {}
		f1 = 0
		for i in range(10):
			if i in a and i in b:
				m[i] = 3
			if i in a and i not in b:
				m[i] = 1
			if i in b and i not in a:
				m[i] = 2
		for i in range(1, 10):
			if m[i] == 3:
				continue
			if m[i] == 1:
				for j in range(10):
					if j not in b:
						s = i * 10 + (j - 1)
						f1 = 1
						break
			else:
				for j in range(10):
					if j not in b:
						s = i * 10 + (j - 1)
						f1 = 1
						break
			if f1 == 1:
				break
		print(s)
else:
	a = li()
	b = li()
	c = li()
	f = 0
	for i in range(1, 10):
		if i not in a + b + c:
			print(i - 1)
			f = 1
			break
	if f == 0:
		if 0 not in a + b + c:
			print('9')
			f = 1
	if f == 0:
		m = {}
		f1 = 0
		for i in range(10):
			if i in a and i in b:
				m[i] = 3
			if i in b and i in c:
				m[i] = 3
			if i in a and i in c:
				m[i] = 3
			if i in a and i not in b and (i not in c):
				m[i] = 1
			if i in b and i not in a and (i not in c):
				m[i] = 2
			if i in c and i not in a and (i not in b):
				m[i] = 0
		for i in range(1, 10):
			if m[i] == 3:
				continue
			if m[i] == 1:
				for j in range(10):
					if j not in b + c:
						s = i * 10 + (j - 1)
						f1 = 1
						break
			elif m[i] == 2:
				for j in range(10):
					if j not in a + c:
						s = i * 10 + (j - 1)
						f1 = 1
						break
			else:
				for j in range(10):
					if j not in a + b:
						s = i * 10 + (j - 1)
						f1 = 1
						break
			if f1 == 1:
				break
		print(s)


cubecount = input()
cubies = []
for i in range(int(cubecount)):
	cubies.append(input().split(' '))
count = 0
while count < 1000:
	p = False
	candidate = str(count + 1)
	if count + 1 < 10:
		for cube in cubies:
			if candidate in cube:
				p = True
	elif count + 1 < 100:
		for cube in cubies:
			if candidate[0] in cube:
				cubieb = cubies.copy()
				cubieb.remove(cube)
				for cubeb in cubieb:
					if candidate[1] in cubeb:
						p = True
	else:
		for cube in cubies:
			if candidate[0] in cube:
				cubieb = cubies.copy()
				cubieb.remove(cube)
				for cubeb in cubieb:
					if candidate[1] in cubeb:
						cubiec = cubieb.copy()
						cubiec.remove(cubeb)
						for cubec in cubiec:
							if candidate[2] in cubec:
								p = True
	if p:
		count += 1
	else:
		break
print(count)


from itertools import permutations as p
a = int(input())
(g, h, k) = ('', '', '')
if a >= 1:
	g = input()
if a >= 2:
	h = input()
if a >= 3:
	k = input()
z = [0] * 100
for i in range(1, 1001):
	r = str(i)
	s = list(p(list(r), len(r)))
	if len(r) == 1:
		if r in g + h + k:
			z[i] += 1
	elif len(r) == 2:
		ok = 0
		for t in s:
			if t[0] in g and t[1] in h or (t[0] in g and t[1] in k) or (t[0] in k and t[1] in h):
				ok = 1
		if ok:
			for t in s:
				y = int(''.join(t))
				z[y] += 1
for i in range(1, 100):
	if z[i] == 0:
		print(i - 1)
		break


n = int(input())
if n == 1:
	a = list(map(int, input().split()))
	for i in range(1, 11):
		if not i in a:
			print(i - 1)
			break
elif n == 2:
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	for i in range(1, 10):
		if not i in a and (not i in b):
			print(i - 1)
			break
	else:
		for i in range(10, 101):
			if not (i % 10 in a and i // 10 in b or (i % 10 in b and i // 10 in a)):
				print(i - 1)
				break
else:
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = list(map(int, input().split()))
	for i in range(1, 10):
		if not i in a and (not i in b) and (not i in c):
			print(i - 1)
			break
	else:
		for i in range(10, 100):
			if not (i % 10 in a and i // 10 in b or (i % 10 in b and i // 10 in a)) and (not (i % 10 in a and i // 10 in c or (i % 10 in c and i // 10 in a))) and (not (i % 10 in c and i // 10 in b or (i % 10 in b and i // 10 in c))):
				print(i - 1)
				break
		else:
			for i in range(100, 1001):
				x1 = i % 10
				x2 = i // 10 % 10
				x3 = i // 100
				if not (x1 in a and x2 in b and (x3 in c) or (x2 in a and x1 in b and (x3 in c)) or (x1 in a and x3 in b and (x2 in c)) or (x2 in a and x3 in b and (x1 in c)) or (x3 in a and x2 in b and (x1 in c)) or (x3 in a and x1 in b and (x2 in c))):
					print(i - 1)
					break


import itertools
n = int(input())
cubes = []
x = []
for i in range(n):
	s = input()
	s = s.split()
	x.extend([int(z) for z in s])
	s = ''.join(s)
	cubes.append(s)
x = list(set(x))
if n >= 2:
	z = [[0, 1]]
	if n == 3:
		z = [[0, 1], [0, 2], [1, 2]]
	idx = []
	for i in z:
		idx.extend(list(itertools.permutations(i)))
	for i in idx:
		y = [name + number for name in cubes[i[0]] for number in cubes[i[1]]]
		x.extend([int(z) for z in y])
if n == 3:
	idx = [0, 1, 2]
	idx = list(itertools.permutations(idx))
	for i in idx:
		y = [name + number for name in cubes[i[0]] for number in cubes[i[1]]]
		y = [name + number for name in y for number in cubes[i[2]]]
		x.extend([int(z) for z in y])
x = list(set(x))
cnt = 1
for i in range(1001):
	if cnt in x:
		cnt += 1
	else:
		break
print(cnt - 1)


n = int(input().strip())
n_array = []
for x in range(n):
	n_array.append(input().strip().split())
vals = {}
for x in range(len(n_array)):
	for y in range(6):
		vals[int(n_array[x][y])] = 1
if n == 2:
	for p in range(6):
		for y in range(6):
			num = str(n_array[0][p])
			num += str(n_array[1][y])
			vals[int(num)] = 1
			num = str(n_array[1][y])
			num += str(n_array[0][p])
			vals[int(num)] = 1
elif n == 3:
	for p in range(6):
		for y in range(6):
			num = str(n_array[0][p])
			num += str(n_array[1][y])
			vals[int(num)] = 1
			num = str(n_array[1][y])
			num += str(n_array[0][p])
			vals[int(num)] = 1
			num = str(n_array[0][p])
			num += str(n_array[2][y])
			vals[int(num)] = 1
			num = str(n_array[2][y])
			num += str(n_array[0][p])
			vals[int(num)] = 1
			num = str(n_array[1][p])
			num += str(n_array[2][y])
			vals[int(num)] = 1
			num = str(n_array[2][y])
			num += str(n_array[1][p])
			vals[int(num)] = 1
	for p in range(6):
		for y in range(6):
			for z in range(6):
				num = str(n_array[0][p])
				num += str(n_array[1][y])
				num += str(n_array[2][z])
				vals[int(num)] = 1
				num = str(n_array[0][p])
				num += str(n_array[2][y])
				num += str(n_array[1][z])
				vals[int(num)] = 1
				num = str(n_array[1][p])
				num += str(n_array[0][y])
				num += str(n_array[2][z])
				vals[int(num)] = 1
				num = str(n_array[1][p])
				num += str(n_array[2][y])
				num += str(n_array[0][z])
				vals[int(num)] = 1
				num = str(n_array[2][p])
				num += str(n_array[1][y])
				num += str(n_array[0][z])
				vals[int(num)] = 1
				num = str(n_array[2][p])
				num += str(n_array[0][y])
				num += str(n_array[1][z])
				vals[int(num)] = 1
for x in range(1, 999):
	if x not in vals:
		print(x - 1)
		break


num = int(input())
a = []
b = []
c = []
for i in range(num):
	a = map(int, input().split())
	b.append(list(a))
a = []
for i in range(num):
	for j in b[i]:
		a.append(j)
for i in range(num):
	for j in range(num):
		if i == j:
			continue
		else:
			for k in range(6):
				for l in range(6):
					a.append(b[i][k] * 10 + b[j][l])
a
a.sort()
a = list(set(a))
a.append(a[len(a) - 1])
if a[0] > 1:
	print('0')
else:
	for i in range(len(a) - 1):
		if a[i] + 1 != a[i + 1]:
			print(a[i])
			break


q = int(input())
if q == 3:
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = list(map(int, input().split()))
elif q == 2:
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	c = []
elif q == 1:
	a = list(map(int, input().split()))
	b = []
	c = []
lista = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
lista2 = list()
for x in lista:
	if x not in a + b + c:
		lista2.append(x)
if len(lista2) > 0 and lista2[0] != 0:
	print(lista2[0] - 1)
elif len(lista2) > 1 and lista2[0] == 0:
	print(lista2[1] - 1)
elif len(lista2) == 1 and lista2[0] == 0:
	print('9')
else:
	m = False
	n = False
	o = False
	for x in lista[:1]:
		if x in a and x not in b and (x not in c):
			m = True
		if x in b and x not in c and (x not in a):
			n = True
		if x in c and x not in a and (x not in b):
			o = True
	for x in lista[1:]:
		if x in a and x in b or (x in a and x in c) or (x in b and x in c):
			continue
		else:
			wynik = x
			if wynik in a and wynik not in b and (wynik not in c) and (m == True):
				print(str(wynik * 10 - 1))
				break
			elif wynik in b and wynik not in a and (wynik not in c) and (n == True):
				print(str(wynik * 10 - 1))
				break
			elif wynik in c and wynik not in a and (wynik not in b) and (o == True):
				print(str(wynik * 10 - 1))
				break
			else:
				print(str(wynik) + str(wynik - 1))
				break


n = int(input())

def find(x, d=[]):
	if x == 0 and d != []:
		return True
	l = x % 10
	i = -1
	a = False
	for lis in s:
		i += 1
		if l in lis and i not in d:
			a = max(a, find(x // 10, d + [i]))
	return a
s = [list(map(int, input().split())) for x in range(n)]
e = 1
while find(e):
	e += 1
print(int(e - 1 if find(1) else 0))


n = int(input())
v = []
integers = []
for i in range(n):
	v.append(list(map(int, input().split())))
for i in v[0]:
	integers.append(i)
	if n > 1:
		for j in v[1]:
			integers.append(j)
			if n > 2:
				for k in v[2]:
					integers.append(k)
					integers.append(i * 10 + k)
					integers.append(k * 10 + i)
					integers.append(j * 10 + k)
					integers.append(k * 10 + j)
			integers.append(j * 10 + i)
			integers.append(i * 10 + j)
integers.sort()
for i in range(1, 100):
	if not i in integers:
		print(i - 1)
		break


n = int(input())
cubes = []
for i in range(n):
	c = list(map(int, input().split()))
	cubes.append(c)
ez = True
a = 1
while ez and a < 1000:
	ez = False
	if a < 10:
		for i in range(n):
			if a in cubes[i]:
				ez = True
	if a >= 10 and a < 100:
		d1 = a // 10
		d2 = a % 10
		p1 = set()
		p2 = set()
		for i in range(n):
			if d1 in cubes[i]:
				p1.add(i)
			if d2 in cubes[i]:
				p2.add(i)
		p3 = p1.union(p2)
		if len(p3) >= 2 and len(p1) != 0 and (len(p2) != 0):
			ez = True
	if a >= 100 and a < 1000:
		d1 = a // 10
		d2 = a // 10 % 10
		d3 = a % 10
		p1 = set()
		p2 = set()
		p3 = set()
		for i in range(n):
			if d1 in cubes[i]:
				p1.add(i)
			if d2 in cubes[i]:
				p2.add(i)
			if d3 in cubes[i]:
				p3.add(i)
		p4 = p1.union(p2)
		p4 = p4.union(p3)
		if len(p4) == 3 and len(p1) != 0 and (len(p2) != 0) and (len(p3) != 0):
			ez = True
	a += 1
print(a - 2)


import itertools
n = int(input())
a = []
for i in range(n):
	lst = list(map(int, input().split()))
	a.append(lst)
i = 0
while i < 10 ** n - 1:
	ch = i + 1
	c = []
	while ch > 0:
		z = ch % 10
		kek = []
		for j in range(n):
			if z in a[j]:
				kek.append(j)
		c.append(kek)
		ch //= 10
	if len(c) == 1:
		if len(c[0]) > 0:
			i += 1
		else:
			break
		continue
	if len(c) == 2:
		ok = 0
		for i1 in c[0]:
			for j1 in c[1]:
				if i1 != j1:
					ok = 1
		if ok:
			i += 1
		else:
			break
	if len(c) == 3:
		ok = 0
		for i1 in c[0]:
			for j1 in c[1]:
				for k1 in c[2]:
					if i1 != j1 and j1 != k1:
						print(i1, j1, k1)
						i += 1
						ok = 1
						break
		if not ok:
			break
print(i)


import math
import queue
n = int(input())
a = []
for i in range(0, n):
	a.append([int(c) for c in input().split()])
if n == 3:
	for p in range(1, 1001):
		exist = False
		for i in range(0, 6):
			for j in range(0, 6):
				for k in range(0, 6):
					if 100 * a[0][i] + 10 * a[1][j] + a[2][k] == p:
						exist = True
					if 100 * a[0][i] + 10 * a[2][k] + a[1][j] == p:
						exist = True
					if 100 * a[1][j] + 10 * a[0][i] + a[2][k] == p:
						exist = True
					if 100 * a[1][j] + 10 * a[2][k] + a[0][i] == p:
						exist = True
					if 100 * a[2][k] + 10 * a[1][j] + a[0][i] == p:
						exist = True
					if 100 * a[2][k] + 10 * a[0][i] + a[1][j] == p:
						exist = True
					if 10 * a[0][i] + a[1][j] == p:
						exist = True
					if 10 * a[0][i] + a[2][k] == p:
						exist = True
					if 10 * a[1][j] + a[0][i] == p:
						exist = True
					if 10 * a[1][j] + a[2][k] == p:
						exist = True
					if 10 * a[2][k] + a[0][i] == p:
						exist = True
					if 10 * a[2][k] + a[1][j] == p:
						exist = True
					if a[0][i] == p:
						exist = True
					if a[1][j] == p:
						exist = True
					if a[2][k] == p:
						exist = True
		if not exist:
			break
elif n == 2:
	for p in range(1, 101):
		exist = False
		for i in range(0, 6):
			for j in range(0, 6):
				if 10 * a[0][i] + a[1][j] == p:
					exist = True
				if 10 * a[1][j] + a[0][i] == p:
					exist = True
				if a[0][i] == p:
					exist = True
				if a[1][j] == p:
					exist = True
		if not exist:
			break
elif n == 1:
	for p in range(1, 11):
		exist = False
		for i in range(0, 6):
			if a[0][i] == p:
				exist = True
		if not exist:
			break
print(p - 1)


table = [str(i) for i in range(1, 1000)]
n = int(input())
num = []
res = []
for i in range(n):
	s = input()
	s = s.split()
	num.append(s)
for i in num[0]:
	res.append(i)
if n > 1:
	for i in num[0]:
		for j in num[1]:
			res.append(str(int(i + j)))
			res.append(str(int(j + i)))
	for i in num[1]:
		res.append(str(int(i)))
if n == 3:
	for i in num[0]:
		for j in num[1]:
			for k in num[2]:
				res.append(str(int(i + j + k)))
				res.append(str(int(i + k + j)))
				res.append(str(int(j + i + k)))
				res.append(str(int(j + k + i)))
				res.append(str(int(k + i + j)))
				res.append(str(int(k + j + i)))
	for i in num[2]:
		res.append(str(int(i)))
	for i in num[0]:
		for j in num[2]:
			res.append(str(int(i + j)))
			res.append(str(int(j + i)))
	for i in num[1]:
		for j in num[2]:
			res.append(str(int(i + j)))
			res.append(str(int(j + i)))
for i in range(1, 1001):
	if not str(i) in res:
		print(i - 1)
		break


import collections
n = int(input())
x = []
for i in range(n):
	x.append(list(map(int, input().split())))
if n == 1:
	ans = 0
	for i in range(1, 10):
		if i in x[0]:
			ans = i
		else:
			print(ans)
			break
elif n == 2:
	ans = 1
	while True:
		if ans < 10:
			if ans in x[0] or ans in x[1]:
				ans += 1
			else:
				exit(print(ans - 1))
		else:
			k = str(ans)
			if int(k[0]) in x[0] and int(k[1]) in x[1] or (int(k[0]) in x[1] and int(k[1]) in x[0]):
				ans += 1
			else:
				exit(print(ans - 1))
else:
	ans = 1
	while True:
		if ans < 10:
			if ans in x[0] or ans in x[1] or ans in x[2]:
				ans += 1
			else:
				exit(print(ans - 1))
		elif ans >= 10 and ans <= 99:
			k = str(ans)
			if int(k[0]) in x[0] and (int(k[1]) in x[1] or int(k[1]) in x[2]) or (int(k[0]) in x[1] and (int(k[1]) in x[0] or int(k[1]) in x[2])) or (int(k[0]) in x[2] and (int(k[1]) in x[1] or int(k[1]) in x[0])):
				ans += 1
			else:
				exit(print(ans - 1))


n = int(input())
if n == 1:
	arr = list(map(int, input().split()))
	arr.sort()
elif n == 2:
	arr1 = list(map(int, input().split()))
	arr2 = list(map(int, input().split()))
	arr = []
	for i in arr1:
		arr.append(i)
	for i in arr2:
		arr.append(i)
	for i in arr1:
		for j in arr2:
			arr.append(i * 10 + j)
			arr.append(j * 10 + i)
	arr = list(set(arr))
	arr.sort()
elif n == 3:
	arr1 = list(map(int, input().split()))
	arr2 = list(map(int, input().split()))
	arr3 = list(map(int, input().split()))
	arr = []
	for i in arr1:
		arr.append(i)
	for i in arr2:
		arr.append(i)
	for i in arr3:
		arr.append(i)
	for i in arr1:
		for j in arr2:
			arr.append(i * 10 + j)
			arr.append(j * 10 + i)
	for i in arr2:
		for j in arr3:
			arr.append(i * 10 + j)
			arr.append(j * 10 + i)
	for i in arr1:
		for j in arr3:
			arr.append(i * 10 + j)
			arr.append(j * 10 + i)
	for i in arr1:
		for j in arr2:
			for k in arr3:
				arr.append(i * 100 + j * 10 + k)
				arr.append(i * 100 + k * 10 + j)
				arr.append(j * 100 + i * 10 + k)
				arr.append(j * 100 + k * 10 + i)
				arr.append(k * 100 + i * 10 + j)
				arr.append(k * 100 + j * 10 + i)
	arr = list(set(arr))
	arr.sort()
if arr[0] == 0:
	t = 0
else:
	t = 1
flag = 0
for i in range(len(arr)):
	if i + t != arr[i]:
		flag = 1
		break
if flag == 1:
	print(i - 1 + t)
else:
	print(i + t)


from sys import stdin
import math
n = int(stdin.readline())
dice = []
for i in range(n):
	dice.append([int(x) for x in stdin.readline().strip().split()])
number = 0
for x in range(1, 99):
	control = False
	if x < 10:
		digit1 = x
		for rows in dice:
			if digit1 in rows:
				control = True
	else:
		digit1 = int((x - x % 10) / 10)
		digit2 = x % 10
		if n == 2:
			if digit1 in dice[0] and digit2 in dice[1] or (digit1 in dice[1] and digit2 in dice[0]):
				control = True
		elif n == 3:
			for i in range(3):
				if i == 0:
					if digit1 in dice[0] and (digit2 in dice[1] or digit2 in dice[2]):
						control = True
				elif i == 1:
					if digit1 in dice[1] and (digit2 in dice[0] or digit2 in dice[2]):
						control = True
				elif i == 2:
					if digit1 in dice[2] and (digit2 in dice[0] or digit2 in dice[1]):
						control = True
	if control == True:
		number = x
	if control == False:
		break
print(number)


ms = []
mas = []
a = int(input())
for i in range(0, a):
	ms = [int(s) for s in input().split()]
	mas.append(ms)
for i in range(a):
	mas[i] = sorted(mas[i])
A = set()
for i in range(6):
	A.add(mas[0][i])
	if a > 1:
		A.add(mas[1][i])
		for j in range(6):
			A.add(mas[0][i] * 10 + mas[1][j])
			A.add(mas[1][i] * 10 + mas[0][j])
			if a > 2:
				A.add(mas[2][i])
				A.add(mas[0][i] * 10 + mas[2][j])
				A.add(mas[2][i] * 10 + mas[0][j])
				A.add(mas[2][i] * 10 + mas[1][j])
				A.add(mas[1][i] * 10 + mas[2][j])
				for p in range(6):
					A.add(100 * mas[0][i] + 10 * mas[1][j] + mas[2][p])
for i in range(1, 999):
	if not i in A:
		print(i - 1)
		break


import sys
import itertools

def valid(i):
	s = str(i)
	length = len(s)
	if length > n:
		return False
	for tuple in itertools.permutations(perm, length):
		valid = True
		for (cnt, k) in enumerate(s):
			if k not in strs[tuple[cnt]]:
				valid = False
				break
		if valid:
			return True
	return False
n = int(sys.stdin.readline().rstrip())
perm = [x for x in range(n)]
strs = []
for i in range(n):
	strs.append(''.join(sys.stdin.readline().rstrip().split()))
for i in range(1, 1001):
	if not valid(i):
		print(i - 1)
		exit()


import sys
n = int(input())
max = 0
if n == 1:
	a = [int(x) for x in input().split()]
	for i in range(1, 10):
		if i not in a:
			print(max)
			sys.exit()
		max += 1
elif n == 2:
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	for i in range(1, 10):
		if i not in a and i not in b:
			print(max)
			sys.exit()
		max += 1
	for i in range(10, 100):
		a1 = int(str(i)[0])
		a2 = int(str(i)[1])
		if a1 in a and a2 in b or (a1 in b and a2 in a):
			max += 1
		else:
			print(max)
			sys.exit()
elif n == 3:
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	c = [int(x) for x in input().split()]
	for i in range(1, 10):
		if i not in a and i not in b and (i not in c):
			print(max)
			sys.exit()
		max += 1
	for i in range(10, 100):
		a1 = int(str(i)[0])
		a2 = int(str(i)[1])
		if a1 in a and a2 in b or (a1 in b and a2 in a) or (a1 in a and a2 in c) or (a1 in c and a2 in a) or (a1 in b and a2 in c) or (a1 in c and a2 in b):
			max += 1
		else:
			print(max)
			sys.exit()


def make_num(num, a, n, m=6):
	for i in range(n):
		for j in range(m):
			num[a[i][j]] = 1
	for i1 in range(n):
		for j1 in range(m):
			for i2 in range(n):
				for j2 in range(m):
					if i1 != i2:
						x = a[i1][j1] * 10 + a[i2][j2]
						num[x] = 1
	for i1 in range(n):
		for j1 in range(m):
			for i2 in range(n):
				for j2 in range(m):
					for i3 in range(n):
						for j3 in range(m):
							if i1 != i2 and i2 != i3:
								x = a[i1][j1] * 100 + a[i2][j2] * 10 + a[i3][j3]
								num[x] = 1

def find_ans(num):
	n = 1000
	for i in range(1, n):
		if not num.get(i):
			print(i - 1)
			break

def main():
	n = int(input())
	m = 6
	a = [[0] * m] * n
	for i in range(0, n):
		a[i] = [int(x) for x in input().split()]
	num = {}
	make_num(num, a, n, m=6)
	find_ans(num)
main()


n = int(input())
cs = []
for i in range(n):
	cs.append([int(x) for x in input().split()])
ans = 0

def can_make(num, cs):
	if num == 0:
		return True
	elif len(cs) == 0:
		return False
	cm = False
	for i in range(len(cs)):
		if num % 10 in cs[i]:
			if can_make(num // 10, cs[0:i] + cs[i + 1:]):
				return True
	return False
for i in range(1, 1000):
	if can_make(i, cs):
		ans = i
	else:
		break
print(ans)


n = int(input())
a = []
z = [False] * 100
for i in range(n):
	a.append(list(map(int, input().split())))
for i in range(n):
	for x in a[i]:
		z[x] = True
for i in range(n):
	for j in range(6):
		for k in range(n):
			if i != k:
				for p in range(6):
					z[a[i][j] * 10 + a[k][p]] = True
x = 1
while z[x]:
	x += 1
print(x - 1)


n = int(input())
c = [list(map(int, input().split())) for i in range(n)]
s = set()
from itertools import *
for i in permutations(c):
	for j in product(range(6), repeat=n):
		v = []
		for k in range(n):
			v.append(i[k][j[k]] * 10 ** k)
		for k in accumulate(v):
			s.add(k)
t = set(range(1, 10 ** n))
ans = min(t - s) - 1
print(ans)


n = int(input())
mas = []
for i in range(n):
	mas.append(input().split())
q = 1
while True:
	if len(str(q)) == 1:
		x = -1
		for el in mas:
			if str(q) in el:
				x = 0
		if x == -1:
			k = q - 1
			break
	elif len(str(q)) == 2:
		if n == 1:
			k = q - 1
			break
		q1 = str(q)[0]
		q2 = str(q)[1]
		if n == 3:
			if not (q1 in mas[0] and q2 in mas[1] or (q1 in mas[1] and q2 in mas[0]) or (q1 in mas[0] and q2 in mas[2]) or (q1 in mas[2] and q2 in mas[0]) or (q1 in mas[1] and q2 in mas[2]) or (q1 in mas[2] and q2 in mas[1])):
				k = q - 1
				break
		elif not (q1 in mas[0] and q2 in mas[1] or (q1 in mas[1] and q2 in mas[0])):
			k = q - 1
			break
	else:
		if n == 2:
			k = q - 1
			break
		q1 = str(q)[0]
		q2 = str(q)[1]
		q3 = str(q)[2]
		if not (q1 in mas[0] and q2 in mas[1] and (q3 in mas[2]) or (q1 in mas[1] and q2 in mas[0] and (q3 in mas[2])) or (q1 in mas[1] and q2 in mas[2] and (q3 in mas[0])) or (q1 in mas[2] and q2 in mas[1] and (q3 in mas[0])) or (q1 in mas[2] and q2 in mas[0] and (q3 in mas[1])) or (q1 in mas[0] and q2 in mas[2] and (q3 in mas[1]))):
			k = q - 1
			break
	q += 1
print(k)


n = int(input())
data = []
number = -1
for i in range(n):
	data.append({int(z) for z in input().split()})
for a in range(1, 10):
	for i in range(n):
		if a in data[i]:
			break
	else:
		number = a
		break
if number != -1:
	print(number - 1)
	exit(0)
for a in range(10, 100):
	r = a % 10
	l = a // 10
	lk = []
	rk = []
	for i in range(n):
		if l in data[i]:
			lk.append(i)
		if r in data[i]:
			rk.append(i)
	if len(lk) >= 2 and len(rk) >= 1 or (len(rk) >= 2 and len(lk) >= 1):
		continue
	elif len(lk) >= 1 and len(rk) >= 1:
		if lk != rk:
			continue
		else:
			number = a
			break
	else:
		number = a
		break
print(number - 1)


n = int(input())
if n == 1:
	a = [int(i) for i in input().split()]
	b = [10000 for i in range(6)]
	c = [10000 for i in range(6)]
if n == 2:
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	c = [10000 for i in range(6)]
if n == 3:
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]
	c = [int(i) for i in input().split()]
for r in range(1, 10):
	if r not in a + b + c:
		print(r - 1)
		exit(0)
for r in range(10, 100):
	ok = 0
	s = list(str(r))
	if int(s[0]) in a and int(s[1]) in b + c or (int(s[0]) in b and int(s[1]) in c + a) or (int(s[0]) in c and int(s[1]) in a + b):
		ok = 1
	if ok == 0:
		print(r - 1)
		exit(0)


n = int(input())
a = []
alll = []
for i in range(n):
	a += [list(map(str, input().split()))]
a += [[]]
a += [[]]
t = 1
while t != 1000:
	dt = str(t)
	if len(dt) == 1 and dt in a[0] + a[1] + a[2]:
		pass
	elif len(dt) == 1:
		break
	if len(dt) == 2:
		tt = False
		for i in range(3):
			(j, k) = (0, 0)
			while j == i:
				j += 1
			while k == i or k == j:
				k += 1
			if dt[0] in a[i] and (dt[1] in a[j] or dt[1] in a[k]):
				tt = True
		if not tt:
			break
	if len(dt) == 3:
		tt = False
		for i in range(3):
			for j in range(i + 1, 3):
				k = 0
				while k == i or k == j:
					k += 1
				if dt[0] in a[i] and dt[1] in a[j] and (dt[2] in a[k]):
					tt = True
		if not tt:
			break
	t += 1
print(t - 1)


import itertools
kostki = []
for i in range(int(input())):
	kostki.append(input().split())
l = [''.join(i) for i in itertools.product(*kostki)]
s = [(1, 2, 3), (1, 2), (1, 3), (2, 3), (1,), (2,), (3,)]
s1 = []
for p in s:
	s1 += itertools.permutations(p)
res = set()
for inp in l:
	for p in s1:
		num = ''
		for ind in p:
			if ind <= len(inp):
				num += inp[ind - 1]
		if num:
			res.add(int(num))
for i in range(1, 1003):
	if i not in res:
		print(i - 1)
		break


n = int(input())
if n == 1:
	a = list(map(int, input().split()))
	a.sort()
	c = 1
	if 0 in a:
		a = a[1:]
	for i in a:
		if i == c:
			c += 1
		else:
			print(c - 1)
			exit()
	print(c - 1)
elif n == 2:
	a = set(map(int, input().split()))
	b = set(map(int, input().split()))
	x = a.union(b)
	x = set(sorted(x))
	for i in a:
		for j in b:
			k = i * 10 + j
			u = j * 10 + i
			x.add(k)
			x.add(u)
	x = list(x)
	c = 1
	if 0 in x:
		x = x[1:]
	for i in x:
		if i == c:
			c += 1
		else:
			print(c - 1)
			exit()
	print(c - 1)
elif n == 3:
	a = set(map(int, input().split()))
	b = set(map(int, input().split()))
	c = set(map(int, input().split()))
	x = a.union(b)
	x = c.union(x)
	x = set(sorted(x))
	for i in a:
		for j in b:
			x.add(int(str(i) + str(j)))
			x.add(int(str(j) + str(i)))
	for i in a:
		for j in c:
			x.add(int(str(i) + str(j)))
			x.add(int(str(j) + str(i)))
	for i in c:
		for j in b:
			x.add(int(str(i) + str(j)))
			x.add(int(str(j) + str(i)))
	for i in a:
		for j in b:
			for k in c:
				x.add(int(str(i) + str(j) + str(k)))
				x.add(int(str(i) + str(k) + str(j)))
				x.add(int(str(j) + str(i) + str(k)))
				x.add(int(str(j) + str(k) + str(i)))
				x.add(int(str(k) + str(j) + str(i)))
				x.add(int(str(k) + str(i) + str(j)))
	x = list(x)
	c = 1
	if 0 in x:
		x = x[1:]
	for i in x:
		if i == c:
			c += 1
		else:
			print(c - 1)
			exit()
	print(c - 1)


n = int(input())
cubes = []
for i in range(n):
	cubes.append(set(input().split()))
max_num = None
for i in range(1, 10):
	num = str(i)
	found = False
	for cube in cubes:
		if num in cube:
			found = True
			break
	if not found:
		max_num = i
		break
if not max_num:
	for j in range(10, 100):
		(num1, num2) = (str(j)[0], str(j)[1])
		fnum1 = []
		fnum2 = []
		for i in range(len(cubes)):
			if num1 in cubes[i]:
				fnum1.append(i)
			if num2 in cubes[i]:
				fnum2.append(i)
		if len(fnum1) > 1 and len(fnum2) > 0:
			continue
		if len(fnum2) > 1 and len(fnum1) > 0:
			continue
		if len(fnum2) == 1 and len(fnum1) == 1 and (fnum1 != fnum2):
			continue
		max_num = j
		break
print(max_num - 1)


def func(s, a, n):
	use = [''] * len(a)
	for i in range(len(a)):
		for j in range(n):
			if a[i] in s[j]:
				use[i] += str(j)
	if len(a) == 3:
		if (use[0] == use[1] or use[1] == use[2] or (use[2] == use[0] and (use[0] < 3 or use[1] < 3))) or use[0] == '' or use[1] == '' or (use[2] == ''):
			return False
		else:
			return True
	elif len(a) == 2:
		if use[0] == use[1] and len(use[0]) == 1 or use[0] == '' or use[1] == '':
			return False
		else:
			return True
	elif use[0] == '':
		return False
	else:
		return True
n = int(input())
s = [''] * n
for i in range(n):
	s[i] = input()
k = 0
while True:
	k += 1
	if not func(s, str(k), n):
		break
print(k - 1)


n = int(input())
d = [[], [], []]
for i in range(n):
	d[i] = input().split()
combine = d[0][:] + d[1][:] + d[2][:]
combine += [i + j for i in d[0] for j in d[1] + d[2]]
combine += [i + j for i in d[1] for j in d[0] + d[2]]
combine += [i + j for i in d[2] for j in d[0] + d[1]]
combine += [i + j + k for i in d[1] for j in d[2] for k in d[0]]
combine += [i + j + k for i in d[1] for j in d[0] for k in d[2]]
combine += [i + j + k for i in d[2] for j in d[1] for k in d[0]]
combine += [i + j + k for i in d[2] for j in d[0] for k in d[1]]
combine += [i + j + k for i in d[0] for j in d[1] for k in d[2]]
combine += [i + j + k for i in d[1] for j in d[0] for k in d[2]]
f = True
now = 1
while f:
	if now == 1:
		if str(now) not in combine:
			print('0')
			exit(0)
	if str(now) not in combine:
		f = False
		print(now - 1)
	else:
		now += 1


def f(m):
	m = list(map(int, list(str(m))))
	for k in range(dd[n]):
		cur = 0
		for j in range(n):
			kub = d[k][j] - 1
			if cur == len(m):
				return True
			if m[cur] in a[kub]:
				cur += 1
		if cur == len(m):
			return True
	return False
n = int(input())
a = [[], [], []]
for i in range(n):
	a[i] = list(map(int, input().split()))
d = [[1, 2, 3], [2, 1, 3], [1, 3, 2], [2, 3, 1], [3, 1, 2], [3, 2, 1]]
dd = [0, 0, 2, 6]
if n == 1:
	for j in range(1, 10):
		if j not in a[0]:
			print(j - 1)
			exit()
ans = 0
while f(ans + 1):
	ans += 1
print(ans)


import sys, math
readline = sys.stdin.readline
n = int(readline())
dd = dict()
for i in range(10):
	dd[i] = 0
tp = []
for i in range(n):
	tp.append(list(map(int, readline().split())))
if n == 2:
	ans = -1
	for i in range(1, 10):
		if i not in tp[0] and i not in tp[1]:
			ans = i - 1
			break
	if ans == -1:
		if 0 not in tp[0] and 0 not in tp[1]:
			ans = 9
		else:
			for i in range(10, 100):
				ii = ord(str(i)[1]) - 48
				iii = (i - ii) // 10
				t = not (ii in tp[0] and iii in tp[1] or (ii in tp[1] and iii in tp[0]))
				if t:
					ans = i - 1
					break
	print(ans)
elif n == 3:
	for i in range(1, 100):
		if i < 10:
			if not (i in tp[0] or i in tp[1] or i in tp[2]):
				print(i - 1)
				break
		else:
			ii = ord(str(i)[1]) - 48
			iii = (i - ii) // 10
			t = not (ii in tp[0] and iii in tp[1] or (ii in tp[0] and iii in tp[2]) or (ii in tp[1] and iii in tp[2]))
			tt = not (iii in tp[0] and ii in tp[1] or (iii in tp[0] and ii in tp[2]) or (iii in tp[1] and ii in tp[2]))
			if t and tt:
				print(i - 1)
				break
else:
	for i in range(1, 8):
		if i not in tp[0]:
			print(i - 1)
			break


from itertools import combinations
n = int(input())
cb = []
p = set()
for i in range(n):
	c = list(map(int, input().split()))
	cb.append(c)
	for a in c:
		p.add(a)
if n >= 2:
	t = combinations(range(n), 2)
	for (a, b) in t:
		for t in cb[a]:
			for k in cb[b]:
				p.add(int(str(t) + str(k)))
				p.add(int(str(k) + str(t)))
if n >= 3:
	for a in cb[0]:
		for b in cb[1]:
			for c in cb[2]:
				p.add(int(str(a) + str(b) + str(c)))
				p.add(int(str(a) + str(c) + str(b)))
				p.add(int(str(b) + str(a) + str(c)))
				p.add(int(str(b) + str(c) + str(a)))
				p.add(int(str(c) + str(b) + str(a)))
				p.add(int(str(c) + str(a) + str(b)))
k = list(sorted(p)) + [-4]
if k[0] == 1 or k[1] == 1:
	for i in range(len(k) - 1):
		if k[i] + 1 != k[i + 1]:
			print(k[i])
			break
else:
	print(0)


import itertools
n = int(input())
cubes = []
for i in range(n):
	line = input().split()
	cubes.append(line)
nums = {}
for i in range(1, 1000):
	nums[i] = False
if n == 3:
	for a in cubes[0]:
		for b in cubes[1]:
			for c in cubes[2]:
				for i in range(n):
					for comb in itertools.permutations([a, b, c], i + 1):
						pres = 0
						for num in comb:
							pres *= 10
							pres += int(num)
						nums[pres] = True
if n == 2:
	for a in cubes[0]:
		for b in cubes[1]:
			for i in range(n):
				for comb in itertools.permutations([a, b], i + 1):
					pres = 0
					for num in comb:
						pres *= 10
						pres += int(num)
					nums[pres] = True
if n == 1:
	for a in cubes[0]:
		nums[int(a)] = True
x = 0
while nums[x + 1]:
	x += 1
print(x)


n = int(input())
if n == 1:
	a1 = list(map(int, input().split()))
	a1.sort()
	while a1[0] == 0:
		a1.pop(0)
	if a1[0] == 1:
		cnt = 1
		for i in a1[1:]:
			if i == cnt + 1:
				cnt += 1
			else:
				break
		print(cnt)
	else:
		print(0)
elif n == 2:
	a1 = list(map(int, input().split()))
	a2 = list(map(int, input().split()))
	res = []
	for a in a1:
		res.append(a)
	for a in a2:
		res.append(a)
	for a in a1:
		for b in a2:
			res.append(a * 10 + b)
			res.append(b * 10 + a)
	res = list(set(res))
	res.sort()
	while res[0] == 0:
		res.pop(0)
	if res[0] == 1:
		cnt = 1
		for i in res[1:]:
			if i == cnt + 1:
				cnt += 1
			else:
				break
		print(cnt)
	else:
		print(0)
elif n == 3:
	a1 = list(map(int, input().split()))
	a2 = list(map(int, input().split()))
	a3 = list(map(int, input().split()))
	res = []
	for a in a1:
		res.append(a)
	for a in a2:
		res.append(a)
	for a in a3:
		res.append(a)
	for a in a1:
		for b in a2:
			res.append(a * 10 + b)
			res.append(b * 10 + a)
	for a in a1:
		for b in a3:
			res.append(a * 10 + b)
			res.append(b * 10 + a)
	for a in a3:
		for b in a2:
			res.append(a * 10 + b)
			res.append(b * 10 + a)
	for a in a1:
		for b in a2:
			for c in a3:
				res.append(a * 100 + b * 10 + c)
				res.append(a * 100 + c * 10 + b)
				res.append(b * 100 + a * 10 + c)
				res.append(b * 100 + c * 10 + a)
				res.append(c * 100 + a * 10 + b)
				res.append(c * 100 + b * 10 + c)
	res = list(set(res))
	res.sort()
	while res[0] == 0:
		res.pop(0)
	if res[0] == 1:
		cnt = 1
		for i in res[1:]:
			if i == cnt + 1:
				cnt += 1
			else:
				break
		print(cnt)
	else:
		print(0)


import itertools
n = int(input())
A = [[] for i in range(n)]
for i in range(n):
	a = list(map(int, input().split()))
	A[i] = a
if n == 1:
	num = 1
	for i in range(10):
		if num not in A[0]:
			break
		num += 1
	print(num - 1)
elif n == 2:
	num = 1
	while num in A[0] or num in A[1]:
		num += 1
	if num == 10:
		while num // 10 in A[0] and num % 10 in A[1] or (num // 10 in A[1] and num % 10 in A[0]):
			num += 1
	print(num - 1)
else:
	num = 1
	while num in A[0] or num in A[1] or num in A[2]:
		num += 1
	if num == 10:
		R = [0, 1, 2]
		while True:
			flag = False
			for (i, j) in list(itertools.combinations(R, 2)):
				if num // 10 in A[i] and num % 10 in A[j] or (num // 10 in A[j] and num % 10 in A[i]):
					flag = True
			if not flag:
				break
			else:
				num += 1
	print(num - 1)


import sys
import math
import itertools

def ria():
	return [int(i) for i in input().split()]
n = int(input())
cubes = [[j for j in input().split()] for i in range(n)]
ans = 0
for i in range(1, 1000):
	if len(str(i)) > n:
		break
	good = False
	d = str(i)
	for j in itertools.permutations(range(n), len(str(i))):
		bad = False
		for (N, k) in enumerate(j):
			if not d[N] in cubes[k]:
				bad = True
				break
		if not bad:
			good = True
			break
	if not good:
		break
	ans = i
print(ans)


def check(cubes, n):
	if len(str(n)) == 1:
		for cube in cubes:
			if n in cube:
				return True
		return False
	elif len(str(n)) == 2:
		for c1 in range(len(cubes)):
			for c2 in range(len(cubes)):
				if c1 == c2:
					pass
				elif int(str(n)[0]) in cubes[c1] and int(str(n)[1]) in cubes[c2]:
					return True
		return False
n = int(input())
cubes = [[int(x) for x in input().split(' ')] for i in range(n)]
i = 1
while check(cubes, i):
	i += 1
print(i - 1)


n = int(input())
start = 1
L = [list(map(int, input().split())) for i in range(n)]
for i in range(n):
	L.append(L[i])
f = True
while f:
	z = False
	t = [int(x) for x in str(start)]
	for i in range(n):
		p = 0
		if z:
			break
		for j in range(i, i + n):
			if t[p] in L[j]:
				p += 1
			if p == len(t):
				z = True
				break
	if z:
		start += 1
	else:
		break
print(start - 1)


from itertools import combinations as c
n = int(input())
s = set()
if n >= 1:
	l = input().split()
	for i in l:
		if i != '0':
			s.add(int(i))
if n >= 2:
	l2 = input().split()
	for i in l:
		for j in l2:
			if i != '0':
				s.add(int(i + j))
			if j != '0':
				s.add(int(j))
				s.add(int(j + i))
if n == 3:
	l3 = input().split()
	for i in l:
		for j in l2:
			for k in l3:
				if i != '0':
					s.add(int(i + j + k))
					s.add(int(i + k))
				if j != '0':
					s.add(int(j + k))
				if k != '0':
					s.add(int(k))
					s.add(int(k + j))
					s.add(int(k + i))
print(min(set(range(1000)) - s - {0}) - 1)


from sys import exit

def double(l1, l2):
	ans = []
	for i in l1:
		for j in l2:
			ans.append(i * 10 + j)
	return ans

def triple(l1, l2, l3):
	ans = []
	for i in l1:
		for j in l2:
			for k in l3:
				ans.append(i * 100 + j * 10 + k)
	return ans
n = int(input())
(l, gen) = ([], [])
for i in range(n):
	l.append(list(map(int, input().split())))
if n == 1:
	for i in range(1, 10):
		if l[0].count(i) == 0:
			print(i - 1)
			break
	exit()
for i in l:
	for j in i:
		gen.append(j)
for i in range(n):
	for j in range(n):
		if i != j:
			gen.extend(double(l[i], l[j]))
if n == 2:
	for i in range(1, 99):
		if gen.count(i) == 0:
			print(i - 1)
			exit()
	print(99)
	exit()
for i in range(n):
	for j in range(n):
		if i == j:
			continue
		for k in range(n):
			if k == i or k == j:
				continue
			gen.extend(triple(l[i], l[j], l[k]))
for i in range(1, 999):
	if gen.count(i) == 0:
		print(i - 1)
		exit()
print(999)


def gen(cur, used, x):
	pos.add(cur)
	if x == n:
		return
	for j in range(n):
		if not used[j]:
			for i in a[j]:
				if i != 0 or x != 0:
					used[j] = True
					gen(cur * 10 + i, used, x + 1)
					used[j] = False
n = int(input())
a = []
for i in range(n):
	a.append(list(map(int, input().split())))
pos = set()
gen(0, [False] * n, 0)
x = 1
while x in pos:
	x += 1
print(x - 1)


n = int(input())
B = []
flag0 = 0
for q in range(n):
	A = list(map(int, input().split()))
	B.append(A)
for q in range(300):
	C = B.copy()
	a = q + 1
	while a != 0:
		E = []
		D = []
		flag = 0
		b = a % 10
		a = a // 10
		f = 0
		for w in range(n):
			if b in C[w]:
				f = f + 1
				D.append(w)
		if f == 0:
			flag0 = 1
			break
		elif f == 1:
			C[D[0]] = []
		elif f == 2:
			E.append(D.copy())
			count = 0
			for l in range(len(E) - 1):
				if E[l] == E[l + 1]:
					count == count + 1
			if count >= 3:
				flag0 = 1
				break
	if flag0 == 1:
		print(q)
		break


cube = []
n = int(input())
for i in range(n):
	cube.append(list(map(int, input().split())))
val = [0] * 1000
used = [0] * n

def dfs(used_num, num):
	val[num] = 1
	if used_num >= n:
		return
	for i in range(n):
		if used[i]:
			continue
		for j in range(6):
			used[i] = 1
			dfs(used_num + 1, num * 10 + cube[i][j])
			used[i] = 0
dfs(0, 0)
print(val.index(0) - 1)


def ch(x, t):
	if s[x].find(str(t)) == -1:
		return 0
	else:
		return 1
n = int(input())
s = []
s.append(input())
s.append(input() if n > 1 else '')
s.append(input() if n == 3 else '')
for i in range(1, 999):
	if i < 10:
		if (s[0] + s[1] + s[2]).find(str(i)) == -1:
			print(i - 1)
			exit(0)
	if i > 9 and i < 100:
		if not (ch(0, i // 10) * ch(1, i % 10) or ch(1, i // 10) * ch(0, i % 10) or ch(0, i // 10) * ch(2, i % 10) or ch(2, i // 10) * ch(0, i % 10) or ch(1, i // 10) * ch(2, i % 10) or ch(2, i // 10) * ch(1, i % 10)):
			print(i - 1)
			exit(0)
	if i > 99:
		if not (ch(0, i // 100) * ch(1, i % 100 // 10) * ch(2, i % 10) or ch(0, i // 100) * ch(2, i % 100 // 10) * ch(1, i % 10) or ch(1, i // 100) * ch(0, i % 100 // 10) * ch(2, i % 10) or ch(1, i // 100) * ch(2, i % 100 // 10) * ch(0, i % 10) or ch(2, i // 100) * ch(0, i % 100 // 10) * ch(1, i % 10) or ch(2, i // 100) * ch(1, i % 100 // 10) * ch(0, i % 10)):
			print(i - 1)
			exit(0)


import itertools

def main():
	n = int(input())
	l7 = [(int(x), i) for i in range(1, n + 1) for x in input().split()]
	l7ily = set()
	for p in range(1, n + 1):
		for x in itertools.permutations(l7, p):
			count = set()
			s = ''
			for xi in x:
				s += str(xi[0])
				count.add(xi[1])
			if len(count) == p:
				l7ily.add(int(s))
	for lah in range(1, 1000):
		if not lah in l7ily:
			print(lah - 1)
			return
	else:
		print(999)
main()


n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
for ai in a:
	ai.insert(0, '')
dic = {}
for k in range(1, 7 ** n):
	tmp = k
	i = 0
	arr = []
	while 0 < tmp:
		arr.append(str(a[i][tmp % 7]))
		tmp //= 7
		i += 1
	arr.sort()
	dic[''.join(arr)] = True
ans = 0
while ''.join(sorted(list(str(ans + 1)))) in dic:
	ans += 1
print(ans)


while True:
	try:
		n = int(input())
	except:
		break
	lst = []
	for i in range(n):
		inpt = input()
		lst.append([int(x) for x in inpt.split()])
	num = [0] * 100
	for raw in lst:
		for i in raw:
			num[i] += 1
	for rawi in lst:
		for rawj in lst:
			if rawi == rawj:
				continue
			for i in rawi:
				for j in rawj:
					num[i * 10 + j] += 1
	for i in range(1, num.__len__()):
		if num[i] == 0:
			print(i - 1)
			break


n = int(input())
data = [[0] * 6 for i in range(n)]
for i in range(n):
	data[i] = list(map(int, input().split()))
mb = set()
for i in range(n):
	for j in range(6):
		mb.add(data[i][j])
for i in range(n):
	for j in range(n):
		for k in range(6):
			for k2 in range(6):
				if i != j:
					mb.add(data[i][k] * 10 + data[j][k2])
					mb.add(data[i][k] + data[j][k2] * 10)
if n == 3:
	for k1 in range(6):
		for k2 in range(6):
			for k3 in range(6):
				mb.add(data[0][k] * 100 + data[1][k2] * 10 + data[2][k3])
				mb.add(data[0][k] * 100 + data[1][k2] + data[2][k3] * 10)
				mb.add(data[0][k] * 10 + data[1][k2] * 100 + data[2][k3])
				mb.add(data[0][k] + data[1][k2] * 100 + data[2][k3] * 10)
				mb.add(data[0][k] * 10 + data[1][k2] + data[2][k3] * 100)
				mb.add(data[0][k] + data[1][k2] * 10 + data[2][k3] * 100)
i = 1
while i in mb:
	i += 1
print(i - 1)


d = []
n = int(input())

class dice:

	def __init__(self, line):
		s = line.split()
		self.a = []
		for i in range(6):
			self.a.append(int(s[i]))
		self.l = 6

def isValid(x):
	if x < 10:
		for cur in d:
			for i in cur.a:
				if x == i:
					return True
	elif x < 100:
		for i in range(n):
			for p in d[i].a:
				for j in range(n):
					if i == j:
						continue
					for q in d[j].a:
						y = p * 10 + q
						if x == y:
							return True
	else:
		for i in range(n):
			for j in range(n):
				if i != j:
					for k in range(n):
						if k != i and k != j:
							for p in d[i].a:
								for q in d[j].a:
									for r in d[k].a:
										y = 100 * p + 10 * q + r
										if x == y:
											return True
	return False
for i in range(n):
	d.append(dice(input()))
ans = 0
for i in range(1, 1000):
	if isValid(i):
		ans = i
	else:
		break
print(i - 1)


def main():
	n = int(input())
	l = []
	for i in range(n):
		l.append(list(map(int, input().split())))
	a = [[(0,)], [(0,), (1,)], [(0,), (1,), (2,)]]
	d = 1
	while d <= 9:
		ds = [d]
		flag = False
		for i in a[n - 1]:
			flag2 = True
			for j in range(1):
				if ds[j] not in l[i[j]]:
					flag2 = False
					break
			if flag2:
				flag = True
				break
		if not flag:
			return d - 1
		d += 1
	a = [[], [(0, 1), (1, 0)], [(0, 1), (0, 2), (1, 0), (1, 2), (2, 0), (2, 1)]]
	d = 10
	while d <= 99:
		ds = [d // 10, d % 10]
		flag = False
		for i in a[n - 1]:
			flag2 = True
			for j in range(2):
				if ds[j] not in l[i[j]]:
					flag2 = False
					break
			if flag2:
				flag = True
				break
		if not flag:
			return d - 1
		d += 1
	a = [[], [], [(0, 1, 2), (0, 2, 1), (1, 0, 2), (1, 2, 0), (2, 0, 1), (2, 1, 0)]]
	d = 100
	while d <= 999:
		ds = [d // 100, d // 10 % 10, d % 10]
		flag = False
		for i in a[n - 1]:
			flag2 = True
			for j in range(3):
				if ds[j] not in l[i[j]]:
					flag2 = False
					break
			if flag2:
				flag = True
				break
		if not flag:
			return d - 1
		d += 1
print(main())


n = int(input())
cubes = [set() for i in range(10)]
for i in range(n):
	for n in sorted(list(map(int, input().split()))):
		cubes[n].add(i)
for curr in range(1, 100):
	str_curr = str(curr)
	if len(str_curr) == 1:
		if len(cubes[curr]) == 0:
			print(curr - 1)
			break
	else:
		d1 = int(str_curr[0])
		d2 = int(str_curr[1])
		if len(cubes[d2]) == 0 or len(cubes[d1].union(cubes[d2])) == 1:
			print(curr - 1)
			break


n = int(input())
a = [[int(x) for x in input().split()] for _ in range(n)]

def can(x):
	ss = [str(x)]
	if not ss[0].startswith('0'):
		ss = [''.join(reversed(ss[0])), ss[0]]
	for s in ss:
		was = [False] * n
		for i in s:
			for c in range(n):
				if was[c]:
					continue
				if int(i) in a[c]:
					was[c] = True
					break
			else:
				break
		else:
			return True
for i in range(1, 100):
	if not can(i):
		print(i - 1)
		exit(0)


import sys, os
from io import BytesIO, IOBase
import collections, itertools, bisect, heapq, math, string
from decimal import *
BUFSIZE = 8192
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')

def main():
	n = int(input())
	a = []
	used = []
	for i in range(n):
		x = list(input().split())
		a.append(x)
		for _ in range(6):
			used.append(x[_])
	if n == 2:
		for z in range(6):
			for k in range(6):
				s = a[0][z] + a[1][k]
				if s not in used:
					used.append(s)
					used.append(s[::-1])
	if n > 2:
		for z in range(3):
			for g in range(6):
				for v in range(6):
					s = a[z][g] + a[(z + 1) % 3][v]
					if s not in used:
						used.append(s)
						used.append(s[::-1])
		for j in range(6):
			for k in range(6):
				for p in range(6):
					s = a[0][j] + a[1][k] + a[2][p]
					if s not in used:
						used.append(s)
						used.append(s[::-1])
	used = sorted(list(set(map(int, used))))
	if 0 in used:
		del used[used.index(0)]
	if used.count(1) > 0:
		for q in range(len(used)):
			if used[q] != q + 1:
				print(q)
				exit()
		print(used[-1])
	else:
		print(0)
main()


import sys
n = int(input())
a = []
b = []
for i in range(n):
	tem = list(map(int, input().strip().split()))
	a.append(tem)
	b.extend(tem)
k = 0
for i in range(1, 10):
	if i in b:
		k = k + 1
	else:
		print(k)
		sys.exit()
k = a
if n == 2:
	k.append(a[0])
else:
	k.append(a[0])
	k.append(a[1])
for i in range(10, 100):
	t1 = i // 10
	t2 = i % 10
	looped = False
	for j in range(len(k) // 2 + 1):
		if n == 2:
			if t1 in k[j] and t2 in k[j + 1]:
				looped = True
		elif t1 in k[j] and (t2 in k[j + 1] or t2 in k[j + 2]):
			looped = True
	if looped == False:
		print(i - 1)
		sys.exit()
print(0)


import itertools
n = int(input())
l = [set(input().split()) for _ in range(n)]
x = 0
for i in range(1, 1000):
	s = str(i)
	ok = False
	for p in itertools.permutations((0, 1, 2), len(s)):
		if max(p) >= n:
			continue
		f = True
		for j in range(len(p)):
			if not s[j] in l[p[j]]:
				f = False
				break
		if f:
			ok = True
			break
	if ok:
		x = i
	else:
		break
print(x)


from itertools import permutations
n = int(input())
m = 0
lis = [0 for _ in range(1000)]
lis[0] = 1
a = []
for _ in range(n):
	s = input().split()
	for i in s:
		lis[int(i)] = 1
	a.append(s)
if n == 3:
	for i in a[0]:
		for j in a[1]:
			for k in a[2]:
				l = permutations([i, j, k], 3)
				for item in l:
					lis[int(item[0] + item[1] + item[2])] = 1
				l = permutations([i, j, k], 2)
				for item in l:
					lis[int(item[0] + item[1])] = 1
elif n == 2:
	for i in a[0]:
		for j in a[1]:
			l = permutations([i, j], 2)
			for item in l:
				lis[int(item[0] + item[1])] = 1
ind = lis.index(0) - 1
print(ind)


n = int(input())
A = []
poss = []
for i in range(0, n):
	A = A + input().split()
for i in range(0, n):
	for j in range(0, 6):
		if int(A[6 * i + j]) == 0:
			a = 0
		else:
			poss = poss + [int(A[6 * i + j])]
for i in range(0, n):
	for j in range(0, n):
		if i == j:
			a = 0
		else:
			for k in range(0, 6):
				for l in range(0, 6):
					if int(A[6 * i + k]) == 0:
						a = 0
					else:
						poss = poss + [int(A[6 * i + k]) * 10 + int(A[6 * j + l])]
for i in range(0, n):
	for j in range(0, n):
		for k in range(0, n):
			if i == j:
				a = 0
			if j == k:
				a = 0
			if k == i:
				a = 0
			else:
				for l in range(0, 6):
					for m in range(0, 6):
						for p in range(0, 6):
							if int(A[6 * i + l]) == 0:
								a = 0
							else:
								poss = poss + [int(A[6 * i + l]) * 100 + int(A[6 * j + m]) * 10 + int(A[6 * k + p])]

def high(S):
	x = 1
	while True:
		if not x in S:
			return x - 1
		else:
			x += 1
print(high(poss))


q = int(input())
a = [False for i in range(0, 1002)]
s = []
for i in range(0, q):
	s.append(list(map(int, input().split())))
for i in s:
	for j in i:
		a[j] = True
if q == 2:
	for i in s[0]:
		for j in s[1]:
			(a[i * 10 + j], a[j * 10 + i]) = (True, True)
if q == 3:
	for i in s[0]:
		for j in s[1]:
			(a[i * 10 + j], a[j * 10 + i]) = (True, True)
	for i in s[0]:
		for j in s[2]:
			(a[i * 10 + j], a[j * 10 + i]) = (True, True)
	for i in s[1]:
		for j in s[2]:
			(a[i * 10 + j], a[j * 10 + i]) = (True, True)
	for i in s[0]:
		for j in s[1]:
			for k in s[2]:
				(a[k * 100 + i * 10 + j], a[k * 100 + j * 10 + i]) = (True, True)
				(a[k * 10 + i * 100 + j], a[k + j * 10 + i * 100]) = (True, True)
				(a[k + i * 10 + j * 100], a[k * 10 + i + j * 100]) = (True, True)
z = 0
while a[z + 1]:
	z += 1
print(z)


n = int(input())
arr = []
for i in range(n):
	tmp = []
	x = input()
	x = x.split()
	for j in range(6):
		tmp.append(int(x[j]))
	arr.append(tmp)

def ans(arr):
	a = set()

	def helper1(i):
		for x in arr[i]:
			if x not in a:
				a.add(x)

	def helper2(i, j):
		for x in arr[i]:
			if x not in a:
				a.add(x)
			for y in arr[j]:
				if y not in a:
					a.add(y)
				if x * 10 + y not in a:
					a.add(x * 10 + y)
				if y * 10 + x not in a:
					a.add(y * 10 + x)

	def helper3(i, j, k):
		for x in arr[i]:
			for y in arr[j]:
				for z in arr[k]:
					if x * 100 + y * 10 + z not in a:
						a.add(x * 100 + y * 10 + z)
					if y * 100 + z * 10 + x not in a:
						a.add(y * 100 + z * 10 + x)
					if z * 100 + x * 10 + y not in a:
						a.add(z * 100 + x * 10 + y)
	if len(arr) == 1:
		helper1(0)
	if len(arr) == 2:
		helper2(0, 1)
	if len(arr) == 3:
		helper2(0, 1)
		helper2(0, 2)
		helper2(1, 2)
		helper3(0, 1, 2)
	if 1 not in a:
		return 0
	for i in range(2, 101):
		if i not in a:
			return i - 1
print(ans(arr))


n = int(input())
A = set()
B = set()
C = set()
for i in range(n):
	s = input().split()
	for item in s:
		if i == 0:
			A.add(int(item))
		if i == 1:
			B.add(int(item))
		if i == 2:
			C.add(int(item))
key = 0
for i in range(1, 1000):
	flag = False
	for item in A:
		if item == i:
			flag = True
			break
	if not flag:
		for item in B:
			if item == i:
				flag = True
				break
	if not flag:
		for item in C:
			if item == i:
				flag = True
				break
	if not flag:
		for item1 in A:
			for item2 in B:
				if item1 * 10 + item2 == i or item2 * 10 + item1 == i:
					flag = True
					break
	if not flag:
		for item1 in A:
			for item2 in C:
				if item1 * 10 + item2 == i or item2 * 10 + item1 == i:
					flag = True
					break
	if not flag:
		for item1 in B:
			for item2 in C:
				if item1 * 10 + item2 == i or item2 * 10 + item1 == i:
					flag = True
					break
	if not flag:
		for item1 in A:
			for item2 in B:
				for item3 in C:
					if item1 * 100 + item2 * 10 + item3 == i or item1 * 100 + item3 * 10 + item2 == i or item2 * 100 + item1 * 10 + item3 == i or (item2 * 100 + item3 * 10 + item1 == i) or (item3 * 100 + item1 * 10 + item2 == i) or (item3 * 100 + item2 * 10 + item1 == i):
						flag = True
						break
	if not flag:
		print(key)
		break
	if flag:
		key += 1


import itertools
n = int(input())
cubes = []
for i in range(n):
	cubes.append(input().split())
canMake = set()
for positions in itertools.combinations_with_replacement([0, 1, 2, 3, 4, 5], n):
	words = []
	for truePos in itertools.permutations(positions):
		word = ''
		for i in range(n):
			word += cubes[i][truePos[i]]
		words.append(word)
	for word in words:
		for i in range(n):
			for comb in itertools.permutations(word, i + 1):
				canMake.add(int(''.join(comb)))
for i in range(1, 1000):
	if i not in canMake:
		break
print(i - 1)


n = int(input())
d = {}
for val in range(10):
	d[val] = []
for i in range(n):
	for val in input().strip().split():
		if len(d[int(val)]) <= i:
			d[int(val)].append(i)
for j in range(1, 1001):
	num = j
	found = False
	temp = []
	c = 0
	while num > 0:
		rem = num % 10
		c += 1
		if len(d[rem]) > 0:
			for val in d[rem]:
				temp.append(val)
		else:
			break
		num //= 10
	if num == 0 and len(set(temp)) >= c:
		found = True
	if not found:
		print(j - 1)
		break


n = int(input())
a = []

def v2(n, l):
	n = str(n)
	if len(n) == 1:
		if not (int(n) in l[0] or int(n) in l[1]):
			return int(n) - 1
		return -1
	elif len(n) == 2:
		if not (int(n[0]) in l[0] and int(n[1]) in l[1] or (int(n[1]) in l[0] and int(n[0]) in l[1])):
			return int(n) - 1
		return -1

def v3(n, l):
	n = str(n)
	if len(n) == 1:
		if not (int(n) in l[0] or int(n) in l[1] or int(n) in l[2]):
			return int(n) - 1
		return -1
	elif len(n) == 2:
		if not (int(n[0]) in l[0] and int(n[1]) in l[1] or (int(n[0]) in l[0] and int(n[1]) in l[2] or (int(n[0]) in l[1] and int(n[1]) in l[2]) or (int(n[0]) in l[1] and int(n[1]) in l[0]) or (int(n[0]) in l[2] and int(n[1]) in l[0]) or (int(n[0]) in l[2] and int(n[1]) in l[1]))):
			return int(n) - 1
		return -1
	else:
		if not (int(n[0]) in l[0] and int(n[1]) in l[1] and (int(n[2]) in l[2]) or (int(n[0]) in l[0] and int(n[1]) in l[2] and (int(n[2]) in l[1])) or (int(n[0]) in l[1] and int(n[1]) in l[0] and (int(n[2]) in l[2])) or (int(n[0]) in l[1] and int(n[1]) in l[2] and (int(n[2]) in l[0])) or (int(n[0]) in l[2] and int(n[1]) in l[0] and (int(n[2]) in l[1])) or (int(n[0]) in l[2] and int(n[1]) in l[1] and (int(n[2]) in l[0]))):
			return int(n) - 1
		return -1
for i in range(n):
	r = 0
	l = list(map(int, input().split()))
	a.append(l)
if n == 1:
	for i in range(1, 9):
		if not i in a[0]:
			print(i - 1)
			break
elif n == 2:
	for i in range(1, 100):
		if v2(i, a) != -1:
			print(v2(i, a))
			break
else:
	for i in range(1, 1000):
		if v3(i, a) != -1:
			print(v3(i, a))
			break


n = int(input())
v = []
for i in range(n):
	v.append(list(map(int, input().split())))
l = []
for i in v[0]:
	l.append(i)
	if n > 1:
		for j in v[1]:
			l.append(j)
			if n > 2:
				for q in v[2]:
					l.append(q)
					l.append(q * 10 + j)
					l.append(j * 10 + q)
					l.append(q * 10 + i)
					l.append(i * 10 + q)
			l.append(j * 10 + i)
			l.append(i * 10 + j)
i = 1
while i in l:
	i += 1
print(i - 1)


n = int(input())
sum = set()
r = [0] * n
for i in range(n):
	r[i] = set(input().split())
	sum = sum | r[i]
r.append(set([44]))
r.append(set([44]))
for i in range(1, 10):
	p = str(i)
	if p not in sum:
		print(i - 1)
		break
else:
	a = r[0]
	b = r[1]
	c = r[2]
	ab = a | b
	ac = a | c
	bc = b | c
	for i in range(10, 100):
		p = str(i)
		if not (p[0] in a and p[1] in bc or (p[0] in b and p[1] in ac) or (p[0] in c and p[1] in ab)):
			print(i - 1)
			break
	else:
		for i in range(100, 1000):
			p = str(i)
			if not (p[0] in a and p[1] in b and (p[2] in c) or (p[0] in a and p[2] in b and (p[1] in c)) or (p[1] in a and p[0] in b and (p[2] in c)) or (p[1] in a and p[2] in b and (p[0] in c)) or (p[2] in a and p[0] in b and (p[1] in c)) or (p[2] in a and p[1] in b and (p[0] in c))):
				print(i - 1)
				break


def able(x, exceptCubes=None):
	if not type(x) is list:
		x = list(map(int, list(str(x))))
	if len(x) == 0:
		return True
	if exceptCubes is None:
		exceptCubes = set()
	for cube in cubes - exceptCubes:
		if x[0] in cube:
			newExceptCubes = exceptCubes.copy()
			newExceptCubes.add(cube)
			if able(x[1:], newExceptCubes):
				return True
	return False
n = int(input())
cubes = {frozenset(map(int, input().split())) for __ in range(n)}
number = 1
while True:
	if able(number):
		number += 1
	else:
		print(number - 1)
		exit()


def is_possible1(i, cubes):
	for cube in cubes:
		for c in cube:
			if int(c) == i:
				return True
	return False

def is_possible2(i, cubes):
	if len(cubes) < 2:
		return False
	for (j, cube) in enumerate(cubes):
		if str(i)[0] in cube:
			for (k, cube2) in enumerate(cubes):
				if j != k and str(i)[1] in cube2:
					return True
	return False

def is_possible3(i, cubes):
	if len(cubes) < 3:
		return False
	for (j, cube) in enumerate(cubes):
		if str(i)[0] in cube:
			for (k, cube2) in enumerate(cubes):
				if j != k and str(i)[1] in cube2:
					for (l, cube3) in enumerate(cubes):
						if l != j and l != k and (j != k) and (str(i)[2] in cube3):
							return True
	return False

def is_possible(i, cubes):
	if len(str(i)) == 1:
		return is_possible1(i, cubes)
	if len(str(i)) == 2:
		return is_possible2(i, cubes)
	if len(str(i)) == 3:
		return is_possible3(i, cubes)
n = int(input())
cubes = []
for i in range(n):
	cubes.append(input().split())
flat_cubes = [c for cube in cubes for c in cube]
if '1' not in flat_cubes:
	print(0)
else:
	i = 1
	while is_possible(i, cubes):
		i += 1
	print(i - 1)


n = int(input())
l = []
vv = []
for i in range(n):
	s = input().split()
	s = [int(s[i]) for i in range(len(s))]
	l.append(set(s))
	vv = vv + s
g = set(vv)

def f1(v, i):
	s = str(i)
	for j in range(len(s)):
		if int(s[j]) not in v:
			return False
	return True

def v(l, i):
	return [i in l[j] for j in range(len(l))]

def r(l, i):
	s = str(i)
	t = []
	for j in range(len(s)):
		t.append(v(l, int(s[j])))
	return t

def verif(l, n):
	t = []
	for j in range(n):
		v = False
		for i in range(len(l)):
			v = v or l[i][j]
		t.append(v)
	return t
for i in range(1, 999):
	if f1(vv, i) == True:
		t = r(l, i)
		h = verif(t, n)
		if i < 10:
			if h.count(True) < 1:
				print(i - 1)
				break
		elif i < 100:
			if h.count(True) < 2:
				print(i - 1)
				break
		elif h.count(True) < 3:
			print(i - 1)
			break
	else:
		print(i - 1)
		break
if i == 998:
	t = r(l, i + 1)
	h = verif(t, n)
	if h.count(True) < 3:
		print(i)
	else:
		print(i + 1)


from itertools import permutations

def parse(n):
	l = list()
	while n > 0:
		l.append(n % 10)
		n = n // 10
	return l

def check(per, n):
	for i in range(len(per)):
		ok = True
		for j in range(len(n)):
			if n[j] not in per[i][j]:
				ok = False
		if ok == True:
			return True
	return False
l = list()
for _ in range(int(input())):
	l.append(list(map(int, input().split())))
per = list(permutations(l))
for i in range(1, 100):
	if not check(per, parse(i)):
		print(i - 1)
		break


dice = [[int(x) for x in input().split()] for i in range(int(input()))]
doable = [False] * 100
for dice1 in dice:
	for face1 in dice1:
		doable[face1] = True
	for dice2 in dice:
		if dice1 is dice2:
			continue
		for face1 in dice1:
			for face2 in dice2:
				doable[10 * face1 + face2] = True
for i in range(1, 100):
	if not doable[i]:
		print(i - 1)
		break


n = int(input())
a = []
ans = n
for i in range(n):
	a.append(list(map(int, input().split())))
mx_arr = []
for i in a:
	mx_arr.append(max(i))
mx_arr.sort()
mx_arr.reverse()
mx = ''
for i in mx_arr:
	mx += str(i)
mx = int(mx)
if mx == 0:
	print(0)
else:
	for i in range(1, mx + 1):
		if n == 3:
			if len(str(i)) == 3:
				nice = False
				n1 = int(str(i)[0])
				n2 = int(str(i)[1])
				n3 = int(str(i)[2])
				if n1 in a[0] and n2 in a[1] and (n3 in a[2]) and (n1 != 0):
					nice = True
				elif n1 in a[0] and n2 in a[2] and (n3 in a[1]) and (n1 != 0):
					nice = True
				elif n1 in a[1] and n2 in a[0] and (n3 in a[2]) and (n1 != 0):
					nice = True
				elif n1 in a[1] and n2 in a[2] and (n3 in a[0]) and (n1 != 0):
					nice = True
				elif n1 in a[2] and n2 in a[0] and (n3 in a[1]) and (n1 != 0):
					nice = True
				elif n1 in a[2] and n2 in a[1] and (n3 in a[0]) and (n1 != 0):
					nice = True
				if nice is False:
					print(max(0, i - 1))
					exit()
			elif len(str(i)) == 2:
				nice = False
				n1 = int(str(i)[0])
				n2 = int(str(i)[1])
				if n1 in a[0] and n2 in a[1] and (n1 != 0):
					nice = True
				elif n1 in a[0] and n2 in a[2] and (n1 != 0):
					nice = True
				elif n1 in a[1] and n2 in a[0] and (n1 != 0):
					nice = True
				elif n1 in a[1] and n2 in a[2] and (n1 != 0):
					nice = True
				elif n1 in a[2] and n2 in a[1] and (n1 != 0):
					nice = True
				elif n1 in a[2] and n2 in a[0] and (n1 != 0):
					nice = True
				if nice is False:
					print(max(0, i - 1))
					exit()
			else:
				nice = False
				n1 = int(str(i)[0])
				if n1 in a[0] or n1 in a[1] or n1 in a[2]:
					nice = True
				if nice is False:
					print(max(0, i - 1))
					exit()
		elif n == 2:
			if len(str(i)) == 2:
				nice = False
				n1 = int(str(i)[0])
				n2 = int(str(i)[1])
				if n1 in a[0] and n2 in a[1] and (n1 != 0):
					nice = True
				elif n1 in a[1] and n2 in a[0] and (n1 != 0):
					nice = True
				if nice is False:
					print(max(0, i - 1))
					exit()
			else:
				nice = False
				n1 = int(str(i)[0])
				if n1 in a[0] or n1 in a[1]:
					nice = True
				if nice is False:
					print(max(0, i - 1))
					exit()
		elif len(str(i)) == 1:
			nice = False
			n1 = int(str(i)[0])
			if n1 in a[0]:
				nice = True
			if nice is False:
				print(max(0, i - 1))
				exit()
	print(mx)


n = int(input())
cubes = [0] * n
for i in range(n):
	cubes[i] = list(map(int, input().split(' ')))

def find1(i, s):
	for j in range(len(s)):
		if i in s[j]:
			return True
	return False

def find2(a, b, s):
	for j in range(len(s)):
		if a in s[j] and find1(b, s[:j] + s[j + 1:]):
			return True
	return False

def find3(a, b, c, s):
	for j in range(len(s)):
		if a in s[j] and find2(b, c, s[:j] + s[j + 1:]):
			return True
	return False
for i in range(10 ** n):
	a = i // 100
	b = (i - 100 * a) // 10
	c = (i - 100 * a) % 10
	if a and (not find3(a, b, c, cubes)):
		break
	elif b and (not find2(b, c, cubes)):
		break
	elif c and (not find1(c, cubes)):
		break
print(max(i - 1, 0))


n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
if n == 1:
	avail = set(a[0])
elif n == 2:
	avail = set(a[0] + a[1])
	avail = avail.union({i * 10 + j for i in a[0] for j in a[1]})
	avail = avail.union({i * 10 + j for i in a[1] for j in a[0]})
else:
	avail = set(a[0] + a[1] + a[2])
	avail = avail.union({i * 10 + j for i in a[0] for j in a[1]})
	avail = avail.union({i * 10 + j for i in a[1] for j in a[0]})
	avail = avail.union({i * 10 + j for i in a[0] for j in a[2]})
	avail = avail.union({i * 10 + j for i in a[2] for j in a[0]})
	avail = avail.union({i * 10 + j for i in a[2] for j in a[1]})
	avail = avail.union({i * 10 + j for i in a[1] for j in a[2]})
	for c in [[0, 1, 2], [0, 2, 1], [1, 0, 2], [1, 2, 0], [2, 0, 1], [2, 1, 0]]:
		avail = avail.union({i * 100 + j * 10 + k for i in a[c[0]] for j in a[c[1]] for k in a[c[2]]})
for i in range(1, 1000):
	if i not in avail:
		print(i - 1)
		exit()
print(999)


def list_input():
	return list(map(int, input().split()))
n = int(input())
c = list()
for i in range(n):
	c.append(list_input())
s = set()
for i in range(n):
	for x in c[i]:
		s.add(x)
if n >= 2:
	for i in range(n):
		for j in range(n):
			if i == j:
				continue
			for x in c[i]:
				for y in c[j]:
					if x != 0:
						s.add(x * 10 + y)
if n >= 3:
	for i in range(n):
		for j in range(n):
			if i == j:
				continue
			for k in range(n):
				if i == k or j == k:
					continue
				for x in c[i]:
					for y in c[j]:
						for z in c[k]:
							if x != 0:
								s.add(x * 100 + y * 10 + z)
if 0 in s:
	s.remove(0)
res = 0
for x in s:
	if x == res + 1:
		res += 1
	else:
		print(res)
		exit(0)
print(res)


num = [[0 for i in range(6)] for j in range(3)]
value = [0 for i in range(1000)]
vis = [0 for i in range(3)]

def dfs(ant, no):
	value[no] = 1
	global n
	if ant > n:
		return
	for i in range(n):
		if vis[i]:
			continue
		for j in range(6):
			vis[i] = 1
			dfs(ant + 1, no * 10 + num[i][j])
			vis[i] = 0

def main():
	global n
	n = int(input())
	for i in range(n):
		v = list(map(int, input().split()))
		for j in range(6):
			num[i][j] = v[j]
	dfs(0, 0)
	for i in range(1, 1000):
		if not value[i]:
			print(i - 1)
			break
main()


from sys import stdin

def inc(x):
	x[-1] += 1
	for i in range(len(x) - 1, 0, -1):
		if x[i] >= 10:
			x[i] = 0
			x[i - 1] += 1

def to_s(x):
	return ''.join([str(d) for d in x])

def have_cubes(x, nums):
	if len(nums) == 0:
		return False
	if len(x) == 1:
		for c in nums:
			if x[0] in c:
				return True
		return False
	else:
		for (i, c) in enumerate(nums):
			if x[0] in c:
				if have_cubes(x[1:], nums[:i] + nums[i + 1:]):
					return True
		return False

def main():
	n = int(stdin.readline())
	nums = []
	for i in range(n):
		nums.append([int(t) for t in stdin.readline().split()])
	x = [0, 0, 0]
	res = '0'
	for i in range(1, 1000):
		inc(x)
		if i < 10:
			st = 2
		elif i < 100:
			st = 1
		else:
			st = 0
		if not have_cubes(x[st:], nums):
			break
		res = to_s(x[st:])
	return res
print(main())


def check(k):
	if k < 10:
		return k in bricks[0] or k in bricks[1] or k in bricks[2]
	else:
		first = k // 10
		second = k % 10
		if first in bricks[0] and (second in bricks[1] or second in bricks[2]) or (first in bricks[1] and (second in bricks[0] or second in bricks[2])) or (first in bricks[2] and (second in bricks[0] or second in bricks[1])):
			return True
		return False
n = int(input())
bricks = []
for _ in range(n):
	bricks.append(set(map(int, input().split())))
if n == 2:
	bricks.append(set())
elif n == 1:
	bricks.append(set())
	bricks.append(set())
for i in range(1, 100):
	if not check(i):
		print(i - 1)
		exit(0)


n = int(input())
lst = []
for x in range(n):
	lst.append([])
for x in range(n):
	spisok = list(map(int, input().split()))
	lst[x] = spisok
a = []
if n != 1:
	for x in range(n - 1):
		for y in range(x + 1, n):
			for i in lst[x]:
				for z in lst[y]:
					a.append(int(str(i) + str(z)))
					a.append(int(str(z) + str(i)))
b = []
if n == 3:
	for x in range(len(a)):
		if x < 72:
			for y in lst[2]:
				b.append(int(str(a[x]) + str(y)))
				b.append(int(str(y) + str(a[x])))
		elif x < 144 and x >= 72:
			for y in lst[1]:
				b.append(int(str(a[x]) + str(y)))
				b.append(int(str(y) + str(a[x])))
		else:
			for y in lst[0]:
				b.append(int(str(a[x]) + str(y)))
				b.append(int(str(y) + str(a[x])))
for x in range(n):
	for y in lst[x]:
		a.append(y)
a += b
a = set(a)
t = True
k = 1
while t:
	if k in a:
		k += 1
	else:
		t = False
print(k - 1)


def f(x, y):
	for i in x:
		for j in y:
			ans[i * 10 + j] = True

def g(x, y, z):
	for i in x:
		for j in y:
			for k in z:
				ans[i * 100 + j * 10 + k] = True
ans = [True]
for i in range(1000):
	ans.append(False)
n = int(input())
a = []
for i in range(n):
	a.append([])
	s = str(input()).split()
	for j in range(6):
		a[i].append(int(s[j]))
for i in range(n):
	for j in range(6):
		ans[a[i][j]] = True
for i in range(n):
	for j in range(n):
		if i != j:
			f(a[i], a[j])
for i in range(n):
	for j in range(n):
		for k in range(n):
			if (i - j) * (j - k) * (k - i) != 0:
				g(a[i], a[j], a[k])
for i in range(len(ans)):
	if not ans[i]:
		print(i - 1)
		break


cubes_sets = [set(), set(), set()]

def myor(smlist):
	buff_list = [0, 0, 0]
	for x in smlist:
		for y in range(3):
			buff_list[y] = max(x[y], buff_list[y])
	return buff_list

def mycount(strnum):
	global cubes_sets
	buff_cubes = cubes_sets
	buffl = [[0, 0, 0]] * len(strnum)
	for (x, y) in enumerate(list(strnum)):
		if y in buff_cubes[0]:
			buffl[x][0] = 1
		if y in buff_cubes[1]:
			buffl[x][1] = 1
		if y in buff_cubes[2]:
			buffl[x][2] = 1
		if not (y in buff_cubes[2] or y in buff_cubes[1] or y in buff_cubes[0]):
			return [[0, 0, 0]] * len(strnum)
	return buffl

def can_make(num):
	buff_num = str(num)
	global cubes_sets
	buff_cubes = cubes_sets
	if len(buff_num) == 1:
		if buff_num in cubes_sets[0] or buff_num in cubes_sets[1] or buff_num in cubes_sets[2]:
			return True
	elif len(buff_num) == 2:
		inn = mycount(buff_num)
		if sum(myor(inn)) >= 2:
			return True
	elif len(buff_num) == 3:
		inn = inn = mycount(buff_num)
		if sum(myor(inn)) == 3:
			return True
		return False

def main():
	global cubes_sets
	n = int(input())
	for x in range(n):
		cubes_sets[x] = set(input().split())
	lastn = 0
	for x in range(1, 1000):
		if can_make(x):
			lastn = x
			continue
		else:
			return lastn
print(main())


import sys
n = int(input())
a = [[], [], []]
for i in range(n):
	a[i] = list(map(int, input().split()))
k = a
i = 1
while 1:
	r = str(i)
	d = []
	g = 0
	y = 0
	for j in r:
		for m in range(3):
			if int(j) in a[m] and m not in d:
				g = m
				d.append(g)
				y = m
				break
		else:
			d = []
			g = 0
			y = 0
			for z in r:
				for t in range(1, 4):
					if int(z) in a[3 - t] and 3 - t not in d:
						g = 3 - t
						d.append(g)
						y = 3 - t
						break
				else:
					print(i - 1)
					sys.exit()
			break
	i += 1


n = int(input())
cnt = True
a = []
Mark = []
for i in range(0, n):
	a.append(list(input().split()))
if n == 1:
	for i in range(0, 6):
		Mark.append(a[0][i])
elif n == 3:
	for i in range(0, 6):
		for j in range(0, 6):
			for p in range(0, 6):
				Mark.append(a[0][i])
				Mark.append(a[1][j])
				Mark.append(a[2][p])
				Mark.append(a[0][i] + a[1][j])
				Mark.append(a[0][i] + a[2][p])
				Mark.append(a[1][j] + a[2][p])
				Mark.append(a[1][j] + a[0][i])
				Mark.append(a[2][p] + a[0][i])
				Mark.append(a[2][p] + a[1][j])
				Mark.append(a[0][i] + a[1][j] + a[2][p])
				Mark.append(a[0][i] + a[2][p] + a[1][j])
				Mark.append(a[1][j] + a[2][p] + a[0][i])
				Mark.append(a[1][j] + a[0][i] + a[2][p])
				Mark.append(a[2][p] + a[0][i] + a[1][j])
				Mark.append(a[2][p] + a[1][j] + a[0][i])
else:
	for i in range(0, 6):
		for j in range(0, 6):
			Mark.append(a[0][i])
			Mark.append(a[1][j])
			Mark.append(a[0][i] + a[1][j])
			Mark.append(a[1][j] + a[0][i])
for o in range(0, len(Mark)):
	Mark[o] = int(Mark[o])
Mark.sort()
for i in range(1, Mark[-1]):
	if Mark.count(i) > 0:
		pass
	else:
		print(i - 1)
		cnt = False
		break
if cnt:
	print(Mark[-1])