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())
if N == 0:
    print(X)
    exit()
p = list(map(int, input().split()))

ans_list = [i for i in range(102)]
for i in range(N):
    now = p[i]
    for j in range(len(ans_list)):
        if ans_list[j] == now:
            del ans_list[j]
            break
        
ans = 1000
k = 1000
for i in range(len(ans_list)):
    if abs(ans_list[i] - X) < ans:
        ans = abs(ans_list[i] - X)
        k = ans_list[i]

print(k)

Solution (Python):
X, N = list(map(int, input().split()))
if N==0:
    print(X)
else:
    ps = list(map(int, input().split()))
    sub_abs = 0
    while True:
        if (X-sub_abs) not in ps:
            print(X-sub_abs)
            break
        if (X+sub_abs) not in ps:
            print(X+sub_abs)
            break
        sub_abs += 1

Solution (Python):




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


for x in range(0,101):
    if X-x not in p:
        print(X-x)
        exit()
    elif X+x not in p:
        print(X+x)
        exit()

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

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

else:
    p = list(map(int, input().split()))
    li = [i for i in range(-101, 102) if i not in p]
    li.sort(reverse = True)

    tmp1 = float('inf')
    ans = float('inf')

    for i in li:
        if abs(i - x) <= tmp1:
            if i < ans:
                ans = i
                tmp1 = abs(i - x)

    print(ans)

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

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

    if not p == "":
        p = list(map(int, p.split()))
        p.sort()

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

    else:
        print(x)

Solution (Python):

import copy
import random
import bisect 
import fractions 
import math
import sys
import collections

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

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

X, N = LI()
p = LI()

ans = X
for i in range(2 * N):
    if X - i not in p:
        ans = X -i
        break
    if X + i not in p:
        ans = X + i
        break

print(ans)

Solution (Python):
x,n=map(int,input().split())
if n>0:
	p=list(map(int,input().split()))
	ans,cnt=0,0
	while cnt<=100:
		if x-cnt not in p:
			ans=x-cnt
			break
		if x+cnt not in p:
			ans=x+cnt
			break
		cnt+=1
	print(ans)
else:
	print(x)

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

P = sorted(P)

prev = 1000
ans = 101
for i in range(101, -1, -1):
    if i in P:
        pass
    else:
        if abs(X-i) <= prev:
            ans = min(i, ans)
            prev = abs(X-i)
print(ans)

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

for i in range(102):
    if i in p:
        pass
    else:
        if abs(X-i)<d:
            d=abs(X-i)
            ans=i
        else:
            pass


print(ans)

Solution (Python):
x,n = map(int,input().split())
p = list(map(int,input().split()))
now = 99999
ans = -200
ls = [(i+1) for i in range(-1000,1001)]
for i in range(len(p)):
    ls.remove(p[i])
k = []
for i in range(len(ls)):
    if abs(ls[i]-x) < now:
        now = abs(ls[i]-x)
        ans = ls[i]
print(ans)

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

Solution (Python):
X,N = map(int,input().split())
P = list(map(int,input().split()))
move = 0
discover = True
while discover:
    nowdis = True
    for i in range(0,N):
        if P[i] == X + move:
            nowdis = False
    if nowdis == True:
        discover = False
        print(X + move)
    if move >= 0:
        move = (-1) * move - 1
    else:
        move = (-1) * move

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

ans = 300

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

print(ans)

Solution (Python):
X, N = map(int, input().split())
p = list(map(int, input().split()))
k = 0
ans = 0
c = True

while c:
    if (X - k) not in p:
        ans = X -  k
        c = False
        break
    elif (X + k) not in p:
        ans = X + k
        c = False
        break
    else:
        k += 1
        
print(ans)

Solution (Python):
X,N = map(int,input().split())
P = list(map(int,input().split()))
if P == []:
  print(X)
  exit()
for n in range(101):
  if X - n not in P:
    ans = X - n
    break
  if X + n not in P:
    ans = X + n
    break

print(ans)

Solution (Python):

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


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

p.sort()

q=list(range(-200,200))

for i in range(len(q)):
    if q[i] in p:
        q[i]=1000

d=[]
for i in range(len(q)):
    d.append(abs(X-q[i]))

a=min(d)

if X-a in q:
    print(X-a)
else:
    print(X+a)

Solution (Python):
X, N = map(int, input().split(" "))
if N != 0:
  P = set(map(int, input().split(" ")))
  assert len(P) == N
else:
  P = set([])

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

