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):

X,N = map(int,input().split())
P = list(map(int,input().split()))
i=0
j = 0
while X+i<=101:
    if X+i not in P:
        ans1 = X+i
        break
    i += 1
while X-j>=-1:
    if X-j not in P:
        ans2 = X-j
        break
    j += 1
if ans1-X>=X-ans2:
    print(ans2)
else:
    print(ans1)

Solution (Python):
def main():
  X, N = map(int, input().split())
  if N == 0:
    print(X)
    return
  p = tuple(map(int, input().split()))  
  if X not in p:
    print(X)
    return
  
  not_p = list(set([i for i in range(max(p)+2)]) - set(p))
  not_p_X = [abs(X - i) for i in not_p]
  print(not_p[not_p_X.index(min(not_p_X))])
    
main()

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

def main():
    if n == 0:
        print(x)
        return

    ans_l = list(range(-100, 201))

    diff_l = list(set(p) ^ set(ans_l))
    diff_l.sort()

    cnt = 100
    ans = 100
    for i in range(0, len(diff_l)):
        check = abs(diff_l[i]-x)
        if check < cnt:
            cnt = check
            ans = diff_l[i]
    print(ans)
    return

main()

Solution (Python):
import numpy as np

x,n=map(int,input().split())
a=[]*n
a=list(map(int,input().split()))
answer=0
b=[i for i in range(n+x+10)]
c=list(set(b)-set(a))
d=[x for i in range(len(c))]
e=[abs(x-y) for (x,y) in zip(c,d)]
f=np.argmin(e)
print(c[f])

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

for i in range(0,100):
    if not x-i in p:
        print(x-i)
        break
    else:
        if not x+i in p:
            print(x+i)
            break

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

if n!=0:
    p_list=[int(i) for i in input().split()]
    
    if x not in p_list:
        print(x)
        
    else:
        i=1
        while True:
            if (x-i) not in p_list:
                print(x-i)
                break
            elif (x+i) not in p_list:
                print(x+i)
                break
            else:
                i+=1
                


else:
    print(x)

Solution (Python):
x, n = map(int, input().split())
if n == 0:
  print(x)
else:
  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
    else:
      pass

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

not_in_p = list(range(-101,102))
for pn in p:
    if pn in not_in_p:
        not_in_p.remove(pn)

diff_p = []
for not_in_pn in not_in_p:
    diff_p.append(abs(not_in_pn - X))
answer = not_in_p[diff_p.index(min(diff_p))]

print(answer)

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

if N == 0:
    print(X)

elif X not in p:
    print(X)
    
else:
    for i in range(110):
        if (X-(i+1)) in p and (X+i+1) in p:
            continue
    
        else:
            if(X-(i+1)) not in p:
                print(X-(i+1))
                break
    
            elif (X+i+1) not in p:
                print(X+i+1)
                break

Solution (Python):
from sys import stdin


X,N=[int(x) for x in stdin.readline().rstrip().split()]
P=[int(x) for x in stdin.readline().rstrip().split()]
l=[i for i in range(-1,102) if i not in P]
abslist = list(map(lambda a:abs(a-X),l))
print(l[abslist.index(min(abslist))])

Solution (Python):
from sys import stdin
input = stdin.readline

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

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

li = []





def dfslower(std) :
    """
    argument x : 基準となる数字
    y 結果となりうる数字？
    return : 結果
    """
    if std  in p_list:
        return dfslower(std-1)
        
    else:
        return std
        

def dfsupper(std) :
    """
    argument x : 基準となる数字
    y 結果となりうる数字？
    return : 結果
    """
    if std  in p_list:
        return dfsupper(std+1)
        
    else:
        return(std)

mininte = dfslower(x)
maxinte =  dfsupper(x)

if abs(mininte-x)> abs(maxinte -x):
    print(maxinte)
elif abs(mininte-x) <= abs(maxinte -x):
    print(mininte)

Solution (Python):
X, N = map(int, input().split(' '))
found = False
goal = 0
challenge_plus = X
challenge_minus = X





if(N == 0):
  goal = X
  found = True
