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 bisect
x, n = map(int, input().split())
p = sorted(list(map(int, input().split())))
b = []
if n == 0:
    print(x)
else :
    for i in range(-200, 300):
        if not i in p:
            b.append(i)
    index = bisect.bisect_left(b, x)
    a = abs(x-b[index-1]) 
    c = abs(x-b[index])
    if a <= c:
        print(b[index-1])
    else :
        print(b[index])

Solution (Python):
import sys

X, N = map(int,input().split())
if N == 0:
  print(X)
  sys.exit()
p = input().split(" ")
a = X
b = X
for i in range(len(p)):
  for i in range(len(p)):
    if int(p[i]) == a:
      a = a + 1
    if int(p[i]) == b:
      b = b - 1
  

if -1*(X - a) < X - b:
  print(a)
else:
  print(b)

Solution (Python):
x, n = map(int, input().split())
lst = list(map(int, input().split()))
if n == 0:
    print(x)
    exit()
lst.sort()
container = []
store = []
d = []
lst_num = list(range(0, lst[-1] + 2))


for i in lst_num:
    base = lst_num.index(x)
    if i not in lst:
        container.append(i)
for y in container:
    if y < x:
        store.append(y)
    else:
        d.append(y)
if x - max(store) <= min(d) - x:
    print(max(store))
else:
    print(min(d))

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

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

Solution (Python):
X,N= map(int,input().split())
p = list(map(int, input().split()))
p = sorted(p)
ans_tmp = 10**9+7
ans = 0
if N==0:
    print(X)
else:
    if X not in p:
        print(X)
        exit()
    else:
        tmp1,tmp2 = X-1,X+1
        while True:
            if tmp1 not in p:
                print(tmp1)
                exit()
            if tmp2 not in p:
                print(tmp2)
                exit()
            tmp1 -= 1
            tmp2 += 1

Solution (Python):
x, n = map(int, input().split())
p = []
while True:
  try:
    p = list(map(int, input().split()))
  except EOFError:
    break

for num in range(100 + 1):
  high, low = x + num, x - num
  if low not in p:
    print(low)
    break
  if high not in p:
    print(high)
    break

Solution (Python):
x, n = [int(x) for x in input().split()]

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

P = [int(x) for x in input().split()]

before = x
after = x
while True:
    if before not in P:
        print(before)
        break
    elif after not in P:
        print(after)
        break
    before -= 1
    after += 1

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

list_a = []
for a in range(-102,102):
    if a not in p:
        list_a.append(abs(X-a))

m = X - min(list_a)
l = X + min(list_a)
if m not in p:
    print(m)
else:
    print(l)

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

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


if n == 100:
    if x <= 50:
        print(0)
        sys.exit()
    else:
        print(101)
        sys.exit()


nun_list = list(map(int, input().split()))
answer = 0

for i in range(0, 210):
    if nun_list.__contains__(i):
        continue
    else :
        if abs(x - answer) >= abs(x - i):
            if abs(x - answer) == abs(x - i):
                if answer > i:
                    answer = i
            else:
                answer = i
if abs(x - answer) <= abs(x - 0):
    print(answer)
else :
    print(0)

Solution (Python):
import numpy as np
X,N=map(int,input().split())
L = list(map(int,input().split()))
if N == 0:
    print(X)
else:
    for n in np.array(range(N+1)):
        for l in L:
            s = X - n
            if (s == l):
                break
        else:
            print(s)
            break

        for l in L:
            s = X + n
            if (int(s) == l):
                break
        else:
            print(s)
            break

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

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

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

tmp = [i for i in range(-101, 200)]
for i in p:
  tmp.remove(i)
for i in range(len(tmp)):
  tmp[i] = abs(tmp[i] - X)

ans = 0
for i in p:
  if X-min(tmp)==i:
    ans = 1

if ans==0:
  print(X-min(tmp))
else:
  print(X+min(tmp))

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

ans=0
min_ans=200
t=0