Solution (Python):

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

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

    else:
        x1=x
        x2=x
        x1=x1-i
        x2=x2+i
        if x1 not in p:
            print(x1)
            break
        
        elif x2 not in p:
            print(x2)
            break

        else:
            continue

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

    p.sort()

    for i in range(100):
        a = X+i
        b = X-i
        if not b in p:
            print(b)
            break
        elif not a in p:
            print(a)
            break
else:
    print(X)

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

Solution (Python):


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


if N==0:
    print(X)
else:
    p_nums = list(map(int, input().split()))
    nums = [i for i in range(-1000, 1001)]
    
    for p in p_nums:
        nums.remove(p)
    point = 0
    
    kyori = float('INF')
    for n in nums:
        tmp = min(abs(X-n), abs(n-X))
        if tmp<kyori:
            point = n
            kyori = tmp

    
    print(point)

Solution (Python):

import sys


def solve(X: int, N: int, p: "List[int]"):
    p.sort()

    Q = []
    for q in range(-200, 200):
        if q not in p:
            Q.append(q)

    Q_diff = [abs(a - X) for a in Q]

    mn = min(Q_diff)

    ans_idx = Q_diff.index(mn)
    ans = Q[ans_idx]

    print(ans)
    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):
from collections import defaultdict
x, n = [int(i) for i in input().split()]
arr = [int(i) for i in input().split()]
Dict = defaultdict(int)
for i in arr:
    Dict[i] = 1
ans = int(1e9)
val = -1
for i in range(0,200):
    if Dict[i] == 0:
        diff = abs(x - i)
        if diff < ans:
            val = i
            ans = diff
print(val)

Solution (Python):
a = list(map(int, input().split()))
if a[1]!=0:
    b = list(map(int, input().split()))
    c=100
    d=0
    for i in range(201):
        if abs(a[0]-i)<c and i not in b:
            c=abs(a[0]-i)
            d=i
        if i>c+a[0]:
            break
    print(d)

else:
    print(a[0])

Solution (Python):

import sys
import bisect


input = sys.stdin.readline
def IS(cb): return cb(input().strip())
def IL(cb): return [cb(s) for s in input().strip().split()]
def IR(cb, rows): return [IS(cb) for _ in range(rows)]
def ILL(cb, rows): return [IL(cb) for _ in range(rows)]


def solve():
    X, N = IL(int)
    if N > 0:
        P = IL(int)
        A = set(range(-2, 102)) - set(P)
    else:
        A = set(range(-2, 102))

    A = list(A)
    A.sort()
    i = bisect.bisect(A, X)
    print(min(A[i - 1: i + 1], key=lambda x: abs(X - x)))


solve()

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

for i in range(101):
  minans = X - i
  maxans = X + i
  if minans not in A:
    print(minans)
    exit(0)
  elif maxans not in A:
    print(maxans)
    exit(0)

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

Solution (Python):
x,n=map(int,input().split())
if n==0:
  print(x)
else:
  lst=sorted(map(int,input().split()))
  dis=200
  ans=100
  for i in range(102):
    temp=abs(x-i)
    if temp<dis and i not in lst:
      dis=temp
      ans=i
  print(ans)

Solution (Python):


import math



from collections import deque




x,n=map(int,input().split())
if n==0:
  print(x)
  exit()
p=list(map(int,input().split()))
p=set(p)
res=[]
for i in range(x,-1,-1):
    if i not in p:
        res.append(i)
        break
for i in range(x+1,102):
    if i not in p:
        res.append(i)
if len(res)==1:
    print(res[0])
else:
    if x-res[0]>res[1]-x:
        print(res[1])
    else:
        print(res[0])

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

Solution (Python):
import numpy as np
import math
import collections
import bisect


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

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


for i in range(200):
    ans = X - i
    if(ans not in p):
        print(ans)
        break

    ans = X + i
    if(ans not in p):
        print(ans)
        break

Solution (Python):
x,n=map(int,input().split())
l=list(map(int,input().split()))
ans=1000
c=0
for i in range(-100,110):
    if i not in l:
        if(abs(i-x)<ans):
            ans=min(ans,abs((i-x)))
            c=i
print(c)

Solution (Python):
X,N = map(int,input().split())
p = list(map(int,input().split()))
p = set(p)
mini = 10**3
ans = 0
for i in range(10**3):
    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 = set(list(map(int, input().split())))
notP = set(list(range(-1, 102))) - P


min_dif = 10000
ans = 10000
for num in list(notP):
    dif = abs(x - num)
    if dif < min_dif:
        min_dif = dif
        ans = num
    elif dif == min_dif and num < ans:
        min_dif = dif
        ans = num
print(ans)

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