else:
  p_list = list(map(int, input().split(' ')))
  max_p = max(p_list)
  min_p = min(p_list)
  
  
  
  
  if not(X in p_list):
    goal = X
    found = True
  else:
    for i in range(102):
      tmp_break = False
      challenge_plus += 1
      challenge_minus -= 1
      
      if not (challenge_plus in p_list):
        goal = challenge_plus
        found = True
        tmp_break = True
      
      if not(challenge_minus in p_list):
        goal = challenge_minus
        found = True
        break
        
      if(tmp_break):
        break

if(found):
  print(goal)
else:
  challenge_plus += 1
  challenge_minus -= 1
  
  
  
  if(dist_plus < dist_minus):
    print(challenge_plus)
  else:
    print(challenge_minus)

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


ret = 0
diff = 0
flag = False
while True:
    flag = False
    ret = x - diff
    
    for i in p:
        if i == ret:
            flag = True
            break
    if flag == False:
        break

    flag = False    
    ret = x + diff
    
    for i in p:
        if i == ret:
            flag = True
            break
    if flag == False:
        break

    diff += 1

print("{}".format(ret))

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

if N == 0:
  print(X)
else:
  p_list = sorted(p_list)
  all_range = list(range(102))
  A = [i for i in all_range if i not in p_list]
  B = [abs(i - X) for i in A]

  low = X - min(B)
  high = X + min(B)

  output = 0
  if high > 101:
    output = low
  if low < 0:
    output = high

  if output != 0:
    print(output)
  elif high in p_list:
    print(low)
  elif low in p_list:
    print(high)
  else:
    print(low)

Solution (Python):
x, n = map(int, input().split())
p = list(map(int, input().split()))
if p == []:
    print(x)
    exit()
t = [0]*(max(p)+2)
for i in p:
    t[i] = 1

mi = t[:x+1]
ma = t[x:]
mi.reverse()
mii = mi.index(0)
maa = ma.index(0)

if mii < maa:
    print(x-mii)
elif mii > maa:
    print(x+maa)
elif mii == maa:
    print(x-mii)

Solution (Python):
x,n=map(int,input().split())
p=list(map(int,input().split()))
m=float("inf")
m1=float("inf")
if n==0:
    print(x)
else:
    for i in range(x,x-100,-1):
        if i not in p:
            m=i
            break
    for i in range(x+1,x+100):
        if i not in p:
            m1=i
            break
    diff=abs(x-m)
    diff1=abs(x-m1)
    if diff<diff1:
        print(m)
    elif(diff>diff1):
        print(m1)
    else:
        print(min(m,m1))

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

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

    if x not in p:
        print(x)
    else:
        off = 1
        for i in range(200):
            k = x - off
            if k not in p and -99 < k <= 200:
                print(k)
                break
            k = x + off
            if k not in p and -99 < k <= 200:
                print(k)
                break
            off += 1

if __name__ == '__main__':
    main()

Solution (Python):




x,n = map(int, input().split())
def deflis(n):
    tempn=int(n)
    return tempn-x
num_list = list(map(deflis, input().split()))
num_list.sort()
count=0
maxans=0
minans=0
maxflag=False
minflag=False
minlist=[]
maxlist=[]
for num in num_list:
    if(num<0):
        minlist.append(num)
    elif(num==0):
        minlist.append(num)
        maxlist.append(num)
    else:
        maxlist.append(num)

for mintemp in range(len(minlist)):
    if(minlist[len(minlist)-mintemp-1]==minans):
        minans=minans-1
for maxtemp in maxlist:
    if(maxtemp==maxans):
        maxans=maxans+1

if(abs(minans)>abs(maxans)):
    print(x+maxans)
else:
    print(x+minans)

Solution (Python):
X,N = map(int,input().split())
if N > 0:
    A = list(map(int,input().split()))
    d = {}
    for i in range(102):
        d[i] = 0
    for a in A:
        d[a] = 1
    for i in range(0,100):
        x = X - i
        y = X + i
        if d[x] == 0:
            print(x)
            quit()
        if d[y] == 0:
            print(y)
            quit()
else:
    print(X)

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

x = X
y = X
i = True
while i:
    x += 1
    i = False
    for n in range(N):
        if x == p[n]:
            i = True
i = True
while i:
    y -= 1
    i = False
    for n in range(N):
        if y == p[n]:
            i = True
p.append(X)
if len(p) == len(set(p)):
    print(X)
    sys.exit(0)
if abs(X-x) < abs(X-y):
    ans = x
else:
    ans = y
print(ans)

