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 math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy,bisect






import sys

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
nf = lambda: float(ns())
na = lambda: list(map(int, stdin.readline().split()))
nb = lambda: list(map(float, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  

X, N = na()
p = na()
kouho = []
for i in range(-100, 200):
    if i in p:
        continue
    kouho.append((abs(X - i), i))
print(min(kouho)[1])

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

a = 100
b = 0
for i in range(0, 102):
    if i not in p and abs(x - i) < a:
        a = abs(x - i)
        b = i

print(b)

Solution (Python):
x,n=map(int,input().split())
l=list(map(int,input().split()))
flag=0
i=0
while flag==0:
    if x-i not in l:
        flag=1
        ansa=x-i
    i+=1
flag=0
i=0
while flag==0:
    if x+i not in l:
        flag=1
        ansb=x+i
    i+=1
if abs(ansa-x)<=abs(ansb-x):
    print(ansa)
else:
    print(ansb)

Solution (Python):
import sys

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

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

if x not in p:
    print(x)
    sys.exit()
    
q=list(i for i in range(p[0]-1,p[-1]+2))

for i in p:
    q.remove(i)

ans=[]
c=x+n
for i in q:
    if c>abs(x-i):
        c=abs(x-i)
        ans.clear()
        ans.append(i)
    if c==abs(x-i):
        ans.append(i)

print(min(ans))

Solution (Python):

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



result = x
for i in range(100):
    if x in l:
        pass
    else:
        result = x
        break

    if x - i in l:
        pass
    else:
        if x - i >= 0:
            result = x - i
            break

    if x + i in l:
        pass
    else:
        if x + i <= 101:
            result = x + i
            break



print(result)

Solution (Python):
x,n=map(int, input().split())
p=list(map(int, input().split()))
dif=0
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):
x,n=map(int,input().split())
p=list(map(int,input().split()))
temp=100
for i in range(x-51,x+51):
    a=abs(x-i)
    if a<temp and i not in p:
        temp=a
        ans=[i]
    if a==temp and i not in p:
        ans+=[i]
print(min(ans))

Solution (Python):
X,N=map(int,input().split())
p=input()
def ans170(X:int, N:int, p:str):
    p_list=list(map(int,p.split()))
    count=1
    if len(p)==0:
        return X
    elif X not in p_list:
        return X
    else:
        while True:
            if X-count not in p_list:
                return X-count
                break
            elif X+count not in p_list:
                return X+count
                break
            else:
                count+=1
print(ans170(X,N,p))

Solution (Python):
X, N = map(int, input().split())
ps = list(map(int, input().split()))
bgr, smr = X, X
while bgr <= 100:
	if bgr not in ps:
		break
	bgr += 1
while smr >= 1:
	if smr not in ps:
		break
	smr -= 1
print(bgr) if bgr - X < X - smr else print(smr)

Solution (Python):
import sys
from collections import deque, defaultdict, Counter
from itertools import accumulate, product, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush
from math import ceil, floor, sqrt, gcd, inf
from copy import deepcopy
import numpy as np
import scipy as sp

INF = inf
MOD = 1000000007

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

tmp = 0
res = 0

P = np.array(P) - x

while True:
    if not -res in P:
        res *= -1
        break
    if not res in P:
        break
    res += 1
res += x

print(res)

Solution (Python):
X, N=map(int,input().split())
p=list(map(int,input().split()))
for d in range(X+1):
  for s in [-1,+1]:
    a=X+s*d
    if p.count(a) == 0: 
      print(a)
      exit(0)

Solution (Python):
import bisect

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

A = {i for i in range(102)}

S = list(A - P)

T = bisect.bisect_left(S, X)

if T == 0:
    print(S[0])
elif X - S[T-1] > S[T] - X:
    print(S[T])
else:
    print(S[T-1])

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

for i in range(x+1):
    for j in [-1, 1]:
        ans = x + i*j
        if not p.count(ans):
            print(ans)
            exit(0)

Solution (Python):
x,n=map(int,input().split())
try:
  p=sorted([*map(int,input().split())])
except:
  print(x);exit()
for i in range(x+1):
  for s in [-1,1]:
    a=x+i*s
    if p.count(a)==0:
      print(a);exit()

Solution (Python):


from collections import Counter

def solve():
    x,n = map(int,input().split())
    if n != 0:
        p = set(map(int,input().split()))
    if n == 0 or x not in p:
        print(x)
        return
    else:
        for i in range(100):
            if x - i not in p:
                print(x - i)
                return
            if x + i not in p:
                print(x + i)
                return


if __name__ == '__main__':
    solve()

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

Solution (Python):
a,b = map(int,input().split())
s = list(map(int,input().split()))
num1 =0
num2 =0
if b ==0:
  print(a)
  exit()
for i in range(100):
    num1 = a-i
    num2 = a+i
    if not num1 in s and not num2 in s:
        print(num1)
        exit()
    if not num1 in s:
        print(num1)
        exit()
    if not num2 in s:
        print(num2)
        exit()

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

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

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

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

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

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

min_val = 101
for i in range(102):
    if i not in p:
        if abs(i - x) < min_val:
            min_val = abs(i - x)
            ans = i
print(ans)

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

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

count = 0

flg = False

lis=[]

result=0

while True:
    
    up = X+count
    
    down = X-count
    
    if p.count(down) ==0:
        lis.append(down)
        flg = True
    
    if p.count(up)==0:
        lis.append(up)
        flg = True
        
    
    if flg ==True:
        break
    else:
        count+=1
        

lis.sort()

print(lis[0])

Solution (Python):
from bisect import bisect

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

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

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

if(n):
    l = [0 for _ in range(102)]
    for i in p:
        l[i] = 1

    for i in range(101):
        if(l[x-i] == 0):
            ans = x-i
            break
        if(l[x+i] == 0):
            ans = x+i
            break
    print(ans)
else:
    print(x)

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

mind = 10**10
ans = -102
for i in range(-101, 102):
    dist = abs(X - i)
    if mind > dist:
        if i not in pi:
            ans = i
            mind = dist


print(ans)

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


def rii():
    return [int(v) for v in input().split()]


def solve():
    X, N = rii()
    P = set(rii())
    n = m = float("inf")
    if not P:
        print(X)
        return

    for i in range(min(P)-1, max(P)+2):
        if i not in P:
            d = abs(i - X)
            if d == m:
                n = min(n, i)
            elif d < m:
                m = d
                n = i
    
    print(n)



if __name__ == "__main__":
    solve()

Solution (Python):
X, N = map(int,input().split())
if N == 0:
  P = []
else:
  P = list(map(int, input().split()))
  P = sorted(P)
assert len(P) == N
cands = []

x = X
while True:
  if x not in P:
    cands.append(x)
    break
  x -= 1

x = X
while True:
  if x not in P:
    cands.append(x)
    break
  x += 1
a,b = cands
if abs(a - X) > abs(b - X):
  print(b)
else:
  print(a)

Solution (Python):
x,_ = list(map(int,input().split()))
p = list(map(int,input().split()))
x_l = x
x_u = x
while(True):
    if(not x_l in p):
        print(x_l)
        break
    if(not x_u in p):
        print(x_u)
        break
    x_l -= 1
    x_u += 1

Solution (Python):
x,n=map(int,input().split())
p=list(map(int,input().split()))
a=101
m=101-x
for i in range(102):
  i=100-i
  if i in p:
    continue
  M=abs(i-x)
  if M<=m:
    m=M
    a=i
print(a)

Solution (Python):
X,N = map(int, input().split())
flg=False
i=1

if N==0:
  Ans=X
else:
  S=list(map(int, input().split()))

  if X not in S:
    Ans=X
    flg=True
    
  while not flg:
    if X-i not in S:
      Ans=X-i
      flg=True
      break
    elif X+i not in S:
      Ans=X+i
      flg=True
      break
    else:
      i+=1
      
print(Ans)

Solution (Python):
""" 170/C
"""
import sys
import math
from functools import reduce
from bisect import bisect_left

def readString():
    return sys.stdin.readline()

def readInteger():
    return int(readString())

def readStringSet(n):
    return sys.stdin.readline().split(" ")[:n]

def readIntegerSet(n):
    return list(map(int, readStringSet(n)))

def readIntegerMatrix(n, m):
    return [lambda _: readIntegerSet(m) for _ in range(0, n)]

def main(X, N, P):
    mP = {}
    for p in P:
        mP[p] = p

    if X not in mP:
        return X

    i = 0
    while True:
        if X-i not in mP:
            return X-i

        if X+i not in mP:
            return X+i

        i += 1


if __name__ == "__main__":
    _X, _N = readIntegerSet(2)
    _P = readIntegerSet(_N)

    print(main(_X, _N, _P))

Solution (Python):
X, N = map(int, input().split())
if N != 0:
  p = set(map(int, input().split()))
  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:
    print(X - i - 1)
else:
  print(X)

Solution (Python):
X, N = map(int, input().split())
if N != 0:
  p = list(map(int, input().split()))
  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:
    print(X - i - 1)
else:
  print(X)

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

Solution (Python):
X,N = (int(x) for x in input().split())
p = sorted(list((int(x) for x in input().split())))
if N == 0:
  print(X)
elif N == 1:
  if p[0] == X:
    print(X-1)
  else:
    print(X)
else:
  ans = float('inf')
  for z in range(0,p[0]):
    if (ans-X)**2 > (z-X)**2 :
      ans = z
  for i in range(N-1):
    for z in range(p[i]+1,p[i+1]):
      if (ans-X)**2 > (z-X)**2 :
      	ans = z
  for z in range(p[-1]+1,102):
    if (ans-X)**2 > (z-X)**2 :
      ans = z
  print(ans)

Solution (Python):
x, n = map(int,input().split())
l = list(map(int,input().split()))
a = 0
ab = 0
for i in range(100):
    if x - i not in l:
        ans = x - i
        a = i + 1
        break
for i in range(100):
    if x + i not in l:
        ansb = x + i
        ab = i + 1
        break
if a > ab:
    print(ansb)
else:
    print(ans)

Solution (Python):
from sys import stdin
readline = stdin.readline
def i_input(): return int(readline().rstrip())
def i_map(): return map(int, readline().rstrip().split())
def i_list(): return list(i_map())

def main():
    X, N = i_map()
    if N == 0:
        print(X)
        exit()
    P = i_list()
    p = list(map(lambda x: abs(x - X), P))
    p.sort()
    for i, j in enumerate(p, 1):
        if i // 2 != j:
            ans = X - (i // 2)
            if ans in P:
                ans = X + (i // 2)
            break
    else:
        if N % 2 == 1:
            ans = X - ((N + 1) // 2)
        else:
            ans = X - (N // 2)
            if ans in P:
                ans = X + (N // 2)
    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
x, n = map(int, input().split())
p = list(map(int,input().split()))
p.sort()
s = x
d = 1
while s in p:
    s = s - d
    d = int((abs(d)+1)*d/abs(d)*(-1))
print(s)

Solution (Python):
x, n = map(int, input().split())
p = list(map(int,input().split()))
s = x
d = 1
while s in p:
    s = s - d
    d = int((abs(d)+1)*d/abs(d)*(-1))
print(s)

Solution (Python):
x,n=map(int,input().split())
l=list(map(int,input().split()))
a=0
for i in range(100):
    if x-i not in l:
        ans=x-i
        a=i+1
        break
for i in range(100):
    if x+i not in l:
        ansb=x+i
        ab=i+1
        break
if a>ab:
    print(ansb)
else:
    print(ans)

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

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

count = 0

flg = False

lis=[]

result=0

while True:
    
    up = X+count
    
    down = X-count
    
    if p.count(down) ==0:
        lis.append(down)
        flg = True
    
    if p.count(up)==0:
        lis.append(up)
        flg = True
        
    
    if flg ==True:
        break
    else:
        count+=1
        

lis.sort()

print(lis[0])

Solution (Python):

    
    


import sys, os.path


    
    

sys.setrecursionlimit(10 ** 5)

def mod(): return 10**9+7
def i(): return sys.stdin.readline().strip()
def ii(): return int(sys.stdin.readline())
def li(): return list(sys.stdin.readline().strip())
def mii(): return map(int, sys.stdin.readline().split())
def lii(): return list(map(int, sys.stdin.readline().strip().split()))



def solve():
    a,b=mii()
    if b==0: print(a) ; return
    c=lii();d=111;e=0
    for i in range(max(c)+2):
        if i not in c:
            if abs(i-a)<d:
                d=abs(i-a)
                e=i
    print(e)
                
for _ in range(1):
    solve()

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

l, r = X, X
ans = float("inf")
while True:
    if l not in forbid:
        ans = l
        break
    if r not in forbid:
        ans = r
        break
    l -= 1
    r += 1

print(ans)

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

sa_min=100

"""
sa=[]
for i in range(N):
    sa.append(p[i]-X)
"""

for i in range(102):
    if sa_min>abs(i-X) and (not i in p):
        sa_min=abs(i-X)
        ans=i

if N==0:ans=X

print(ans)

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

Solution (Python):
x, n = map(int, input().split())
li_p = list(map(int, input().split()))
li_p.sort()
i = 0
while True:
    a = x - i
    b = x + i
    if not a in li_p:
        print(a)
        break
    elif a in li_p and not b in li_p:
        print(b)
        break
    elif a in li_p and b in li_p:
        i += 1

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

if n == 0 or x not in L:
  print(x)
  exit()

for i in range(102):
  if (x-i) not in L:
    print(x-i)
    break
  elif (x+i) not in L:
    print(x+i)
    break

Solution (Python):
x, n = map(int,input().split())
L = list(map(int,input().split()))
l, r = x-1, x+1

if n == 0 or x not in L:
  print(x)
  exit()

while True:
  if l not in L:
    print(l)
    break
  elif r not in L:
    print(r)
    break
  l -= 1
  r += 1

Solution (Python):
x, n = map(int,input().split())
L = list(map(int,input().split()))
l, r = x-1, x+1

if n == 0 or x not in L:
  print(x)
  exit()

while True:
  flg = True
  if l not in L:
    print(l)
    break
  elif r not in L:
    print(r)
    break
  l -= 1
  r += 1

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

if N ==0 or X < min(p) or X > max(p):
    print(X)
else:
    for n in range(N+1):
        if not X - n in p:
            print(X - n)
            break
        elif not X + n in p:
            print(X + n)
            break

Solution (Python):
X,N = map(int, input().split())
p = list(map(int, input().split()))
for d in range(X + 1):
  for s in [-1, +1]:
    a = X + s * d
    if p.count(a) == 0:
      print(a)
      exit(0)

Solution (Python):



x, n = map(int, input().split())
P = list(map(int, input().split()))
xm = x 
xM = x

for i in range(0,100):
    if n == 0:
        print(x)
        break
    xm = x - i
    xM = x + i
    mcounter = 0
    Mcounter = 0
    for j in range(len(P)):
        if xm == P[j]:
            mcounter += 1000
        if xM == P[j]:
            Mcounter += 1000
    if mcounter < 1000:
        print(xm)
        break
    if Mcounter < 1000:
        print(xM)
        break

Solution (Python):
import bisect

X, N = map(int,input().split())
if N == 0:
    Ps = []
else:
    Ps = list(map(int,input().split()))
Ps.sort()
for i in range(300):
    if i % 2 == 0:
        x = i//2
    else:
        x = -((i+1)//2)
    if (X + x) in Ps:
        continue
    else:
        print(X + x)
        break

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

min =10000
temp = 0
num = 10000

for i in range(-1000, 1000):
  temp = abs(x- i)
  
  if temp < min and i not in p:
    min = temp
    num = i
    
print(num)

Solution (Python):
x, n = map(int, input().split())
p = [int(v) for v in input().split()]
ans = None
if x not in p:
    ans = x
else:
    diff = 101
    for i in range(0, max(p) + 2):

        if abs(x - i) < diff and i not in p:
            ans = i
            diff = abs(x - i)
print(ans)

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

ans = None
diff = 1000

if X not in p:
    ans = X
else:
    for i in range(-1, max(max(p), X)+2):
        if i in p:continue
        if abs(X - i) < diff:
            diff = abs(X - i)
            ans = i

print(ans)

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

def INT(): return int(input())
def MAPINT(): return map(int, input().split())
def LMAPINT(): return list(map(int, input().split()))
def STR(): return input()
def MAPSTR(): return map(str, input().split())
def LMAPSTR(): return list(map(str, input().split()))

f_inf = float('inf')

x, n = LMAPINT()
if n == 0:
  _ = input()
  print(x)
  exit()

p = LMAPINT()
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()))

p.sort()

def main():

    if len(p) == 0:
        print(X)
        return

    if X < p[0] and p[-1] < X:
        print(X)

    keep = True
    i = 0
    while keep:
        left_found = (X - i) not in p
        right_found = (X + i) not in p

        if left_found and right_found:
            print(X-i)
            keep = False
        elif left_found:
            print(X-i)
            keep = False
        elif right_found:
            print(X+i)
            keep = False


        i += 1


if __name__ == '__main__':
    main()

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

ans = 0

for i in range(1,102):
    if i not in list(p):
        if abs(x-i)<abs(x-ans):
            ans = i

print(ans)

Solution (Python):
m, n = map(int, input().split())
p = list(map(int, input().split()))
a=0

while True:
    if m-a not in p:
        print(m-a)
        break
    elif m+a not in p:
        print(m+a)
        break
    a+=1

Solution (Python):
X,N=map(int,input().split())
p=list(map(int,input().split()))
ans=0
for i in range(1,102):
    if i not in p:
        if abs(X-i)<abs(X-ans):
            ans=i
print(ans)

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


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

a = 0


while True:
    if x - a not in p:
        print(x - a)
        break
    elif x + a not in p:
        print(x + a)
        break
    a += 1

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

for i in range(100):
    num = x - i
    if num not in p:
        print(num)
        exit()
    num = x + i
    if num not in p:
        print(num)
        exit()

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

gap = x
ans = 0

for y in range(102):
  if y not in p:
    if abs(x - y) < gap:
      gap = abs(x-y)
      ans = y
print(ans)

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

for i in range(100):
    num = x - i
    if num not in p:
        print(num)
        exit()
    num = x + i
    if num not in p:
        print(num)
        exit()

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

gap = x
ans = 0

for y in range(0,102):
  if y not in p:
    if abs(x - y) < gap:
      gap = abs(x-y)
      ans = y
      
print(ans)

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

m=X;i=0
for i in range(m,min(p)-2,-1):
  if i not in p:break
M=X;j=0
for j in range(M,max(p)+2):
  if j not in p:break
if abs(i-X)==abs(j-X):print(min(i,j))
elif abs(i-X)<abs(j-X):
  print(i)
else:print(j)

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

m=min(p)-1
M=max(p)+1



m=X;i=0
for i in range(m,min(p)-2,-1):
  if i not in p:break
M=X;j=0
for j in range(M,max(p)+2):
  if j not in p:break
if abs(i-X)==abs(j-X):print(min(i,j))
elif abs(i-X)<abs(j-X):
  print(i)
else:print(j)

Solution (Python):
import math
X, N = map(int, input().split())
P = list(map(int, input().split()))
ans_1 = X
ans_2 = X
while True:
    if ans_1 not in P:
        print(ans_1)
        exit()
    ans_1 -= 1

    if ans_2 not in P:
        print(ans_2)
        exit()
    ans_2 += 1

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

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

    if not X in P:
        print(X)
        return
    
    for i in range(1, 10000):
        if not X-i in P:
            print(X-i)
            return
        if not X+i in P:
            print(X+i)
            return

main()

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

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

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

    for i in range(n//2 + 2):
        if x - i not in ps:
            print(x-i)
            return
        if x + i not in ps:
            print(x+i)
            return


if __name__ == '__main__':
    main()

Solution (Python):











import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log 
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 fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    X,N=MI()
    P=set(LI())

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

if __name__ == '__main__':
    main()

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

if not X in p:
    print(X)
else:
    for i in range(100):
        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())
p=list(map(int,input().split()))
y=x
z=x
if x not in p:
    print(x)
    exit()
for i in range(2*len(p)):
    y-=1
    z+=1
    if y not in p:
        print(y)
        exit()
    if z not in p:
        print(z)
        exit()

Solution (Python):
import bisect
X, N = map(int, input().split())
if N == 0:
    print(X)
else:
    p = set(map(int, input().split()))
    num_list = set([i for i in range(-1, 102)])
    num_list = sorted(list(num_list ^ p))
    nummin = num_list[bisect.bisect_left(num_list, X)]
    nummax = num_list[bisect.bisect_right(num_list, X)]
    if nummin == nummax:
        nummin = num_list[bisect.bisect_left(num_list, X)-1]
    if X-nummin <= nummax-X:
        print(nummin)
    else:
        print(nummax)

Solution (Python):
X,N = map(int,input().split())
p = list(map(int,input().split()))
count = -1
while True:
    count +=1
    if X-count not in p:
        print(X-count)
        break
    elif X+count not in p:
        print(X+count)
        break

Solution (Python):
X,N = map(int,input().split())
p = list(map(int,input().split()))
diff = 0
while True:
    num_p = X + diff
    num_m = X - diff
    if num_m not in p:
        print(num_m)
        break
    elif num_p not in p:
        print(num_p)
        break
    else:
        diff += 1

Solution (Python):
x, n = map(int, input().split())
p = list(map(int, input().split()))
for i in range(n):
    if p[i] - x >= 0:
        p[i] = 2 * (p[i] - x)
    else:
        p[i] = (x - p[i]) * 2 - 1
p = sorted(p)
i = 0
while i in p:
    i += 1
if i % 2 == 0:
    j = round(i / 2) + x
else:
    j = x - round((i + 1) / 2)
print(j)

Solution (Python):
x,n=map(int,input().split())
if n==0:
  print(x)
  exit()
p=[int(y) for y in input().split()]
a=0
for i in range(101):
  if x-a not in p:
    print(x-a)
    break
  elif x+a not in p:
    print(x+a)
    break
  a+=1

Solution (Python):
[X, N] = [int(i) for i in input().split()]
if N == 0:
    P = []
else:
    P = [int(i) for i in input().split()]

if P.count(X) == 0:
    print(X)
else:
    for i in range(100):
        if P.count(X-i) == 0:
            print(X-i)
            break
        elif P.count(X+i) == 0:
            print(X+i)
            break

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

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

l = [i for i in range(102)]

for j in p:
    l.remove(j)

m = []

for k in l:
    m.append(abs(k-x))

print(l[m.index(min(m))])

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

try:
    p = list(map(int, input().split()))
except:
    p = []
i = 0

while True:
    if X + i not in p:
        ans = X + i
        if X - i not in p:
            ans = X - i
        break
    if X - i not in p:
        ans = X - i
        break
    
    i += 1

print(ans)

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

max_num = max(p)
lst = []
for i in range(max_num+2):
  if i not in p:
    lst.append(i)
tmp = float("inf")
for j in lst:
  if tmp > abs(X-j):
    tmp = abs(X-j)
    ans = j
print(ans)

Solution (Python):
import math , sys

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

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

F = math.inf
ans = math.inf
B  =[]
for i in range( -2 , 102):
    if i not in A:
        B.append(i)

for i in range(len(B)):
    d = abs( X - B[i] )
    
    if d < F:
        F = d
        ans = B[i]
    elif d==F:
        if B[i] < ans:
            ans = B[i]
print(ans)

Solution (Python):
def main():
    x, n = map(int, input().split())
    if n == 0:
        print(x)
        return
    p_tuple = tuple(map(int, input().split()))

    radius = 0
    for i in range(100):
        if x-radius not in p_tuple:
            print(x-radius)
            return
        elif x+radius not in p_tuple:
            print(x+radius)
            return
        else:
            radius += 1


if __name__ == '__main__':
    main()

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

table = [0] * 102
ans = X
dist = 102

for p in P:
  table[p] = 1

for i in range(102):
  if table[i] != 0:
    continue
  if abs(i - X) < dist:
    ans = i
    dist = abs(i - X)
  elif abs(i - X) == dist:
    ans = min(i, ans)

print(str(ans))

Solution (Python):
X, N = map(int,input().split())
P = list(map(int,input().split()))
list = [0] * 102
res = X
dist = 102
for p in P:
    list[p] = 1
for i in range(102):
    if list[i] == 0:
        if abs(i - X) < dist:
            dist = abs(i - X)
            res = i
        elif abs(i - X) == dist:
            res = min(res,i)
print(res)