j=''.join

n=int(eval(input()))

d=j(j(input().split())for i in[0]*(n//19+(n%19!=0)))

i=0

while 1:

 if d.find(str(i))<0:

  print(i)

  exit() 

 i+=1
j=''.join

u=input

n=int(u())

d=j(j(u().split())for i in[0]*(n//19+(n%19!=0)))

i=0

while 1:

 if d.find(str(i))<0:

  print(i)

  exit() 

 i+=1
j = "".join
n = int(eval(input()))
d = j(j(input().split()) for i in [0] * (n // 19 + (n % 19 != 0)))
i = 0
while 1:
    if d.find(str(i)) < 0:
        print(i)
        exit()
    i += 1

j = "".join
u = input
n = int(u())
d = j(j(u().split()) for i in [0] * (n // 19 + (n % 19 != 0)))
i = 0
while 1:
    if d.find(str(i)) < 0:
        print(i)
        exit()
    i += 1

-n = int(eval(input())) -d = j(j(input().split()) for i in [0] * (n // 19 + (n % 19 != 0))) +u = input +n = int(u()) +d = j(j(u().split()) for i in [0] * (n // 19 + (n % 19 != 0)))