Solution (Python):
l = list(range(-100,205))
num1 = [int(s) for s in input().split()]
in_tmp = input()
flag = False
if in_tmp == '':
    flag = True
if flag == False:
    num2 = [int(s) for s in in_tmp.split()]

    for n in num2:
        l.remove(n)
        l_list = [int(s) for s in l]
    abs_min = 500
    num_min = 500
    for n in l_list:
        tmp = abs(num1[0] - n)
        if abs_min > tmp:
            abs_min = tmp
            num_min = n
        if abs_min == tmp:
            if num_min > n:
                num_min = n
    print(num_min)
if flag == True:
    print(num1[0])

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

A = [0]*101

for i in P:
    A[i] = 1

if A[X] == 0:
    print(X)
    exit()

count = 1
while(1):
    if (X - count) >= 0:
        if (X - count) < 101:
            if A[X - count] == 0:
                print(X - count)
                exit()
        else:
            print(101)
            exit()

    if count > 0:
        count = -count
    else:
        count = -count
        count += 1

Solution (Python):
x,n = map(int, input().split())
if n == 0:
    print(x)
else:
    lst = list(map(int, input().split()))
    
    left = x
    right = x
    while left>= -1 and right <= 101:
        if left not in lst:
            print(left)
            break
        if right not in lst:
            print(right)
            break
         
        left -= 1
        right += 1

Solution (Python):
def main():
    X,N = map(int, input().split())
    P = list(map(int, input().split()))
    numup = X
    numdown = X
    a = True
    while a:
        if numdown not in P:
            a = False
            return print(numdown)
        elif numup not in P:
            a = False
            return print(numup)
        else:
            numdown -= 1
            numup += 1
main()

Solution (Python):
a, b = map(int, input().split())
if b != 0:
    c = input()
    l = c.split()
    cc = [int(s) for s in l]
    ccc =list(cc)
    for i in range(a,102):
        if i in ccc:
            continue
        else:
            x = i
            break
    for i in reversed(range(0, a)):
        if i in ccc:
            continue
        else:
            y = i
            break
    if x-a<a-y:
        print(x)
    else:
        print(y)
else:
    d = input()
    print(a)

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

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

for i in range(100):
    if (x - i) not in plist:
        print(x - i)
        exit()
    if (x + i) not in plist:
        print(x + i)
        exit()

Solution (Python):
a, b = map(int, input().split())
if b == 0:
    print(a)
else:
    lis = list(map(int, input().split()))
    tt = [0] * 101
    for k in range(b):
        tt[lis[k]] = 1
    
    if tt[a] == 0:
        print(a)
        exit()
    for k in range(101):
        if a -k < 1:
            print(a-k)
            exit()
        if tt[a - k] == 0:
            print(a-k)
            exit()
        if a + k > 100:
            print(a+k)
            exit()
        if tt[a + k] == 0:
            print(a+k)
            exit()

Solution (Python):


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

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

else:
  P = list(map(int,input().split()))
  P_set = list(set(P))
  
  
  ans_chk = 0
  
  if ( X < P_set[0] or X > P_set[N-1] ):
    
    print(X)
    ans_chk = 1
  
  if ( ans_chk==0 ):
    for i in range(N):
      if ( P_set[i] == X ):
        X_i = i
        break
      elif ( P_set[i] > X ):
        
        print(X)
        ans_chk = 1
        break
  
  if ( ans_chk==0 ):
    
    if ( X_i > N-(X_i+1) ): 
      M = N-(X_i+1)
      temp_ans = X + N-(X_i+1) +1
      
      
      for i in range(1,M+1):
        if ( P_set[ X_i -i ] != X-i ):
          print(X-i)
          ans_chk = 1
          break
        elif ( P_set[ X_i +i ] != X+i ):
          print(X+i)
          ans_chk = 1
          break
      
      if ( ans_chk==0 ):
        if ( P_set[ X_i -(M+1) ] != X-(M+1) ):
          print( X-(M+1) )
          ans_chk = 1
  
  
    else: 
      M = X_i
      temp_ans = X - X_i -1
      
    
      for i in range(1,M+1):
        if ( P_set[ X_i -i ] != X-i ):
          print(X-i)
          ans_chk = 1
          break
        elif ( P_set[ X_i +i ] != X+i ):
          print(X+i)
          ans_chk = 1
          break
  
  if ( ans_chk==0 ):
    print(temp_ans)

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

Z = int(X)
flag = 0
count = 0

while flag != 2:

    flag = 0

    for num in datalist:

        if int(num) == Z:

            flag = 1
            break



    if flag == 0:

        print(Z)
        flag = 2




    count = abs(count) + 1
    if (count % 2) == 1:
       Z += count * (-1)
    else:
       Z += count

Solution (Python):
x, n = map(int, input().split())
if n != 0:
    p = list(map(int, input().split()))
    
    
    
    
    min = 1e9
    ans = 0
    for i in range(102):
        
        if i in p:
            continue
        sa = abs(x - i)
        
        if min > sa :
            min = sa
            ans = i
if n == 0:
    print(x)
else:
    print(ans)

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

array = [[0]]*200
if n == 0:
    print(x)
else:
    for i in range(200):
        array[i] = 0
    tmp = input().split(' ')
    for i in range(n):
        array[int(tmp[i])] = 1
    
    dif_tmp = 999
    ret = 999
    for i in range(200):
        if array[199-i] == 0:
            if abs(x-(199-i)) <= dif_tmp:
                ret = 199-i
                dif_tmp = abs(x-(199-i))
    for i in range(1,100):
        if abs(x+i) <= dif_tmp:
            ret = -i
            dif_tmp = abs(x+i)
    print(ret)

Solution (Python):
x, n = map(int, input().split())
p = []
p = list(map(int, input().split()))
i = 0
j = 0
ans = 0
check = 0
if(n == 0):
    check = 1
    print(x)
for i in range(200):
    X = x + ((-1) ** (i)) * int((i + 1) / 2)
    for j in range(n):
        if(X == p[j]):
            ans = 1
            break
        ans = 0
    if(ans == 0) and (check == 0):
        print(X)
        break

Solution (Python):
x,n=map(int,input().split())
if n==0:
  print(x)
  quit()
lst=list(map(int,input().split()))
a=list(range(-1,102))
for i in lst:
  if i in a:
    a.remove(i)
if len(a)==0:
  print(x)
  quit()
b=[]
for j in a:
  b.append(abs(j-x))
print(a[b.index(min(b))])

Solution (Python):

num, i = map(int, input().split())
if(i != 0):
  s = set(map(int, input().split()))
else:
  s = set()
m = set(range(102))
o = list(m-s)
o2 = list(map(lambda x: abs(x - num), o))
print(o[o2.index(min(o2))])

Solution (Python):
x,n = map(int,input().split())
p = list(map(int,input().split()))
ans = 10**18
l = []
if x not in p:
  print(x)
else:
  for i in range(-1,102):
    if (abs(i - x) < abs(ans - x)) and (i not in p):
      ans = i
  print(ans)

Solution (Python):
import sys

x, n = map(int, input().split())
pn = list(map(int, sys.stdin.readline().rstrip().split()))

if x not in pn:
    print(x)
    exit(0)

for i in range(1,100):
    if x-i not in pn:
        print(x-i)
        exit(0)
    elif x+i not in pn:
        print(x + i)
        exit(0)

Solution (Python):
import math

def a():
    x = list(map(int, input().split()))
    print(x.index(0) + 1)


def b():
    x, y = map(int, input().split())
    if x * 2 <= y <= x * 4 and y % 2 == 0:
        print('Yes')
    else:
        print('No')



def c():
    x, n = map(int, input().split())
    p = list(map(int, input().split()))
    for i in range(100):
        temp = x - i
        if temp >= 0 and temp not in p:
            print(temp)
            break
        temp = x + i
        if temp not in p:
            print(temp)
            break



def d():
    print('')


c()

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

for i in range(n):
  if X-i not in p:
    print(X-i)
    break
  elif X+i not in p:
    print(X+i)
    break
  else:
    continue

Solution (Python):
str1 = input()
str2 = input()

A = str1.split(" ")
B = str2

res = 0

if A[1] == "0":
    res = A[0]
else:

    B = B.split(" ")
    intB = []
    for i in B:
        intB.append(int(i))
    intB.sort(reverse=True)

    X = int(A[0])
    N = int(A[1])

    res = 0
    diff = 999999

    
    l = list(range(-101, 102))

    
    for i in range(0, N):
        l.pop(intB[i]+101)

 
    for i in l:
        if 0 == abs(X - int(i)):
            diff = 0
            res = i
            break
        elif diff > abs(X - int(i)):
            diff = abs(X - int(i))
            res = i



print(res)

Solution (Python):
from sys import stdin
X, N = [int(x) for x in stdin.readline().rstrip().split()]
P = [int(x) for x in stdin.readline().rstrip().split()]
ans = 0
if N == 0 or X not in P:
    ans = X
else:
    i = True
    k = True
    a = X
    b = X
    while i:
        a += 1
        i = a in P
    while k:
        b -= 1
        k = b in P
    if abs(X - a) == abs(X - b):
        if a > b:
            ans = b
        else:
            ans = a
    else:
        if  abs(X - a) > abs(X - b):
            ans = b
        else:
            ans = a
print(ans)

Solution (Python):
import numpy as np

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

if N == 0:
    print(X)
else:
    A = [i for i in range(1,210)]

    for i in P:
        A.remove(i)

    a = (np.array(A) - X)**2
    j = np.argmin(a)
    if (A[j] - X)**2 >= X**2:
        print(0)
    else:
        print(A[j])

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

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

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

for i in range(N):
    if X-i not in P:
        ans = X-i
        break
    elif X+i not in P:
        ans = X+i
        break

print(ans)

Solution (Python):
xn=input()
x,n=xn.split()
if n=='0':
  print(int(x))
else:
  p=input()
  p={int(i) for i in p.split()}
  s={i for i in range(-150,150)}
  s_p=list(s-p)
  d=[abs(i-int(x)) for i in s_p]
  print(s_p[d.index(min(d))])

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

P_ori=list(map(int,input().split()))
if P_ori.count(X)==0:
    print(X)
    exit()


P1=sorted(P_ori)
N=list(range(0,102))
PZ=[]
for i in range(len(N)):
    if P1.count(N[i])==0:
        PZ.append(N[i])

PZ.append(X)
P2=sorted(PZ)
t=P2.index(X)
if P2[t]==P2[0]:
    print(P2[1])
    exit()
elif P2[t]==P2[-1]:
    print(P2[-2])
    exit()
else:
    dist1=abs(P2[t-1]-P2[t])
    dist2=abs(P2[t]-P2[t+1])
    if dist1<=dist2:
        print(P2[t-1])
        exit()
    else:
        print(P2[t+1])
        exit()
print(0)

Solution (Python):
import sys
import bisect

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())


def main():
  X,N = LI()[:]
  if N > 0:
    P = LI()
    P.sort()
  else:
    print(X)
    exit()
  
  
  
  
  index = bisect.bisect_left(P, X)
  
  if index >= N :
    print(X)
    exit()
    
  l = index
  r = index
  for i in range(0,200):
    up = X + i
    down = X - i
    
    
     
    
    if l < 0 or P[l] != down:
      print(down)
      break

    if r >= N or P[r] != up:
      print(up)
      break
    
    l -= 1
    r += 1
    
if __name__ == '__main__':
	main()

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

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

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

allList=[]

for i in range(-201,301):
    allList.append(i)

diff = set(allList) ^ set(p)



diff = list(diff)
diff.append(x)
diff = sorted(diff)



ind = diff.index(x)



    

a = diff[ind-1]
b = diff[ind+1]


ax = abs(x-a)
bx = abs(x-b)



if ax==bx:
    if a < b:
        print(a)
        exit()
    else:
        print(b)
        exit()

if ax > bx:
    print(b)
else:
    print(a)

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

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

abs_n = 0
ans = 0

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

    for i in range(-100,201):
    
        
        if i in p:
            continue
            
        tmp = abs(x-i)
        

        if i == -100:
            abs_n = tmp
            ans = i
        
        if tmp < abs_n:
            abs_n = tmp
            ans = i
        
    print(ans)

Solution (Python):
x, n = map(int, input().split())
if n:
    p = {int(i) for i in input().split()}
if n == 0:
    print(x)
else:
    if x not in p:
        print(x)
    else:
        flag = True
        abs_diff = 1
        while flag:
            for i in range(1, 3):
                ans = x + (-1)**i * abs_diff
                if ans not in p:
                    flag = False
                    print(ans)
                    break
            abs_diff += 1