diff = 103
ans = X
for i in range(101):
    a = X - i
    b = X + i
    if a not in P:
        ans = a
        break
    elif b not in P:
        ans = b
        break
print(ans)

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

Solution (Python):
import sys

X, N = map(int, sys.stdin.readline().split())
P = [int(x) for x in sys.stdin.readline().split()]

Y = [x for x in range(102)]
setY = set(Y)
setP = set(P)
R = list(setY-setP)
RX = [abs(r - X) for r in R]
i = RX.index(min(RX))
print(R[i])

Solution (Python):
from collections import Counter 
from collections import defaultdict
from collections import deque
from functools import reduce
import math
import itertools
import heapq
import numpy as np
import bisect
import sys

sys.setrecursionlimit(10**6)


def bfs(s,n,node):
    
    check=[False for _ in range(n)]
    check[s]=True
    
    queue=deque([s])
    visited_num=1

    
    
    color=[-1 for _ in range(n)]
    color[s]=0
    
    while visited_num<n:
        
        if len(queue)==0:
            
            
            return color

        now_vertex=queue.popleft()
        
        for next_vertex in node[now_vertex]:


            if check[next_vertex]==True:
                continue

            queue.append(next_vertex)
            check[next_vertex]=True

            
            color[next_vertex]=color[now_vertex]+1
            visited_num+=1

    return color




ceil=lambda x,y: (x+y-1)//y
input_list = lambda : list(map(int,input().split()))




n,m=list(map(int,input().split()))
a=list(map(int,input().split()))
a=set(a)
tmp=set(i for i in range(-5,103))
cal=tmp-a
cal=list(cal)
cal.sort()
ind=bisect.bisect_left(cal,n)
ans=cal[ind]
if ans-n >= n-cal[ind-1]:
    ans=cal[ind-1]
print(ans)

Solution (Python):
import sys

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

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

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

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

Solution (Python):
import sys
x,n = map(int,input().split())
ls = list(map(int,input().split()))
p = float("inf")
s = 0
if n == 0:
    print(x)
    sys.exit()
for i in range(102):
    if i in ls:
        continue
    k = abs(x-i)
    if k < p:
        p = k
        s = i
print(s)

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

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

    p = set(map(int, input().split()))
    diff = set(range(-1, 150)) - p

    a = [(abs(x - q), q) for q in diff]
    a.sort()
    print(a[0][1])


main()

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

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

cnt = [0] * 102

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

ans = 0
sa = x
for i in range(1, 102):
    if cnt[i] == 0:
        if sa > abs(x - i):
            ans = i
            sa = abs(x - i)
print(ans)

Solution (Python):
x,n=map(int, input().split()) 
p=list(map(int,input().split()))
s=100
t=0
c=0
if p==[]:
    print(x)
    c=1
if c==0:
    for i in range(-201,201):
        if not i in p:
            if abs(x-i)<s:
                
                s = abs(x-i)
                t=i
    print(t)

Solution (Python):
import sys
import math
import itertools
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
import bisect
X,N = I()
if N == 0:
    print(X)
    exit()
p = l()
A = [i for i in range(-1,102)]
for i in range(N):
    if p[i] in A:
        A.remove(p[i])
i = bisect.bisect_left(A,X)
if abs(A[i-1]-X) > abs(A[i]-X):
    print(A[i])
else:
    print(A[i-1])

Solution (Python):
import sys, bisect, math, itertools, string, queue, copy



from collections import Counter,defaultdict,deque
from itertools import permutations, combinations, combinations_with_replacement
from heapq import heappop, heappush, heapify
from fractions import gcd

sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

def main():
    x,n = inpm()
    l = inpl()
    for i in range(200):
        if x-i not in l:
            print(x-i)
            return
        if x+i not in l:
            print(x+i)
            return
    
if __name__ == "__main__":
    main()

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

sa=1000
ans=0
for i in range(110):
    if i in P:
        continue
    else:
        if sa>abs(i-X):
            sa=abs(i-X)
            ans=i

print(ans)

Solution (Python):
x,n=map(int,input().split())
if n>0:
    p=list(map(int,input().split()))
    p=set(p)
    mini=10**10
    ans=0
    for i in range(102):
        if i not in p:
            if abs(i-x)<mini:
                mini=abs(i-x)
                ans=i
    print(ans)
else:
    print(x)

Solution (Python):
def main():
    X,N  = map(int, input().split()) 
    c=list(map(int, input().split()))
    XY = [True]*(104)

    for i in range(len(c)):
        XY[c[i]]=False

    ans = 0
    sa = 10000

    for i in range(-1,104):
        if i==-1 or XY[i]:
            if sa > abs(X-i) :
                ans = i
                sa = abs(X-i)
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
x,y=map(int,input().split())
if y==0:print(x);exit()
l=list(map(int,input().split()))
work=x
if not work in l:
    print(work)
    exit()
i=1
while 1:
    if not work-i in l:
        print(work-i)
        exit()
    if not work+i in l:
        print(work+i)
        exit()
    i+=1

Solution (Python):
x, n = map(int, input().split())
if n == 0:
    print(x)
    exit()
p = sorted([-999] + list(map(int, input().split())) + [999])

from bisect import bisect_left, bisect_right

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


m = p.index(x) - 1
target_L = x - 1
while True:
    if target_L not in p:
        break
    target_L -= 1

target_R = x + 1
while True:
    if target_R not in p:
        break
    target_R += 1

if abs(target_L - x) <= abs(target_R - x):
    print(target_L)
else:
    print(target_R)

Solution (Python):
X,N = map(int,input().split())
if N>0:
    p = list(map(int,input().split()))
else:
    p = []
ans = []
for i in range(100):
    ans.append(X-i)
    ans.append(X+i)
import sys
for j in ans:
    if j not in p:
        print(j)
        sys.exit()

Solution (Python):
x, n = map(int, input().split())
p = list(map(int, input().split()))
for i in range(n+1):
    c = 10**5
    t = 10**5
    y = 0
    if x + i not in p:
        c = x+i
        y += 1
    if x - i not in p:
        t = x-i
        y += 1
    if y:
        print(min(t,c))
        exit()

Solution (Python):
x,n=map(int,input().split())
p=list(map(int,input().split()))
p=sorted(p)
c=0
z=0
a=[]
for i in range(n):
    a.append(p[i]-x)
for i in range(100):
    if a.count(-i)==0:
        z=-c
        break
    elif a.count(i)==0:
        z=c
        break
    else:
        c+=1
print(x+z)

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


def read():
    X, N = map(int, input().strip().split())
    P = list(map(int, input().strip().split()))
    return X, N, P


def solve(X, N, P):
    if N == 0:
        return X
    k = 0
    v = 10**5
    for i in range(102, -102, -1):
        if i in P:
            continue
        if v >= abs(X - i):
            v = abs(X - i)
            k = i
    return k


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))

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

i=0

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

Solution (Python):
X,N=list(map(int,input().split()))
p=list(map(int,input().split()))
dist=1000
ans=1000
for i in range(0,150):
    low=X-i
    high=X+i
    if p.count(low)==0:
        print(low)
        exit()
    elif p.count(high)==0:
        print(high)
        exit()

Solution (Python):
x,n = map(int,input().split())
a = list(map(int,input().split()))
if n == 0:
    print(x)
    exit()
ans = min(a)-1
for i in range(1,102):
    if i in a:
        continue
    if abs(x-i) < abs(x-ans):
        ans = i
print(ans)

Solution (Python):
import sys
X, N = map(int, input().split())
if N != 0:
    P = list(map(int, input().split()))
else:
    print(X)
    sys.exit(0)
l = []
for i in range(102):
    if i not in P:
        l.append(i)
tmp = 1000
ans = 0
for i in range(len(l)):
    if tmp > abs(X-l[i]):
        tmp = abs(X-l[i])
        ans = l[i]

print(ans)

Solution (Python):



from math import *
from copy import *					
from heapq import *					
from string import *				
from random import *				
from bisect import *				
from sys import stdin				
from sys import maxsize				
from operator import *				
from itertools import *				
from decimal import Decimal 		
from collections import Counter		
from collections import defaultdict 

'''
6 5
4 7 10 6 5
'''

def solve(l,x,n):
	n = len(l)
	diff,ans = maxsize,0
	for i in range(102):
		if(i not in l and abs(i-x) < diff):
			diff = abs(i-x)
			ans = i
	return ans
	

X,N = map(int, input().split())
l = list(map(int, stdin.readline().rstrip().split()))
ans = solve(l,X,N)
print(ans)

Solution (Python):
def main():
    X, N = [int(s) for s in input().strip().split()]

    if N == 0:
        print(X)
        return
    
    ps = [int(s) for s in input().strip().split()]

    p_max = max(ps)
    p_min = min(ps)

    for d in range(100):
        cand = X - d

        if cand < p_min:
            print(cand)
            return
        
        if cand not in ps:
            print(cand)
            return

        cand = X + d

        if cand > p_max:
            print(cand)
            return

        if cand not in ps:
            print(cand)
            return

main()

Solution (Python):


import sys
input=sys.stdin.readline

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

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

minX = X
maxX = X
for i in range(100):
    if cnt[minX] == 0:
        print(minX)
        exit()
    elif cnt[maxX] == 0:
        print(maxX)
        exit()
    else:
        minX -= 1
        maxX += 1

Solution (Python):
X, N = [int(_c) for _c in input().split(" ")]

p_list_raw = input()
if p_list_raw == "":
    print(X)
else:
    p_list = [int(_c) for _c in p_list_raw.split(" ")]

    ans = -1
    for i in range(101):
        target = X - i
        if target not in p_list:
            ans = target
            break
        target = X + i
        if target not in p_list:
            ans = target
            break

    print(ans)

Solution (Python):
X,N=map(int,input().split())
P=list(map(int,input().split()))
setP=set(P)
ANS=[]
for i in range(102):
  if i not in setP:
    ANS+=[i]
d=100
for i in ANS:
  if abs(X-i)<d:
    ans=i
    d=abs(X-i)
print(ans)

Solution (Python):
li = input().split()
x = int(li[0])
n = int(li[1])
if n == 0:
    print(x)
else:
    li = list(map(int,input().split()))
    count = 0
    while True:
        if  x - count not in li:
            print(x-count)
            break
        elif x+count not in li:
            print(x+count)
            break 

        count+= 1

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

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

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

if not x in plist:
    print(x)
    sys.exit()

for i in range(1,102):
    if not x-i in plist:
        print(x-i)
        sys.exit()
    elif not x+i in plist:
        print(x+i)
        sys.exit()

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



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

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

ans = -1
for k in range(X, -1, -1):
    if not k in P:
        ans = k
        break
for k in range(X, 102):
    if not k in P:
        if X-ans <= k-X:
            break
        else:
            ans = k
            break
print(ans)

Solution (Python):
x,n,*l = map(int,open(0).read().split())

import sys
if not x in l:
    print(x)
    sys.exit()
for i in range(1, 100):
    if  not x -i in l:
        print(x -i)
        sys.exit()
    if  not x +i in l:
        print(x +i)
        sys.exit()

Solution (Python):
X, N = map(int, input().split())
P = sorted(list(map(int, input().split())))
ans = -1
diff = 100000
for i in range(-10,110):
    if i in P: continue
    if diff > abs(i-X):
        diff = abs(i-X)
        ans = i
print(ans)

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

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

Solution (Python):
def LI():
    return list(map(int, input().split()))

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

d = dict()
for i in range(n):
    d[p[i]] = 1

i = 0
while True:
    if d.get(x-i, 0) == 0:
        print(x-i)
        break
    elif d.get(x+i, 0) == 0:
        print(x+i)
        break
    i += 1

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

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

for s in range(-101, 110):
    if s not in P:
        ans = s
        break

for s in range(-101, 110):
    if s not in P:
        if abs(ans-x) > abs(s-x):
            ans = s
        elif abs(ans-x) == abs(s-x):
            ans = min(ans, s)

print(ans)

Solution (Python):
l = list (map (int, input().strip().split()))
x = l[0]
n = l[1]
if (n==0):
    print(x)
else:
    l2 = list (map (int, input().strip().split()))
    d = 0
    while True:
        if (x-d) not in l2:
            print(x-d)
            break 
        elif (x+d) not in l2:
            print(x+d)
            break
        d+=1

Solution (Python):

def nearest(x, arr):
    if x not in arr:
        return x
    lower = x - 1
    higher = x + 1
    while True:
        if lower not in arr:
            return lower
        if higher not in arr:
            return higher
        lower -= 1
        higher += 1

        


x = list(map(int, input().rstrip().split()))
a = list(map(int, input().rstrip().split()))
print(nearest(x[0], a))

Solution (Python):
[X,N] = [int(s) for s in input().rstrip().split(' ')]
if N == 0:
    print(X)
else:
    L = [int(s) for s in input().rstrip().split(' ')]
    k = 0
    a = 0
    while a == 0:
        if X - k not in L:
            print(X-k)
            a = 1
            continue
        elif X + k not in L:
            print(X+k)
            a = 1
            continue
        k += 1

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

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

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

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

diff = 10**10
ans = -1
for p in range(102):
    
    if p in P:
        continue
    if abs(X-p) < diff:
        diff = abs(X-p)
        ans = p
print (ans)

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

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

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

cnt = 0
while True:
    if X - cnt not in P:
        print(X - cnt)
        exit()
    if X + cnt not in P:
        print(X + cnt)
        exit()
    cnt += 1