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

Ps = list(map(int, input().split()))



line = [0]*(102)

for p in Ps:

    line[p] = 1



for i in range(101):

    L, R = x-i, x+i

    if line[L] == 0:

        print(L)

        break

    if line[R] == 0:

        print(R)

        break

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

Ps = set(map(int, input().split()))

cood = set(range(0, 102))

cood -= Ps

print((min(cood, key=lambda x: abs(x-X))))
x, n = list(map(int, input().split()))
Ps = list(map(int, input().split()))
line = [0] * (102)
for p in Ps:
    line[p] = 1
for i in range(101):
    L, R = x - i, x + i
    if line[L] == 0:
        print(L)
        break
    if line[R] == 0:
        print(R)
        break

X, n = list(map(int, input().split()))
Ps = set(map(int, input().split()))
cood = set(range(0, 102))
cood -= Ps
print((min(cood, key=lambda x: abs(x - X))))

-x, n = list(map(int, input().split())) -Ps = list(map(int, input().split())) -line = [0] * (102) -for p in Ps: -    line[p] = 1 -for i in range(101): -    L, R = x - i, x + i -    if line[L] == 0: -        print(L) -        break -    if line[R] == 0: -        print(R) -        break +X, n = list(map(int, input().split())) +Ps = set(map(int, input().split())) +cood = set(range(0, 102)) +cood -= Ps +print((min(cood, key=lambda x: abs(x - X))))