Solution (Python):
x, n = map(int, input().split())
p = list(map(int, input().split()))
d = list(a*0 for a in range(n))

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())
if N != 0:
  A = list(map(int, input().split()))
else:
  A =[]
B =[]
for i in range(N):
  B.append(A[i]-X)
  B = sorted(B)
for i in range(100):
  if -i not in B:
    print(X-i)
    break
  elif i not in B:
    print(X+i)
    break

Solution (Python):
def read_int():
    return int(input())


def read_ints():
    return map(int, input().split(' '))


x, n = read_ints()
p = []
if n > 0:
    p = list(read_ints())
ans = -1
delta = 1000
for i in range(-1, 102):
    ok = True
    for j in p:
        if j == i:
            ok = False
            break
    if ok:
        d = abs(x - i)
        if d < delta:
            ans = i
            delta = d
print(ans)

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

if n == 0:
    print(x)
else:
    p = list(map(int, input().split()))
    if x not in p:
        print(x)
    
    else:
        while True:
            x1 -= 1
            x2 += 1
        
            if x1 not in p:
                print(x1)
                break
        
            if x2 not in p:
                print(x2)
                break

Solution (Python):
def check(n,p):
    for j in range(0,len(p)):
        if(n==p[j]):
            return False
    return True

def check_main(X,N,p):
    for i in range(0,51):
        if (check(X-i,p)):
            return X-i
        elif(check(X+i,p)):
            return X+i


if __name__ == "__main__":
    X,N = input().split()
    numbers = list(map(int,input().split()))
    X = int(X)
    N = int(N)
    numbers.sort()
    print(check_main(X,N,numbers))

Solution (Python):


import sys

def main():
    numbers=[]
    x,n = map(int,input().split())
    numbers=list(map(int,input().split()))
    if n==0:
        print(x)
        sys.exit()
    dp_list=list(range(-1000, 1000))
    dp_list=set(dp_list)-set(numbers)

    for i in range(101):
        if abs(x-i) in dp_list:
            print(x-i)
            break
        elif abs(x+i) in dp_list:
            print(x+i)
            break

if __name__ == "__main__":
    main()

Solution (Python):
a = input().split()
if a[1] == "0":
  print(a[0])
else:
  number_list = input().split()
  n = 0
  number = int(a[0])
  while True:
    num = number + n
    num2 = number - n
    if str(num) not in number_list or str(num2) not in number_list:
      if str(num) not in number_list and str(num2) not in number_list:
        print(num2)
        break
      if str(num) in number_list:
        print(num2)
      else:
        print(num)
      break
    n += 1

Solution (Python):

import numpy as np
x, n = map(int, input().split())

