Problem:
 Score : 300 points    Problem Statement 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.      Constraints  1 \leq X \leq 100  0 \leq N \leq 100  1 \leq p_i \leq 100  p_1, \ldots, p_N are all distinct.  All values in input are integers.         Input Input is given from Standard Input in the following format:  X  N  p_1  ...  p_N       Output Print the answer.        Sample Input 1 6 5
4 7 10 6 5      Sample Output 1 8  Among the integers not contained in the sequence 4, 7, 10, 6, 5 , the one nearest to 6 is 8 .       Sample Input 2 10 5
4 7 10 6 5      Sample Output 2 9  Among the integers not contained in the sequence 4, 7, 10, 6, 5 , the ones nearest to 10 are 9 and 11 . We should print the smaller one, 9 .       Sample Input 3 100 0      Sample Output 3 100  When N = 0 , the second line in the input will be empty. Also, as seen here, X itself can be the answer.

Solution (Python):
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log,gcd
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
'''


 
import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix
'''
 

def ii(): return int(sys.stdin.readline().rstrip()) 
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) 
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]

def ss(): return sys.stdin.readline().rstrip() 
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) 
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]





x,n=mii()
arr0=limii()

if len(arr0)==0:
    print(x)
    exit()

arr=[]
for i in range(0,102):
    if i not in arr0:
        arr.append(i)
arr.sort()
ans=[10**100,10*100]

for i in reversed(arr):
    if abs(i-x)<ans[1]:
        
        if i<ans[0]:
            ans[0]=min(ans[0],i)
            ans[1]=abs(i-x)
    elif abs(i-x)==ans[1]:
        ans[0]=min(ans[0],i)
print(ans[0])

Solution (Python):
def C():
    x,n = list(map(int, input().split()))
    p = list(map(int, input().split()))
    for dist in range(102):
        if x-dist not in p:
            print(x-dist)
            return
        if x+dist not in p:
            print(x+dist)
            return
C()

Solution (Python):
x, n = map(int, input().split())
P = list(map(int, input().split()))
INF = 10**18
ans = INF
if x not in P:
    print(x)
    exit()
for i in range(-100, 200):
    if i in P:
        continue
    if ans > abs(x-i):
        ans = abs(x-i)
        cnt = i
print(cnt)

Solution (Python):

import sys
import math

low = 1
high = 100


tmp = input().split()
x,n = list(map(lambda a: int(a), tmp))

if(n==0):
	print(x)
	sys.exit()

tmp = input().split()
p = list(map(lambda a: int(a), tmp))

ans=[]
for i in range(102):
	ans.append(0)



for i in range(n):
	ans[p[i]]+=1

tmp=0
if(ans[x]==0):
	print(x)
	sys.exit()

for i in range(102):
	if(ans[x-tmp]==0):
		print(x-tmp)
		sys.exit()
	if(ans[x+tmp]==0):
		print(x+tmp)
		sys.exit()
	tmp+=1