if n==0:
    print(x)
else:
    p= list(map(int,input().split()))
    for i in range(110):
        if p.count(i)==0:
            ans=abs(x-i)
            if ans<min_ans:
                min_ans=ans
                t=i
        else:
            continue

    print(t)

Solution (Python):
from sys import stdin
x, n = map(int, stdin.readline().rstrip().split())
if n ==0:
    print(x)
else:
    data = list(map(int, stdin.readline().rstrip().split()))

    data_sorted = sorted(data)

    abs_min = 100000000
    res = data_sorted[0]-1
    for i in range(data_sorted[0]-1, data_sorted[-1]+2):
        if (i in data_sorted) == False and abs_min > abs(i-x):
            abs_min = abs(i-x)
            res = i
    print(res)

Solution (Python):
x , n = map(int,input().split())
p_str = []
if n != 0 :
    p_str = input().split()
    
list = []

for i in p_str :
    p = int(i)
    list.append(p)

if not x  in list :
    print(x)
else :
    for i  in range(101):
        y = x - i
        if not y in list :
            print(y)
            break
        z = x + i
        if not z in list :
            print(z)
            break

Solution (Python):
x, n = map(int, input().split())
p = list(map(int, input().split()))
sa = float("inf")
for i in range(-100, 201):
    if i not in p:
        sa = min(sa, abs(i - x))
if x - sa not in p and x + sa not in p:
    print(x - sa)
elif x - sa in p and x + sa not in p:
    print(x + sa)
elif x - sa not in p and x + sa in p:
    print(x - sa)

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


def num(x, p_list):
    if n == 0:
        return x
        
    p_num = x 
    m_num = x 
    p_list_max = max(p_list)
    p_list_min = min(p_list)

    while p_num <= p_list_max:
        if p_num not in p_list:
            break
        else:
            p_num += 1

    while m_num >= p_list_min:
        if m_num not in p_list:
            break
        else:
            m_num -= 1
    
    if abs(p_num - x) >= abs(x - m_num):
        return m_num
    else:
        return p_num

print(num(x, p_list))

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

y_min = 101 - X
ans = 101

for i in range(0,101):
    x = 100 - i 
    
    if x in p:
        continue

    y = abs( X - x )

    if y_min >= y:
        y_min = y
        ans = x
        
print(ans)

Solution (Python):
x,n = map(int,input().split())
p = list(map(int,input().split()))
ans = 0
c = 1
i = 0
y = x
z = x
while c:
    y = x-i
    z = x+i
    a = 0
    b = 0
    for j in range(n):
        if y == p[j]:
            a = 1
        if z == p[j]:
            b = 1
    if b == 0:
        ans = z
        c = 0
    if a == 0:
        ans = y
        c = 0
    i+=1
print(ans)

Solution (Python):
X,N = map(int,input().split())
P = list(map(int,input().split()))
X2=X
c=-5000
d=-5000
b=0
for i in range(1000):
    if X+i not in P and X+i <= 200 :
        c=X+i
    if X-i not in P and X-i >= -100: 
        d=X-i
    if c!=-5000:
        if d!=-5000:
            print(d)
        else:
            print(c)
        break
    if d!=-5000:
        print(d)
        break

Solution (Python):
def main():
    x, n = map(int, input().split())
    
    if n==0:
        print(x)
    else:
        p = list(map(int, input().split()))
        
        truefalse = [True]*101
        for i in range(n):
            truefalse[p[i]-1] = False
        
        a = 0
        while 1:
            if truefalse[x-a-1]:
                print(x-a)
                break
            elif truefalse[x+a-1]:
                print(x+a)
                break
            else:
                a += 1

if __name__ == "__main__":
    main()

Solution (Python):
import numpy as np

int_num, length = map(int, input().split())
if length == 0:
    print(int_num)
