n=int(eval(input()))

d=''.join([''.join(input().split())for i in range(n//19+(n%19!=0))])

i=0

while True:

 if d.find(str(i))==-1:

  print(i)

  exit() 

 i+=1
n=int(eval(input()))

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

i=0

while 1:

 if d.find(str(i))==-1:

  print(i)

  exit() 

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

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

-d = "".join(["".join(input().split()) for i in range(n // 19 + (n % 19 != 0))]) +d = "".join("".join(input().split()) for i in [0] * (n // 19 + (n % 19 != 0))) -while True: +while 1: