x, n = list(map(int, input().split()))

s = set(list(map(int, input().split())) if n != 0 else "")



i = 0

while True:

    k = x + i

    if k not in s:

        print(k)

        break



    if i >= 0: i += 1

    i *= -1

x, n = list(map(int, input().split()))

s = set(list(map(int, input().split())) if n != 0 else "")



i = 0

while x + i in s:

    if i >= 0: i += 1

    i *= -1



print((x + i))

x, n = list(map(int, input().split()))
s = set(list(map(int, input().split())) if n != 0 else "")
i = 0
while True:
    k = x + i
    if k not in s:
        print(k)
        break
    if i >= 0:
        i += 1
    i *= -1

x, n = list(map(int, input().split()))
s = set(list(map(int, input().split())) if n != 0 else "")
i = 0
while x + i in s:
    if i >= 0:
        i += 1
    i *= -1
print((x + i))

-while True: -    k = x + i -    if k not in s: -        print(k) -        break +while x + i in s: +print((x + i))