else:
    num_list = (list(map(int, input().split())))
    num_zettai_list = np.abs(num_list)
    up_int = int_num
    down_int = int_num
    while True:
        up_int += 1
        down_int -= 1
        flg1 = up_int in num_zettai_list
        flg2 = down_int in num_zettai_list
        if int_num not in num_zettai_list:
            print(int_num)
            break
        if not flg1 and not flg2:
            print(down_int)
            break
        elif flg1 and not flg2:
            print(down_int)
            break
        elif flg2 and not flg1:
            print(up_int)
            break

Solution (Python):
x, N = map(int, input().split(" "))
try:
  data = list(map(int, input().split(" ")))
except:
  data = []
point = 0
i = 0
while(1):
    if x not in data:
        print(x)
        break
    elif x+i not in data:
        print(x+i)
        break
    elif x+(-1*i) not in data:
        print(x+(-1*i))
        break
    else:
        i=i-1

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

plus = x
minus = x

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

while True:

    if plus <= 100:
        plus += 1

    if minus >= 0:
        minus -=1


    if not minus in line:
        print(minus)
        exit()

    if not plus in line:
        print(plus)
        exit()

    if plus > 100 and minus < 0:
      exit()

Solution (Python):
x,n = map(int,input().split())
sub_list=[0]*n

if n == 0: 
    print(x)
else: 
    number_list = list(map(int,input().split()))
    for tmp in range(0,n):
        sub_list[int(tmp)]=abs(number_list[int(tmp)]-x) 
    sub_list.sort()

    if sub_list.count(0) == 0:
        print(x)
    else:
        for tmp in range(1,100):
            if sub_list.count(tmp) == 0:
                print(x-tmp)
                break
            elif sub_list.count(tmp) == 1:
                    Ans1=x-tmp
                    Ans2=x+tmp
                    if number_list.count(Ans1) == 0: 
                        print(Ans1)
                    else:
                        print(Ans2)
                    break

Solution (Python):
import numpy as np

def main():

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

        P = np.array(P)
        gap = P-X
        gap = list(gap)

        ans = X

        for i in range(200):
                temp = ((i+1)//2) * (-1)**(i)
                if temp not in gap:
                        ans = X+temp
                        break
        return ans

if __name__=="__main__":
        ans = main()
        print(ans)

Solution (Python):
x, n = map(int, input().split())
p = list(map(int, input().split()))
ls1 = []
if x not in p:
    print(x)
else:
    for i in range(100):
        y = x - (i + 1)
        z = x + i + 1
        if y not in p:
            print(y)
            break
        if z not in p:
            print(z)
            break

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

if N==0:
    print(X)
else:
    if X<min(P):
        ans=X
        print(ans)
    
    elif X in range(min(P),max(P)+1):
        
        ans_len=200 
        for i in range(250):
            if i in P:
                continue
            else:
                l=abs(X-i)
                if l < ans_len:
                    ans_len=l
                    ans=i
        print(ans)
                
    else:
        ans=X
        print(ans)

Solution (Python):


num1 = []
num1 = input().split(" ")
ans=int(num1[0])
count=int(num1[1])


if count != 0 and count != 1:
    num2 = []
    num2 = input().split(" ")


    num3 = []
    for i in range(count):
        num3.append(int(num2[i]))
    num3.sort()


    up=1
    down=1
    for i in range(count//2+3):
        if up == 1 and down == 1:
            num_up=ans+i
            num_down=ans-i
            up=0
            down=0
        elif up ==1:
            print(num_down)
            break
        elif down == 1:
            print(num_up)
            break
        else:
            print(num_down)
            break
        
        for k in range(count):
            if num_up == num3[k]:
                up=1
            
            if num_down == num3[k]:
                down=1
                
elif count ==0:
    print(ans)
elif count ==1:
    num2=int(input())
    
    if ans == num2:
        print(num2-1)
    else:
        print(ans)

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

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

  min_abs = 101
  min_e = 0
  for i in p:
    if abs(x-i) < min_abs:
      min_abs = abs(x-i)
      min_e = i

  if min_abs == 0 and min_e not in p:
      print(min_e)
      return

  for i in range(1, 101):
    if min_e - i not in p:
      print(min_e - i)
      return
    if min_e + i not in p:
      print(min_e + i)
      return
    
main()

Solution (Python):
x,n=map(int,input().split())
if n!=0:
    l=list(map(int,input().split()))
    if x not in l:
        print(x)
    else:
        for i in range(120):
            if x - i not in l:
                print(x-i)
                break
            if x + i not in l:
                print(x+i)
                break
else:
    print(x)

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

if n == 0:
  print(x)

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

  xu = x
  uc = 0
  while xu in p:
    xu += 1
    uc += 1

  xd = x
  dc = 0
  while xd in p:
    xd -= 1
    dc += 1
  
  if uc < dc:
    print(xu)
  else:
    print(xd)

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

minv=110
v=0

if X in P:
  for i in range(200):
    if not(i in P):
      if abs(X-i) < minv:
        minv=abs(X-i)
        v=i
else:
  v=X
       

print(v)

Solution (Python):
import numpy as np
def calc_double(nn):
    return nn -x

x,n = list(map(int,input().split()))
p= list(map(int,input().split()))
p_all = list(range(-200,200,1))

l_in = [s for s in p_all if s not in p]

data2 = []
for val in l_in:
    data2.append(abs(calc_double(val)))

min_index =np.argmin(data2)
print(l_in[min_index])

Solution (Python):
X,N=map(int, input().split())
NL=list(map(int, input().split()))
BL=[i for i in range(-1,102)]

for i in NL:
    BL.remove(i)

ANS=1000
out=1000
for i in BL:
    temp=abs(X-i)
    if ANS>temp:
        ANS=temp
        out=i
print(out)

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

num = []
for i in range(102):
    num.append(i)
for j in range(n):
    num.remove(p[j])

a = 1000000000000
b = 0
for k in range(102-n):
    if(abs(x-num[k]) < a):
        a = abs(x-num[k])
        b = num[k]

print(b)

Solution (Python):
import numpy as np
a = list(map(int,input().split()))

x = a[0]
n = a[1]

if (n == 0):
    print(x)
else:
    d = list(map(int,input().split()))
    min_int = d[np.argmin(d)]
    max_int = d[np.argmax(d)]
    if (x < min_int or max_int < x):
        print(x)
    else:
        p = []
        for var in range(min_int - 10,max_int + 10):
            if var not in d:
                p.append(var)
            else:
                continue
        ans = []
        for pp in p:
            ans.append(np.abs(pp - x))
        ans = np.array(ans)
        print(p[np.argmin(ans)])

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

Solution (Python):
x, n = map(int, input().split())
integers = list(map(int, input().split()))
integers.sort()
if len(integers) == 0:
    print(x)
    exit()
x1 = x
while x1 in integers:
    x1 -= 1
x2 = x
while x2 in integers:
    x2 += 1
if x-x1 > x2-x:
    print(x2)
else:
    print(x1)

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

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

    if (n == 0):
        print(x)
    else:
        for i in range(100):
            low = x - i
            if (low not in p):
                print(low)
                sys.exit()
            up = x + i
            if (up not in p):
                print(up)
                sys.exit()
                
main()

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

def minusx(f):
    return f-x

if n !=0:
    plist =list(map(int,input().split(" ")))
    for i in range(100):
        if x-i not in plist:
            print(x-i)
            break
        elif x+i not in plist:
            print(x+i)
            break
else:
    print(x)

Solution (Python):
x,n=map(int,input().split())
try:
    p= list(map(int, input().split()))
except:
    print(x)
else:
    for i in range(150):
        if p.count(x)==0:
            print(x)
            exit()
        elif (p.count(x-i)==0):
            print(x-i)
            exit()
        elif(p.count(x+i)==0):
            print(x+i)
            exit()

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

    num = []
    for i in range(-49,150):
        num.append(abs(x-i))

    for i in range(n):
        num[p[i]+49] = 1000

    min = 1000
    ansnum = -49
    for i in range(len(num)):
        if min > num[i]:
            min = num[i]
            ansnum = i-50

    print(ansnum+1)
else:
    print(x)

Solution (Python):
import numpy as np

def ForbiddenList():

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

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

    if len(NumB) != 0:
        result = list(range(min(NumB)-1, max(NumB)+2, 1))

        for data in NumB:
            result.remove(data)

        idx = np.abs(np.asarray(result) - NumA[0]).argmin()

        print(result[idx])

    else:
        print(NumA[0])
    

if __name__ == '__main__':
    ForbiddenList()

Solution (Python):

F = input().split()

X = int(F[0])
N = int(F[1])
k = 0
L = -1

if N == 0:
	q = [N]

else:
	p = list(map(int, input().split()))
	p.sort()
	q = list(set(p))

while k == 0:
	L += 1
	deka = X+L
	tibi = X-L
	for i in range(len(q)):
		if q[i] == deka:
			deka = 999
		if q[i] == tibi:
			tibi = 999
	if deka != 999 or tibi != 999:
		k = 1

if tibi == 999:
	print(deka)

else:
	print(tibi)

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

def abs_search(o,*l):
    if X  not in p:
        print(X)
        return
    
    for pl_num in range(X+1,102):
        if pl_num not in p:
            break
            
    for mi_num in range(X-1,-1,-1):
        if mi_num not in p:
            break
            
    abs_pl=abs(pl_num-X)
    abs_mi=abs(mi_num-X)
    
    if abs_pl<abs_mi:
        print(pl_num)
    else:
        print(mi_num)
        
abs_search(*p)

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

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

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

for i in range(0, 101):
    i1 = x - i
    i2 = x + i
    if i1 not in p:
        print(i1)
        break
    elif i2 not in p:
        print(i2)
        break
    else:
        continue

Solution (Python):
def main():
    X, N = map(int, input().split())
    p = set(map(int, input().split()))
    for diff in range(N+3):
        if X - diff not in p:
            print(X - diff)
            return
        if X + diff not in p:
            print(X+diff)
            return

if __name__ == '__main__':
    main()

Solution (Python):
X, N = map(int, input().split())
if N !=0:
  A = list(map(int, input().split()))
  A.sort()
MIN = 1000
if N ==0:
  print(X)
elif not X in A:
  print(X)
else:
  for i in range(X*10):
    N = abs(X - i)
    if not i in A:
      if MIN > N:
        Z = i
        MIN = N
  print(Z)

Solution (Python):
X,N=map(int,input().split())
if N==0:
	print(X)
	exit()
p=list(map(int,input().split()))
if X not in p:
	print(X)
	exit()
tmp=101
for i in range(200):
	if i not in p:
		if tmp>abs(X-i):
			ans=i
			tmp=abs(X-i)
print(ans)

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

ans = 10**19
num = []
arr = []

if not p:
    print(x)
    exit()

for i in range(min(p)-1, max(p)+2):
    if i in p:
        continue
    
    
    
    
    num.append(i)
    arr.append([abs(x-i)])
    ans = abs(x-i)

mm = 10**10

for i in range(len(arr)-1):
    if arr[i] <= arr[i+1]:
        print(num[i])
        exit()

print(num[-1])

Solution (Python):
x,n=map(int,input().split())
if n==0:
  print(x)
else:
  a=list(map(int,input().split()))
  flag=0
  i=0
  while flag==0:
    continueflag=0
    for j in range(n):
      if a[j]==x-i:
        continueflag=1
        break
    if continueflag==0:
      print(x-i)
      break
      
    continueflag=0
    for j in range(n):
      if a[j]==x+i:
        continueflag=1
        break
    if continueflag==0:
      print(x+i)
      break
    i=i+1

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

Solution (Python):

def main():
	x,n=map(int,input().split())
	p=[]
	try:
		p=list(map(int,input().split()))
	except:
		print(str(x))
		return
	p=set(p)
	ans=0
	ansc=x
	for i in range(1,102):
		if not(i in p):
			a=min(abs(x-i),ansc)
			if(a!=ansc):
				ans=i
				ansc=a
	print(ans)
main()

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

ans=1000
flg=False
if X not in p:
    print(X)
    flg = True
else:
    for i in range(0,102):
        if i not in p and abs(X-i)<abs(X-ans) and i!=X:
            ans=i
        
if flg==False:
    print(ans)

Solution (Python):
x,n = map(int, input().split())
valid = [1] *101
p = list(map(int, input().split()))
for i in range(n):
	valid[p[i]] = 0



for j in range(100):



	if((x-j) >= 1):
		if(valid[x-j] == 1):
			print(x-j)
			break
	else:
		print(0)
		break
	if((x+j) <= 100):

		if(valid[x+j] == 1):
			print(x+j)
			break
	else:
		print(101)
		break

Solution (Python):
from sys import stdin,stdout
import math
from collections import deque,defaultdict
from math import ceil,floor,inf,sqrt,factorial,gcd,log2
from copy import deepcopy
ii1=lambda:int(stdin.readline().strip())
is1=lambda:stdin.readline().strip()
iia=lambda:list(map(int,stdin.readline().strip().split()))
isa=lambda:stdin.readline().strip().split()
mod=1000000007










x,n=iia()
if n==0:
    print(x)
elif x<=0:
    print(x)
else:
    arr=iia()
    arr.sort()
    dp = [-1,0]
    res=inf
    for i in range(1,101):
        if i not in arr:
            dp.append(i)
    dp.append(101)
    dp.append(102)
    for j in dp:
        if abs(j-x)<res:
            ans = j
            res=abs(j-x)
    print(ans)

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

Solution (Python):
x,n=map(int,input().split())
lis=[]
if n==0:
    print(x)
else:
    y=sorted(int(_) for _ in input().split())
    for i in range(n):
        a=y[i]-x
        lis.append(a)
    L=l=0
    while l in lis:
        l-=1
    while L in lis:
        L+=1
    print(x+L if abs(L)<abs(l)  else x+l)

Solution (Python):

X, N= map(int, input().split())
if N == 0:
  print(X)
else:
  p = input().split()
  i = 0
  while True:
    if (str(X-i) in p) == False:
      print(X-i)
      break
    elif (str(X+i) in p) == False:
      print(X+i)
      break
    else:
      i += 1

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

p = list(map(int, input().split()))
p.sort()
y = 0
count = 0
for i in range(0, n):
    if p[i] == x:
        y = i
    else:
        count += 1

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

min = p[y] - 1
max = p[y] + 1
for i in reversed(range(0, y)):
    if p[i] != min:
        break
    else:
        min -= 1

for i in range(y+1, n):
    if p[i] != max:
        break
    else:
        max += 1

if p[y] - min < max - p[y]:
    print(min)
elif p[y] - min > max - p[y]:
    print(max)
elif p[y] - min == max - p[y]:
    print(min)

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

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

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



for i in range (100+1):
  if(X-i) not in P:
    print(X-i)
    exit()
  elif (X+i) not in P:
    print(X+i)
    exit()
      
  else:
    continue

Solution (Python):
x, n = map(int, input().split())
P = list(map(int, input().split()))
a = 0
b = 0

i = x
for i in reversed(range(x)):
    if i in P:
        i = i-1
    else:
        break
a = x -i

j = x
for j in range(j,101):
    if j in P:
        j = j + 1
    else:
        break
b = j - x

if a <= b:
    print(i)
else:
    print(j)

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

for i in range(-200, 200):
    if i in p:
        continue
    if min_n > abs(x-i):
        min_n = abs(x-i)
        ans = i

print(ans)

Solution (Python):

import sys
import numpy as np


def solve(X: int, N: int, p: "List[int]"):
    ii = [i for i in range(-10,110)]
    iii = sorted(list(set(ii) - set(p)))
    idx = np.abs(np.asarray(iii) - X).argmin()
    print(iii[idx])
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  
    N = int(next(tokens))  
    p = [int(next(tokens)) for _ in range(N)]  
    solve(X, N, p)

if __name__ == '__main__':
    main()

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


pp=[abs(i-X) for i in p]
ans=0
if 0 not in pp:
    print(X)
else:
    for a in range(1,X+1):
        if pp.count(a)>=2:
            continue
        else:
            ans=a
            break
    
    if X-ans in p:
        print(X+ans)
    else:
        print(X-ans)

Solution (Python):

"""AtCoder Beginner Contest 170: C - Forbidden List
https://atcoder.jp/contests/abc170/tasks/abc170_c
"""


def main():
    X, N = list(map(int, input().split()))
    Ps = list(map(int, input().split()))

    ans = X
    min_diff = float('inf')
    for d in range(102):
        if d in Ps:
            continue

        v = abs(X - d)
        
        if v < min_diff:
            min_diff = v
            ans = d

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
x, n = map(int, input().split())
p = list(map(int, input().split()))
len=float("inf")
memo=list(range(-100,300))
ans=[[float("inf")] for i in range(10000)]
for i in p:
    memo.remove(i)
for i in memo:
    if abs(x-i)<=len:
        len=abs(x-i)
        ans[len].append(i)
ans[len].sort()
print(ans[len][0])

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

if n>=1:
    p=list(map(int,input().split()))
else:
    print(x)
    sys.exit()
s=[]
d={}
l={}
for i in range(-105,200):
    if i not in p:
        s.append(i)


for k in s:

    d[k]=abs(x-k)


l=[m[0] for m in d.items() if m[1]==min(d.values())]
print(min(l))

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

for i in range(102):
    if i in p:
        ans = ans
    else:
        
        if abs(x - i) < pc:
            
            
            pc = abs(x - i)
            
            ans = i
    
if abs(x + 1) <= pc:
    print(-1)
else:
    print(ans)

Solution (Python):

x, n = map(int, input().split())
if n != 0:
  p = list(map(int, input().split()))
  
  p.sort()
  x_plus = 0
  x_search = x
  for i in range(n):
    if p[i] == x_search:
      x_search += 1
      if i == n-1:
        x_plus = x_search
    elif p[i] > x_search:
      x_plus = x_search
      break
  p.sort(reverse=True)
  x_minus = 0
  x_search = x
  for i in range(n):
    if p[i] == x_search:
      x_search -= 1
      if i == n-1:
        x_minus = x_search
    elif p[i] < x_search:
      x_minus = x_search
      break
  if abs(x_plus - x) - abs(x_minus -x) >= 0:
    print(x_minus)
  else:
    print(x_plus)
else:
  print(x)

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

for i in range (-101, 102, 1):
  c_list.append(i)

if n == 0:
  ans = x
else:
  p = list(map(int, input().split()))
  for i in range(len(p)):
    c_list[c_list.index(p[i])] = 250
  
  diff = 500
  for i in range(len(c_list)):
    if abs(x - c_list[i]) < diff:
      diff = x - c_list[i]
      ans = c_list[i]

print(ans)

Solution (Python):
X,N=map(int, input().split())
ans=0
flag=0

if N!=0:
	P=sorted(list(map(int, input().split())))
	pabs=[]
	
	for p in P:
		pabs.append(abs(X-p))
	pabs.sort()
	
	if 0 in pabs:
		for i in range(1,max(pabs)+1):
			if i in pabs:
				
				if pabs.count(i)==1:
					if X-i not in P:
						ans=X-i
						flag=1
						break
					else:
						ans=X+i
						flag=1
						break
					
				else:
					continue
				
			else:
				ans=X-i
				flag=1
				break
		
		print(X-max(pabs)-1 if flag==0 else ans)
										
	else:
		print(X)
		
else:
	print(X)

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