Problem: Given are an integer X and an integer sequence of length N: p_1, \ldots, p_N.  Among the integers not contained in the sequence p_1, \ldots, p_N (not necessarily positive), find the integer nearest to X, that is, find the integer whose absolute difference with X is the minimum. If there are multiple such integers, report the smallest such integer.

Submission attempts (in order):
ans = []
x,n = map(int,input().split())
l = list(map(int,input().split()))

l.sort()

ans.append(x)

nl = [0] * 100


for i in l:
    nl[i] = i

if(not (n == 0)):
    
    mx = x+1
    if(mx < 100):
        for i in range(x+1,len(nl)+1):
            if( nl[i] ==  0):
                ans.append(mx)
                break
            mx = mx + 1
    
    
    mi = x - 1
    if(mi > 1):
        for i in range(x-1,1,-1):
            if( nl[i] ==  0):
                ans.append(mi)
                break
            mx = mx + 1        

print(min(ans))


#C

ans = []
x,n = map(int,input().split())
l = list(map(int,input().split()))

l.sort()

ans.append(x)

print(x,n)
print(l)

nl = [0] * 100


for i in l:
    nl[i] = i

if(not (n == 0)):
    
    mx = x+1
    if(mx < 100):
        for i in range(x+1,len(nl)+1):
            if( nl[i] ==  0):
                ans.append(mx)
                break
            mx = mx + 1
    
    
    mi = x - 1
    if(mi > 1):
        for i in range(x-1,1,-1):
            if( nl[i] ==  0):
                ans.append(mi)
                break
            mx = mx + 1        

print("ans=",ans)
print(min(ans))


import sys

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

for d in range(X + 1):
    for s in [-1, +1]:
        a = X + s * d
        print(a," = ",X ," + ",s," * ",d)
        if p.count(a) == 0:
            print(a)
            sys.exit(0)

#C

ans = []
x,n = map(int,input().split())
l = list(map(int,input().split()))

l.sort()


nl = [0] * 100


for i in l:
    nl[i] = i

if(not (n == 0)):

    mx = x+1
    if(mx < 100):
        for i in range(x+1,len(nl)+1):
            if( nl[i] ==  0):
                ans.append(mx)
                break
            mx = mx + 1
    
    
    mi = x - 1
    if(mi > 1):
        for i in range(x-1,1,-1):
            if( nl[i] ==  0):
                ans.append(mi)
                break
            mi = mi - 1

print(min(abs(n),abs(mi),abs(mx)))

def workC():
    
    x,n = map(int,input().split())
    l = list(map(int,input().split()))

    if n == 0:
        return x
    
    if n == 100:
        return 0
    
    for i in range(x,maxx):
        if not i in l:
            u = i
            #dic.setdefault(i,abs(i-x))
            break
    
    for i in range(x,minx,-1):
        if not i in l:
            d = i
            #dic.setdefault(i,abs(x-i))
            break
    
    if abs(x-u) == abs(x-d):
        return min(u,d)
    elif abs(x-u) < abs(x-d):
        return u
    else:
        return d

ans = workC()
print(ans)

import sys

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

for d in range(X + 1):
    for s in [-1, +1]:
        a = X + s * d
        if p.count(a) == 0:
            print(a)
            sys.exit(0)

Verdicts: Runtime Error

Runtime Error

Wrong Answer

Runtime Error

Runtime Error

Accepted