if n!=0:
    p_list = list(map(int, input().split()))
    kouho = list(range((x-n//2-1),(x+n//2+1)))    
    kouho2 = list(set(kouho) - set(p_list))
    ans = [j for i, j in enumerate(kouho2) if abs(j-x) == min(abs(np.array(kouho2) - x))]
    ans = min(ans)

else:
    ans = x

print(ans)

Solution (Python):
num = list(map(int,input().split()))
if num[1] ==0:
  print(num[0])
else:  
  num_list = list(map(int,input().split()))
  flg = True
  ans = num[0]
  distance = 0

  while flg:
    ch_1 = ans-distance
    ch_2 = ans+distance
    if ch_1 not in num_list:
      print(ch_1)
      flg = False
    elif ch_2 not in num_list:
      print(ch_2)
      flg = False
    else:
      distance +=1

Solution (Python):


def main():
    X,N = map(int,input().split())
    if N == 0:
        print(X)
        exit()
    p = set(map(int,input().split()))
    if N == 100:
        print(0 if X<=50 else 101)
        exit()
    lst = [0] + list(set(range(1,101)) - p) + [101]
    lst2 = [abs(lst[i] - X) for i in range(len(lst))]
    min_ = min(lst2)
    print(lst[lst2.index(min_)])    



if __name__ == '__main__':
    main()

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

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


data_list = [i for i in range(V_RANGE)]

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


sub_list = set(data_list) - set(get_list)


g_abs = 10**4
abs_value = 0
for i in sub_list:
	t_abs = abs(X - i)

	if(g_abs > t_abs):
		g_abs = t_abs
		abs_value = i

print(abs_value)

Solution (Python):
X, N = map(int, input().split())
if not N:
    print(X)
    exit()
p = list(map(int, input().split()))
if X not in p:
    print(X)
    exit()
    
p_low = sorted([X - i for i in p if i < X])
p_high = sorted([i - X for i in p if i > X])

if len(p_low) > len(p_high):
    lng = len(p_low)
else:
    lng = len(p_high)

for i in range(1, lng + 2):
    if i not in p_low:
        print(X - i)
        exit()
    elif i not in p_high:
        print(X + i)
        exit()

Solution (Python):
X,N = map(int,input().split())
if N > 0:
  p = list(map(int,input().split()))
a = 102
ans = 0
for i in range(-1,200):
  if N == 0:
    ans = X
    break
  if p.count(i) == 0 and a > abs(X - i):
    a = abs(X - i)
    ans = i
print(ans)

Solution (Python):
X, N = map(int, input().split())
P = list(map(int, input().split()))
Pli = set(sorted(P))
X1 = X
X2 = X
while True:
    if X1 not in Pli:
        print(X1)
        break
    elif X2 not in Pli:
        print(X2)
        break
    else:
        X1 -= 1
        X2 += 1

Solution (Python):
a=input().split(" ")
b=input().split(" ")
c=0
d=0
e=0
f=int(a[0])
g=int(a[0])
if int(a[1])!=0:
	for i in range(int(a[1])):
		if int(a[0])==int(b[i]):
			c=c+1
elif int(a[1])==0:
	print(a[0])

 
if c>=1:
	while str(f) in b:
		f=f+1
		d=d+1
	while str(g) in b:
		g=g-1
		e=e+1
	if d>e:
		print(g)
	elif e>d:
		print(f)
	elif e==d:
		print(g)
if c==0 and int(a[1])!=0:
	print(a[0])

Solution (Python):
X,N = map(int, input().split())
def intlist(x):
    y = []
    for i in range(len(x)):
        y.append(int(x[i]))
    return y

P = intlist(input().split())

if X not in P:
    print(X)
else:

    for i in range(N):
        if X-i-1 not in P:
            print(X-i-1)
            break
        if X+i+1 not in P:
            print(X+i+1)
            break

Solution (Python):
X,N = map(int,input().split())
if N > 0:
    A = list(map(int,input().split()))
    d = {}
    for i in range(102):
        d[i] = 0
    for a in A:
        d[a] = 1
    for i in range(0,100):
        x = X - i
        y = X + i
        if d[x] == 0:
            print(x)
            quit()
        if d[y] == 0:
            print(y)
            quit()
else:
    print(X)

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

k=100
for i in range(0,150):
    d=abs(X-i)
    if d<k and(i not in list1):
        k=d
        A=i
print(A)

Solution (Python):
import sys
x, y = map(int,input().split())
n = list(map(int, input().split()))
if y == 0:
    print(x)
    sys.exit()
for i in range(100):
    a = [x-i, x+i]
    if set(a)<=set(n):
        pass
    elif x-i not in n:
        print(x-i)
        sys.exit()
    else:
        print(x+i)
        sys.exit()

Solution (Python):
import math 
X, N = map(int,input().split())
d = int(999)
d1 = int()
ans = int(999)
if 0 < N:
    P = list(map(int,input().split()))
    for i in range(999):
        if P.count(i) == 0:
            d1 = abs(X-i)
            if d1 < d and 0 <= d1:
                d = d1
                ans = i
    print(ans)
else:
    print(X)

Solution (Python):
x, n = map(int, input().split())
p = set(map(int, input().split()))
l = {i for i in range(-100, 200)}

s = list(l - p)
min_diff = 1000
ans = 1000

for j in range(len(s)):
    diff = abs(s[j] - x)
    if min_diff > diff:
        min_diff = diff
        ans = s[j]

print(ans)

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

    if not p:
        return X
    a = max(p) + 1
    b = max(p) + 1
    for i in range(max(p) + 1, min(p) - 2, -1):
        if i in p:
            continue
        if abs(X - i) <= a:
            a = abs(X - i)
            b = min(b, i)
    return b


print(main())

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

if n == 0:
    print(x)

else:
    i = 1
    while True:
        t = x-i
        s = x+i
        if x not in p:
            print(x)
            break
        if t not in p:
            print(t)
            break
        if s not in p:
            print(s)
            break
        i +=1