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

if N == 0:

    print(X)

    exit()

else:

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

L = [i for i in range(0,102) if i not in P]



if X in L:

    ANS = X

else:

    L.append(X)

    L = sorted(L)

    n = L.index(X)

    l = len(L) - 1





    if (0 < n < l):

        if (L[n+1]-L[n] < L[n] - L[n-1]):

            ANS = L[n+1]

        else:

            ANS = L[n - 1]

    elif (n == l):

        ANS = L[l - 1]



print(ANS)
X, N = list(map(int,input().split()))

if N == 0:

    print(X)

    exit()

else:

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

L = [i for i in range(0,102) if i not in P]



if X in L:

    ANS = X

else:

    L.append(X)

    L = sorted(L)

    n = L.index(X)

    if (L[n+1]-L[n] < L[n] - L[n-1]):

        ANS = L[n+1]

    else:

        ANS = L[n - 1]



print(ANS)
X, N = list(map(int, input().split()))
if N == 0:
    print(X)
    exit()
else:
    P = list(map(int, input().split()))
L = [i for i in range(0, 102) if i not in P]
if X in L:
    ANS = X
else:
    L.append(X)
    L = sorted(L)
    n = L.index(X)
    l = len(L) - 1
    if 0 < n < l:
        if L[n + 1] - L[n] < L[n] - L[n - 1]:
            ANS = L[n + 1]
        else:
            ANS = L[n - 1]
    elif n == l:
        ANS = L[l - 1]
print(ANS)

X, N = list(map(int, input().split()))
if N == 0:
    print(X)
    exit()
else:
    P = list(map(int, input().split()))
L = [i for i in range(0, 102) if i not in P]
if X in L:
    ANS = X
else:
    L.append(X)
    L = sorted(L)
    n = L.index(X)
    if L[n + 1] - L[n] < L[n] - L[n - 1]:
        ANS = L[n + 1]
    else:
        ANS = L[n - 1]
print(ANS)

-    l = len(L) - 1 -    if 0 < n < l: -        if L[n + 1] - L[n] < L[n] - L[n - 1]: -            ANS = L[n + 1] -        else: -            ANS = L[n - 1] -    elif n == l: -        ANS = L[l - 1] +    if L[n + 1] - L[n] < L[n] - L[n - 1]: +        ANS = L[n + 1] +    else: +        ANS = L[n - 1]