Solution (Python):
import sys
sys.setrecursionlimit(300000)
from bisect import bisect_right, bisect_left

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI0(): return map(lambda s: int(s) - 1, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
def LMI0(): return list(map(lambda s: int(s) - 1, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


X, N = MI()
if N == 0:
    print(X)
    exit()
else:
    P = LMI()
P.sort()
ng = set(P)
m = INF
ans = -1
l, r = min(X - 1, P[0]), max(X + 1, P[-1] + 1)
for i in range(l - 100, r + 100):
    if i in ng:
        continue
    if abs(X - i) < m:
        m = abs(X - i)
        ans = i
print(ans)

Solution (Python):
X,N=map(int,input().split())
p=map(int,input().split())
P=sorted(p)
PS=[abs(X-y) for y in P]
if N==0:
    print(X)
else:
    if not 0 in PS:
        print(X)
    else:
        for n in range(1,100):
            if PS.count(n)==1:
                place=PS.index(n)
                answer=0
                break
            elif PS.count(n)==0:
                answer=1
                break
        if answer==0:
            if P[place] - X < 0:
                print(X + n)
            else:
                print(X - n)
        else:
            print(X-n)

Solution (Python):
import numpy as np

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

P = set(P)
All = set( np.arange(0,102) )
Q = np.array(list(All-P))

Q_X = np.absolute( Q-X )
ans = Q[ np.argmin(Q_X ) ]

print(ans)

Solution (Python):
x, n = map(int, input().split())
ps = set(map(int, input().split()))

if x not in ps:
   print(x)
   exit()

b, u = x, x
while True:
   b, u = b-1, u+1
   if b not in ps:
      print(b)
      exit()
   if u not in ps:
      print(u)
      exit()

Solution (Python):
X, N = [int(i) for i in input().split(' ')]
if N>0:
  p = [int(i) for i in input().split(' ')]
  abs_list = {}

  for i in range(-100,200):
    if(i in p):
      continue
    abs_list[i] = abs(X - i)
  min_k = min(abs_list, key=abs_list.get)
  print(min_k)
else:
  print(X)

Solution (Python):
x,n = map(int, input().split())
p = list(map(int, input().split()))
ab = min(abs(101 - x),abs(x))
if abs(101 - x) >= abs(x):
    answer = 0
else:
    answer = 101
for i in range(1,101):
    if i in p:
        continue
    else:
        if ab > abs(x - i):
            ab = abs(x - i)
            answer = i
        elif ab == abs(x-i) and answer > i:
            answer = i
print(answer)

Solution (Python):
X,N = (int(x) for x in input().split())
ans = 10000
ansnum = -3
if (N > 0):
    p = list(map(int, input().strip().split()))
    for i in range(-1,102):
        preans = abs(X-i)
        if(preans < ans) and (i in p ) == False:
            ans = preans
            ansnum = i
    print(ansnum)
else:
    print(X)

Solution (Python):
X,N = map(int,input().split())
N_list =  list(map(int, input().split()))
A = []
for x in range(-100,200):
    A.append(x)
for x in N_list:
    A[x+100] = 1000
m = 200
s = 0
for x in A:
    if abs(X-x) < m:
        m = abs(X-x)
        s = x
print(s)

Solution (Python):
''''atcoder beginner contest-170'''

import math
from collections import defaultdict
def r():
    return int(input())
def rm():
    return map(int,input().split())
def rl():
    return list(map(int,input().split()))

'''C'''
x,n=rm()
l=True
try:
    a=rl()
except:
    a=[]
b=defaultdict(int)
for i in a:
    b[i]=1
mini=math.inf
value=-1
for j in range(-101,201):
    if b[j]!=1:
        if abs(x-j)<mini:
            mini=abs(x-j)
            value=j
print(value)

Solution (Python):
X, N = map(int, input().split())
p = input().split()
p = [int(s) for s in p]
low = X
up = X
while 1 > 0:
    if low not in p:
        answer = low
        break
    elif up not in p:
        answer = up
        break
    low -= 1
    up += 1

print(answer)

Solution (Python):
import numpy as np
import sys

x, n = map(int, input().split())
if n == 0:
    print(x)
    sys.exit()
p = np.array(list(map(int, input().split())))
diff = set(p - x)
for i in range(102):
    if -i not in diff:
        print(x-i)
        break
    elif i not in diff:
        print(x+i)
        break

Solution (Python):
X, N = map(int,input().split())
Ps =  set(map(int, input().split()))
for i in range(N+1):
    if (X-i) not in Ps:
        print(X-i)
        exit()
    elif (X+i) not in Ps:
        print(X+i)
        exit()

Solution (Python):
S=lambda:input()
I=lambda:int(input())
L=lambda:list(map(int,input().split()))
LS=lambda:list(map(str,input().split()))

def main():
    x,n=L()
    if n!=0:p=L()
    z=[]
    for i in range(0,105):
        flag=False
        for j in range(n):
            if i==p[j]:
                flag=True
                break
        if(flag): continue
        z.append(i)
    
    mini=1e+5
    ans=1e+5
    for i in range(len(z)):
        absxz=abs(x-z[i])
        if absxz<mini:
            mini=absxz
            ans=z[i]
    print(ans)
            
    
if __name__ == '__main__':
    main()

Solution (Python):
X, N = map(int, input().split())
p_list = [int(i) for i in input().split()]

if N == 0:
    print(X)
elif X not in p_list:
    print(X)
else:
    check_list = []
    for i in range(1, 105+1):
        check_list.append(X-i)
        check_list.append(X+i)

    for el in check_list:
        if el not in p_list:
            break

    print(el)

Solution (Python):
x,n=map(int, input().split())
p=list(map(int, input().split()))

l=[i for i in range(-3, 102)]

new_l=list(set(l)-set(p))
new_l.sort()

ans=-3
sa=100
for l_i in new_l:
    
    if abs(l_i-x)<sa:
        ans=l_i
        sa=abs(l_i-x)

print(ans)

Solution (Python):
x, n = map(int, input().split())
n_list = list(map(int, input().split()))

r_ascend = x
while r_ascend in n_list:
    r_ascend += 1

r_descend = x
while r_descend in n_list:
    r_descend -= 1

if abs(x - r_descend) <= abs(x - r_ascend):
    print(r_descend)
else:
    print(r_ascend)

Solution (Python):
import math
from collections import defaultdict
ml=lambda:map(int,input().split())
ll=lambda:list(map(int,input().split()))
ii=lambda:int(input())
ip=lambda:list(input())
ips=lambda:input().split()

"""========main code==============="""

a,b=ml()
if(b==0):
    n=set()
else:
    n=ll()
    n=set(n)
r=0
for i in range(a,1001):
    if(i not in n):
        r=i
        break
l=0    
for i in range(a-1,-1,-1):
    if(i not in n):
        l=i
        break
if(abs(l-a)<=abs(r-a)):
    print(l)
else:
    print(r)

Solution (Python):




X,N = map(int, input().split())
if N == 0:
    print(X)
    exit()

A = list(map(int, input().split()))
Min = 101

cnt = -200
for i in range(1,400):
    
    if cnt in A:
        cnt += 1
        continue
    if abs(cnt-X) < Min:
        ans = cnt
        Min = abs(cnt-X)
    cnt += 1
print(ans)

Solution (Python):


def main():
    X,N = map(int, input().split())
    p = list(map(int, input().split()))
    
    if X not in p:
        ans=X
    else:
        for i in range(100):
            if X-i not in p:
                ans=X-i
                break
            elif X+i not in p:
                ans=X+i
                break
        
    print(ans)
    
if __name__ == "__main__":
    main()

Solution (Python):
x, n = map(int, input().split())
p = list(map(int, input().split()))
i = 0
while True:
    if not (x - i) in p:
        print(x-i)
        exit()
    if not (x + i) in p:
        print(x+i)
        exit()
    i += 1

Solution (Python):
xn = input('')
x = int(xn.split(' ')[0])
n = int(xn.split(' ')[1])
ps = list(map(int,input().split()))

max_width = 2*x

result = x
for i in range(max_width):
    x1 = x-i
    x2 = x+i
    if x1 not in ps:
        result = x1
        break
    if x2 not in ps:
        result = x2
        break

print(result)

Solution (Python):
X, N = map(int, input().split())
if N==0:
    ans = X
else:
    p = list(map(int, input().split()))
    
    finished = False
    cnt = 1

    if X not in p:
        ans = X

    else:    
        while(not finished):
            L = X-cnt
            R = X+cnt

            if L not in p:
                ans = L
                finished = True
            elif R not in p:
                ans = R
                finished = True

            else:
                cnt += 1

print(ans)

Solution (Python):
X, N= list(map(int, input().split()))
P = list(map(int, input().split()))
for i in range(0, 51):
    try:
        P.index(X - i)
    except Exception:
        print(X - i)
        break

    try:
        P.index(X + i)
    except Exception:
        print(X + i)
        break

Solution (Python):
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

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

if N == 0:
    print(X)
    quit()

abs_ = 200
answers = []


for i in range(102):
    if i in P:
        continue

    tmp_abs = abs(X - i)
    if tmp_abs == abs_:
        answers.append(i)
    if tmp_abs < abs_:
        answers = [i]
        abs_ = tmp_abs
ans = min(answers)
print(ans)

Solution (Python):
X, N = map(int, input().split())
p = [int(n) for n in input().split()]
i = 0

while 1:
    if not X - i in p:
        print(X-i)
        break
    if not X + i in p:
        print(X+i)
        break
    i += 1

Solution (Python):
X,N=map(int,input().split())
p=list(map(int,input().split()))
p.sort()
ans=0
ans1=X
for i in range(1,102):
    if i in p:
        a=p.pop(0)
        continue
    A=abs(X-i)
    if ans1>A:
        ans1=A
        ans=i
    elif ans1==A:
        ans=min(ans,i)
    else:
        break
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(4100000)
import math
INF = 10**9
import fractions

def main():
    x,n = map(int, input().split())
    P = list(map(int, input().split()))

    ans = INF
    array = set(range(x-n-1,x+n+1))
    array = array - set(P)
    array = list(array)
    for i in range(len(array)):
        ans = min(ans, abs(array[i]-x))
    if (x-ans) in P:
        print(x+ans)
    else:
        print(x-ans)




if __name__ == '__main__':
    main()

Solution (Python):
import sys

X, N = map(int, input().split())
a = input().split()
a = [int(i) for i in a]

ans = 1000
count = 0

if len(a) == 0:
    print(X)
    sys.exit()
else:
    m = max(a)*200
    for i in range(-m, m+1):
        if i in a:
            pass
        else:
            kyori = abs(X-i)
            if ans > kyori:
                ans = kyori
                count = i
            elif ans == kyori:
                count = min(count, i)
            else:
                pass

print(count)

Solution (Python):
import numpy as np
x,n=map(int,input().split())
p=np.array(list(map(int,input().split())))
p_abs=sorted(list(map(lambda k:abs(k-x),p)))


if(len(p_abs)==0 or p_abs[0]!=0):
    print(x)
else:
    i=1
    while(True):
        if(2*i>=len(p)):
            if(x-i not in p):
                print(x-i)
            else:
                print(x+i)
            break
        elif(p_abs[2*i-1]!=i or p_abs[2*i]!=i):
            if(x-i not in p):
                print(x-i)
            else:
                print(x+i)
            break
        else:
            i+=1

Solution (Python):
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
INF = 1000000000000

x,n = LI()
p = LI()

val = INF
ret = INF
tmp = 0
for i in range(-100,200):
    flg = False
    for y in p:
        if(i == y):
            flg = True
    if(not flg):
        tmp =  abs(x - i)
        if(val > tmp):
            val = tmp
            ret = i

print(ret)

Solution (Python):
if __name__ == "__main__":
    x, n = map(int, input().split())
    p = list(map(int, input().split()))
    

    ans = float('inf')
    ans2 = 0

    for i in range(0, 102):
        isin = False
        for j in range(len(p)):
            if i == p[j]:
                isin = True
        
        if isin:
            continue

        if ans > abs(x - i):
            ans = abs(x - i)
            ans2 = i

        
    print(ans2)

Solution (Python):
def main1():
    X,N=map(int,input().split())
    p=list(map(int,input().split()))
    ans=-1
    for i in range(X,1000):
        if not (i in p):
            ans=i
            break
    for i in range(X,-1,-1):
        if not (i in p):
            ans2=i
            break
    if abs(ans-X) >= abs(ans2-X):
        print(ans2)
    else:
        print(ans)

main1()

Solution (Python):
import sys
X, N = map(int,input().split())
if N == 0:
  PN = []
else:
  PN = list(map(int,input().split()))
nums = [i for i in range(-10,110)]

for P in PN:
  nums.remove(P)

dist = abs(nums[0]-X)
target = nums[0]
for num in nums[1:]:
  tmp = abs(num-X)
  if tmp >= dist:
    print(target)
    sys.exit()
  else:
    dist = tmp
    target = num

Solution (Python):
X, N = map(int, input().split())
num = list(map(int, input().split()))
a = X
b = X
while a in num and b in num:
  a+=1
  b-=1
if b not in num: print(b)
elif a not in num: print(a)

Solution (Python):
x, n= map(int, input().split(' '))

if n!= 0:
	ps= input().split(' ')
else:
	ps=[]

def in_ps(x):
	for p in ps:
		if x==int(p):
			return True
	return False
d=1

while 1:
	if in_ps(x):
		x+= d*(-1)**d
		d+=1
	else:
		print(x)
		break

Solution (Python):
x,n = map(int,input().split())
p = list(map(int,input().split()))
ans = 10**9
a = 10**9

for i in range(-100,102):
    if not(i in p):
        sa = abs(x-i)
        if sa < a:
            ans = i
            a = sa
        elif sa == a:
            ans = min(ans,i)

print(ans)

Solution (Python):
x,n = map(int,input().split())
if n > 0 :
  p = list( map(int,input().split()) )
  p = set(p)
else:
  p = set()

if x not in p:
  ans = x
else:
  i = x - 1
  j = x + 1
  while 1:
    if i not in p and j not in p:
      ans = min(i,j)
      break

    if i not in p:
      ans = i
      break
    elif j not in p:
      ans = j
      break

    i -= 1
    j += 1

print(ans)

Solution (Python):
X, N = map(int, input().split())
P = map(int, input().split())

Ps = set(P)
import sys

if X not in Ps:
    print(X)

else:
    dec = X - 1
    inc = X + 1

    while True:
        if dec not in Ps:
            print(dec)
            break
        else:
            dec -= 1
        
        if inc not in Ps:
            print(inc)
            break
        else:
            inc += 1

Solution (Python):
import sys
from collections import deque
import copy
def main():
    x, N = map(int, input().split())
    if N == 0:
        print(x)
        sys.exit()
    p = [int(i) for i in input().split()]
    p.sort()
    min_ = 1000
    index_ = N
    count = [0] * 102
    for i in range(N):
        count[p[i]] = 1
    for i in range(102):
        if count[i] == 1:
            continue
        if min_ > abs(i - x):
            min_ = abs(i - x)
            index_ = i
    if min_ > abs(-1 - x):
        index_ = -1
    print(index_)


if __name__ == '__main__':
    main()

Solution (Python):


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


for i in range(100):
    if X - i not in p:
        print(X - i)
        break
    if X + i not in p:
        print(X + i)
        break

Solution (Python):
X,N=map(int,input().split())
if N==0:
  print(X)
else:
  p=list(map(int,input().split()))
  flag=False
  i=0
  while flag==False:
    if (X-i in p)==False:
      flag==True
      print(X-i)
      break
    if (X-i in p)==True and (X+i in p)==False:
      flag==True
      print(X+i)
      break
    i+=1

Solution (Python):
x, n = map(int, input().split())
if n != 0:
    p = list(map(int, input().split()))
    i = 0
    flag = False
    ans = 0
    while True:
        x_minus = x-i
        x_plus = x+i
        if x_plus not in p:
            ans = x_plus
            flag = True
        if x_minus not in p:
            ans = x_minus
            flag = True
        if flag:
            break
        else:
            i += 1
    print(ans)
    
else:
    print(x)

Solution (Python):
import math
import sys
from collections import deque
import heapq
import copy
import itertools
from itertools import permutations
def mi() : return map(int,sys.stdin.readline().split())
def ii() : return int(sys.stdin.readline().rstrip())
def i() : return sys.stdin.readline().rstrip()
a,b=mi()
if b==0:
  print(a)
else:
  l=list(mi())
  for i in range(100):
    if not(a-i in l):
      print(a-i)
      sys.exit()
    elif not(a+i in l):
      print(a+i)
      sys.exit()

Solution (Python):
import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    X, N = map(int, readline().split())
    P = list(map(int, readline().split()))
    diff = 1000
    ans = 0
    for i in range(102):
        if not i in P:
            if abs(X-i)<diff:
                ans = i
                diff = abs(X-i)

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
x,n=map(int,input().split())
if(n==0):
    print(x)
    exit()
p = list(map(int,input().split()))

c = 0
while True:
    if (not (x-c) in p):
        print(x-c)
        exit()
    if (not (x+c) in p):
        print(x+c)
        exit()
    c+=1

Solution (Python):

import sys
K,N=map(int,input().split())
L=list(map(int,input().split()))
diff=float("inf")
ans=0
mi=float("inf")
for i in range(-200,200):
    if i not in L:
        diff=abs(i-K)
        if diff<mi:
            mi=diff
            ans=i
print(ans)

Solution (Python):
x, n = map(int, input().split())
P = input().split()

ng_map = {}
for p in P:
    ng_map[int(p)] = True

min_val = 999
candidate = x
for i in range(102):
    if i in ng_map:
        continue
    val = abs(x - i)
    if val < min_val:
        candidate = i
        min_val = val
print(candidate)

Solution (Python):
x, n = map(int, input().split())

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

n = -1
m = 999
for num in range(-1, 102):
    if num in nums:
        continue
    elif m != min(m, abs(num - x)):
        n = num
        m = min(m, abs(num - x))

print(n)

Solution (Python):
import sys











stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

def main():
    
    x,n = map(int, stdin.readline().rstrip().split())
    if n != 0:
        ps = list(map(int, stdin.readline().rstrip().split()))
    else:
        print(x)
        exit()
    
    
    
    
    ps.sort()
    ab = []
    for i in range(n):
        ab.append(abs(ps[i] - x))
    m = ps[ab.index(min(ab))]
    small = m
    big = m
    if m not in ps:
        print(m)
        exit()
    while True:
        small = small - 1
        big = big + 1
        if small not in ps:
            print(small)
            exit()
        elif big not in ps:
            print(big)
            exit()

main()

Solution (Python):
x, n = map( int, input().split() )
p = list( map( int, input().split() ) )

for i in range( n + 1 ):
    if ( x - i ) not in p:
        print( x - i )
        break
    elif ( x + i ) not in p:
        print( x + i )
        break

Solution (Python):
import io,sys
def main():
    x,n = map(int,sys.stdin.readline().rstrip().split())
    p = list(map(int,sys.stdin.readline().rstrip().split()))

    x_pos = x
    x_neg = x
    while True:
        if x_neg not in p:
            print(x_neg)
            sys.exit()
        if x_pos not in p:
            print(x_pos)
            sys.exit()
        
        x_pos+=1
        x_neg-=1
main()

Solution (Python):
x,n = map(int,input().split())
if n == 0:
    print(x)
else:
    p = list(map(int,input().split()))
    p.sort()
    for i in range(100):
        if x-i not in p:
            print(x-i)
            break
        elif x+i not in p:
            print(x+i)
            break

Solution (Python):
A,B=list(map(int,input().split()))
if B==0:
   print(A)
   exit()
N=list(map(int,input().split()))
N=set(N)
S=0
l=float("Inf")
for i in reversed(range(A,A+101)):
   if i not in N:
      S=i
      l=abs(A-i)
for i in reversed(range(A-100,A+1)):
   if i not in N and l >= abs(A-i):
      S=i
      break
print(S)

Solution (Python):
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    x, n = map(int, input().split())
    p = list(map(int, input().split()))
    arr = []
    for i in range(-100, 201):
        if not i in p:
            arr.append(i)
    ans = arr[0]
    for ai in arr:
        if abs(ai - x) < abs(ans - x):
            ans = ai
    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Solution (Python):
X,N=map(int,input().split())
p=list(map(int,input().split()))
p.sort()
ans=0
ans1=X
for i in range(1,102):
    if i in p:
        a=p.pop(0)
        continue
    A=abs(X-i)
    if ans1>A:
        ans1=A
        ans=i
    elif ans1==A:
        ans=min(ans,i)
    else:
        break
print(ans)

Solution (Python):



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

if N == 0:
    print(X)
    exit(0)

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

abs_diff = 1000000000
ans = 0
for i in range(1000,-1001,-1):
    if i in p:
        continue
    else:
        if abs_diff >= abs(X-i):
            abs_diff = abs(X-i)
            ans = i
        
print(ans)

Solution (Python):
X, N = map(int, input().split())
if N == 0:
  print(X)
  quit()

A = set(list(map(int, input().split())))
ans = 0
diff = 1000
for i in range(102):
  if i in A:
    continue
  d = abs(X - i)
  if d < diff:
    diff = d
    ans = i

print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10**9)

INF = 10**20
def main():
    X,N = map(int,input().split())

    if N == 0:
        print(X)
        exit()

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


    minim = INF
    ans = 0
    for i in range(10**4+1):
        if i in p: continue

        if minim > abs(i-X):
            ans = i
            minim = abs(i-X)


    print(ans)






if __name__ == "__main__":
  main()

Solution (Python):
x, n = map(int, input().split())
li = list(map(int, input().split()))

for i in range(100):
    if x-i not in li:
        print(x-i)
        break
    if x+i not in li:
        print(x+i)
        break

Solution (Python):
X, N = map(int, input().split())
P = list(map(int, input().split()))

li = []
for i in range(0, 102):
    if i not in P:
        li.append(i)

ans = -1
minimum_num = 200

for n in li:
    num = abs(n - X)
    if num < minimum_num:
        minimum_num = num
        ans = n

print(ans)

Solution (Python):
X,N=map(int,input().split())
p=list(map(int,input().split()))
p.sort()
if X in p:
  for i in range(1,100):
    if not X-i in p:
      print(X-i)
      break
    if not X+i in p:
      print(X+i)
      break
else:
  print(X)

Solution (Python):
X,N = list(map(int,input().split()))
if N == 0:
    print(X)
    exit()
p = list(map(int,input().split()))
p.sort()


for i in range(100):
    
    
    if X-i not in p:
        print(X-i)
        exit()
    if X+i not in p:
        print(X+i)
        exit()

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

done = False
curr_diff = 0
while not done:
    curr = []
    if X - curr_diff not in p:
        curr.append(X - curr_diff)
    elif X + curr_diff not in p:
        curr.append(X + curr_diff)
    
    if curr:
        done = True
    curr_diff += 1

print(min(curr))

Solution (Python):
'''     
        
        
        

import sys
import math


def get_ints(): return map(int, input().strip().split())
def get_list(): return list(get_ints())

def printspx(*args): return print(*args, end="")
def printsp(*args): return print(*args, end=" ")
def printchk(*args): return print(*args, end=" \ ")

MODPRIME = int(1e9+7); BABYMODPR = 998244353;

ONLINE_JUDGE = 1
if not ONLINE_JUDGE:
    sys.stdin = open("input.txt","r")  
    sys.stdout = open("output.txt","w")  
    sys.stderr = open("output.txt","w")  

x, n = get_ints()
li = get_list()
li = set(li)
i = 0
ans = -1
while True:
    if x-i not in li:
        ans = x-i
        break
    elif x+i not in li:
        ans = x+i
        break
    i += 1
print(ans)


'''
>>> COMMENT THE STDIN!! CHANGE ONLINE JUDGE !!
THE LOGIC AND APPROACH IS BY ME @luctivud ( UDIT GUPTA )
SOME PARTS OF THE CODE HAS BEEN TAKEN FROM WEBSITES LIKE::
(I Own the code if no link is provided here or I may have missed mentioning it)
DO NOT PLAGIARISE.
TESTCASES:
>>> COMMENT THE STDIN!! CHANGE ONLINE JUDGE !!
'''

Solution (Python):
x, n = map(int, input().split())
p = list(map(int, input().split()))

if n == 0:
    print(x)
    quit()
    
min_ = float('Inf')
ans = 0
for i in range(-1, 110):
    if i in p:
        continue
    
    diff = abs(x - i)
    if diff < min_:
        min_ = diff
        ans = i
print(ans)

Solution (Python):
X, N = map(int,input().split())
if N != 0:
  ps = sorted(list(map(int,input().split())))
  
  min_num = 1000
  min_abs = 1000
  p_index = 0
  for i in range(0,102):
    if i == ps[p_index]:
      p_index += 1
      p_index %= N
    elif abs(i-X)<min_abs:
      min_num = i
      min_abs = abs(i-X)
  print(min_num)
else:
  print(X)

Solution (Python):


from sys import stdin
input = lambda: stdin.readline().rstrip()


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

def solve(A, B):
    if A not in P:
        print(A)
        return

    if B not in P:
        print(B)
        return
    
    solve(A-1, B+1)

solve(X,X)

Solution (Python):
x, n = map(int, input().split())
lists = list(input().split())
for i in range(n):
  lists[i] = int(lists[i])
loop = True
number = x
while True:
  if number in lists:
    number = number - 1
  else:
    break
number_2 = x
while True:
  if number_2 in lists:
    number_2 = number_2 + 1
  else:
    break
if abs(number - x) > abs(number_2 - x):
  print(number_2)
elif abs(number - x) == abs(number_2 - x):
  print(number)
else:
  print(number)

Solution (Python):
x,n=map(int, input().split())
if n==0:
    print(x)
else:
    a=list(map(int, input().split()))
    a.sort()
    sa=1000
    for i in range(0,102):
        if i not in a:
            if sa>abs(x-i):
                ans=i
                sa=abs(x-i)
    print(ans)

Solution (Python):

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




for i in range(200):
    if X+i in p:
        continue
    else:
        dammy1=X+i
        kouho1=i
        break

for j in range(200):
    if X-j in p:
        continue
    else:
        dammy2=X-j
        kouho2=j
        break



if kouho1<kouho2:
    print(dammy1)
else:
    print(dammy2)

Solution (Python):
x, n = map(int, input().split())
p = set(map(int, input().split()))
q = set(range(102))
r = sorted(list(q - p))

tmp = 200
for s in r:
    if abs(x-s) < tmp:
        res = s
        tmp = abs(x-s)

print(res)

Solution (Python):
import math
import pprint
import fractions
import collections
import itertools
from decimal import *
X,N=map(int,input().split())
p=list(map(int,input().split()))
n=len(p)
d={}
l=[i-1 for i in range(104)]

i=0
while i<n:
    for j in range(len(l)):
        if p[i]==l[j]:
            l.pop(j)
            break
    
    
    i=i+1
minim=float("inf")
l2=[]
for i in range(len(l)):
    if minim>abs(l[i]-X):
        minim=abs(l[i]-X)
        l2=[]
        l2.append(l[i])
    elif minim==abs(l[i]-X):
        l2.append(l[i])


print(min(l2))

Solution (Python):
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

x,n = na()
p = na()
q = [i for i in range(-1,102) if i not in p]
r = []

for i in range(len(q)):
    r.append(abs(q[i]-x))

if n == 0:
    print(x)
    exit()

k = min(r)
if x-k in q:
    print(x-k)
else:
    print(x+k)