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

p.sort()
if X not in p or p == []:
    print(X)
else:
    idx = p.index(X)
    for i in range(1,idx+2):
        if i == idx+1:
            before = p[0] - 1
            break
        if p[idx - i +1] - p[idx - i] == 1:
            continue
        else:
            before = p[idx-i+1] -1
            break
    for i in range(1,N-idx+1):
        if i == N-idx:
            after = p[-1] + 1
            break
        if p[idx + i] - p[idx + i -1] == 1:
            continue
        else:
            after = p[idx + i - 1] +1
            break
    if X-before > after-X:
        print(after)
    else:
        print(before)

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

if n == 0:
  print(x)
  exit(0)
  
p = [int(x) for x in input().split()]

a = x
b = x

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

for i in range(1,101):
  a = a + 1
  b = b - 1
  if b not in p:
    print(b)
    exit(0)
  elif a not in p:
    print(a)
    exit(0)

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

    if n > 0:
        p = list(map(int, input().split()))
        q = [i for i in range(min(p)-1, max(p)+2)]
        for item in p:
            if item in q:
                q.remove(item)

        ans = []
        current_min = float('inf')
        for item in q:
            diff = abs(x-item)
            if diff < current_min:
                current_min = diff
                ans.clear()
                ans.append(item)
            elif diff == current_min:
                ans.append(item)

        print(min(ans))
    else:
        print(x)


if 'unittest' not in globals():
    resolve()

Solution (Python):
[x,n] = list(map(int, input().split()))
pList = list(map(int, input().split()))
pSet = set(pList)
step = 0
small = False
big = False
while True:
    if x - step not in pSet:
        small = True
        break
    if x + step not in pSet:
        big = True
        break
    step += 1
if small:
    print(x-step)
else:
    print(x+step)

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

if N == 0:
    print(X)
    exit()
if X not in pp:
    print(X)
    exit()

ans = X
diff = 0
while True:
    diff += 1
    ans = X - diff
    if ans not in pp:
        print(ans)
        break
    ans = X + diff
    if ans not in pp:
        print(ans)
        break

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

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

cnt = [0] *10001
ans1 = 0
ans2 = 0

for _p in p:
    cnt[_p] += 1

for i in range(x, 1000):
    if not i in p:
        ans1 = i
        break

for i in range(x-1, -1000, -1):
    if not i in p:
        ans2 = i
        break

if abs(ans1 - x) < abs(ans2 - x):
    print(ans1)
elif abs(ans1 - x) >= abs(ans2 - x):
    print(ans2)

Solution (Python):
import sys


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

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

    for i in range(101):
        x1 = max(0, x - (i + 1))
        x2 = min(101, x + (i + 1))

        if x1 == 0:
            print(0)
            sys.exit()
            
        if not (x1 in P):
            print(x1)
            sys.exit()

        if x2 == 101:
            print(101)
            sys.exit()
            
        if not (x2 in P):
            print(x2)
            sys.exit()


if __name__ == '__main__':
    main()

Solution (Python):
X, N = map(int,input().split())
p = list(map(int,input().split()))
kazu = [i for i in range(-100,201)]
sa = [0]*301
for i in range(301):
    if kazu[i] in p:
        kazu[i] = 10000
for i in range(301):
    sa[i] = abs(X-kazu[i])
print(kazu[sa.index(min(sa))])

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

nota = list()

for i in range(-1000, 1001):
    if i in a:
        continue
    nota.append(i)

nota.sort()
ans = 1000
minabs = 1000
for i in nota:
    if minabs > abs(i-x):
        minabs = abs(i-x)
        ans = i

print(ans)

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

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

min_diff_val = X + 100
min_val = -100
for y in range(-100, 200):
    if not (y in p):
        if min_diff_val > abs(y - X):
            min_val = y
            min_diff_val = abs(y - X)
print(min_val)

Solution (Python):
R = lambda: map(int, input().split())
x, n = R()
print(min((abs(x - y), y) for y in set(range(102)) - set(R()))[1])

Solution (Python):
import sys

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

if n == 0:
    print(x)
    sys.exit()
elif not(x in p_list):
    print(x)
    sys.exit()
elif len(p_list) == 100 and x <= 50:
    print(0)
    sys.exit()
elif len(p_list) == 100 and x > 50:
    print(101)
    sys.exit()

list.sort(p_list, reverse=True)
dis_list = list(range(102))
for p in p_list:
    dis_list.pop(p)

min_dis = 102
ans = 0
for index in dis_list:
    dis = abs(index - x)
    if dis < min_dis:
        min_dis = dis
        ans = index
print(ans)

Solution (Python):
a = list(map(int,input().split()))
if a[1] == 0:
    print(a[0])
else:
    l = list(map(int, input().split()))

    for i in range(100):
        if a[0]-i not in l:
            print(a[0]-i)
            break
        elif a[0]+i not in l:
            print(a[0]+i)
            break

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

ans1, ans2 = 999, 999
for i in range(x, x + 200, 1):
  if not i in p_list:
    ans1 = i
    delta1 = abs(i - x)
    break
  
for j in range(x, x - 200, -1):
  if not j in p_list:
    ans2 = j
    delta2 = abs(j - x)
    break 

if delta1 > delta2:
  print(ans2)
elif delta1 < delta2:
  print(ans1)
else:
  print(min(ans1, ans2))

Solution (Python):
def main():
    x,n = map(int,input().split())
    if n>0:
        p = list(map(int,input().split()))
    else:
        p = []
    d = [i for i in range(0,102)]
    for i in range(len(d)):
        if d[i] in p:
            d[i] = -1
    d = sorted(d)
    m = 10000
    ans = 0
    for i in range(len(d)):
        if d[i]==-1:
            continue
        if m>abs(d[i]-x):
            m = abs(d[i]-x)
            ans = d[i]
    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
def iput(): return int(input())
def mput(): return map(int, input().split())
def lput(): return list(map(int, input().split()))

def solve():
    x, n = mput()
    p = lput()
    ans = []
    for i in range(x, x-n-1, -1):
        boo = i in p
        if boo != True:
            ans.append(i)
            break
    for i in range(x, x+n+1):
        boo = i in p
        if boo != True:
            ans.append(i)
            break
    if abs(x-ans[0]) <= abs(x-ans[1]):
        print(ans[0])
    else:
        print(ans[1])
    return 0

if __name__ == "__main__":
    solve()

Solution (Python):
import sys
input = sys.stdin.readline
def main():
    X, N = map(int, input().split())
    p = set(list(map(int, input().split())))
    table = set()
    for i in range(1, 101):
        table.add(i)
    table = table - p
    lis = list(table)
    ans = -1
    diff = 10 ** 9
    for i, a in enumerate(lis):
        if abs(a-X) < diff:
            diff = abs(a-X)
            ans = a
        elif abs(a-X) == diff:
            ans = min(ans, a)
    if abs(X-ans) > abs(X-101):
        ans = 101
    if abs(X-ans) >= abs(X):
        ans = 0
    print(ans)
if __name__ == "__main__":
    main()

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

ans = X+10
tmp = []
P2 = [int(i) for i in range(-200,200)]
P3 = list(set(P2)-set(P))
P3.sort()
P3[::-1]
for i in P3:
    if ans > abs(X-i):
        ans = abs(X-i)
        tmp.append(i)
print(max(tmp))

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

i = 0

while X+i<=101 or X-i>=0:
    pflag = X+i in p
    mflag = X-i in p
    if pflag and mflag:
        i+=1
    else:
        if not mflag:
            print(X-i)
            exit()
        else:
            print(X+i)
            exit()

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

Solution (Python):
import os

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

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

mini = 0
min = 1000
for b in range(-200,200):
    if min>abs(x-b):
        if b not in p:
            min = abs(x-b)
            mini = b

print(mini)

Solution (Python):
x, n = map(int, input().split())
if n > 0:
    p = list(map(int, input().split()))
a = [True for i in range(102)]
for i in range(n):
    a[p[i]] = False
i = 0
while True:
    if a[x-i]:
        print(x-i)
        break
    if a[x+i]:
        print(x+i)
        break
    i += 1

Solution (Python):
x, n = map(int, input().split())
try:
  p = list(map(int, input().split()))
except EOFError:
  print(100)
  exit()
old_diff = 10000
for i in range(-110, 110):
  if i in p:
    continue
  else:
    diff = abs(x-i)
    if diff < old_diff:
      ans = i
      old_diff = abs(x-i)

try:
  print(ans)
except:
  print()

Solution (Python):
X, N = map(int, input().split())
if N==0: print(X)
else:
    p = list(map(int, input().split()))
    pd = [[] for _ in range(100)]

    for i in range(N):
        pd[abs(p[i]-X)].append(X - p[i])

    for i in range(1,100):
        if len(pd[i])==0:
            ans = X - i
            break
        elif len(pd[i])==1:
            ans = X + pd[i][0]
            break
    print(ans if pd[0]==[0] else X)

Solution (Python):
import sys
import math

x,n=list(map(int,input().split()))
l=list(map(int,input().split()))
dic={}
if n==0:
    print(x)
else:
    for i in l:
        dic[i]=0
    k=0
    while True:
        if not x-k in dic:  
            print(x-k)
            break
        if not x+k in dic:  
            print(x+k)
            break
        k+=1

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

for i in range(0,102):
    if i in p:
        continue
    if temp <= min(abs(i - x),temp):
        break
    temp = min(abs(i - x),temp)
    ans = i

print(ans)

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

check = x
tansaku = 1
count = 0
while True:
    count += 1
    if not(check in p_list):
        print(check)
        exit()
    
    check -= tansaku
    tansaku = -tansaku
    if tansaku <0:
        tansaku -= 1
    else:
        tansaku += 1
    if count >= 500:
        exit()

Solution (Python):
X,N=list(map(int,input().split()))
if N==0:
  print(X)
else:
  p_list=list(map(int,input().split()))
  not_p_list=[]
  for i in range(-105,105):
    if i not in p_list:
      not_p_list.append(i)

  nN=len(not_p_list)
  abs_list=[]
  for i in range(nN):
    temp=not_p_list[i]-X
    abs_list.append(abs(temp))

  abs_list.sort()    
  if abs_list[0]==0:
    print(X)
  else:
    ans=abs_list[0]
    for i in range(nN):
      if not_p_list[i]==X-ans:
        print(X-ans)
        break
      elif not_p_list[i]==X+ans:
        print(X+ans)
        break

Solution (Python):
in_1 = [int(x) for x in input().split(' ')]
x = in_1[0]
n = in_1[1]
result = 0


if n == 0:
  result = x

else:
  in_data = [int(x) for x in input().split(' ')]
  for i in range(100):
    tmp_m = x-i
    tmp_p = x+i


    if tmp_m not in in_data:
      result = tmp_m
      break
    if tmp_p not in in_data:
      result = tmp_p
      break

print(result)

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

if x not in p:
    print(x)
else:
    for i in range(1, n + 1):
        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(" "))
if n==0:
  print(x)
  exit()

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

s=0
t=0
u=0
w=0
ans=0
flgs=0
flgt=0


for i in range(100):
  s = x + i
  t = x - i
  for j in range(n):
    if s==p[j]:
      flgs=1
  for k in range(n):
    if t==p[k]:
      flgt=1
  if flgs==1 and flgt==1:
    flgs=0
    flgt=0
  else:
    a = i
    break

if flgt == 0:
  ans = x - a
else:
  ans = x + a
  
print(ans)

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

    for d in range(101):
        if X-d not in P:
            print(X-d)
            return
        elif X+d not in P:
            print(X+d)
            return



if __name__ == "__main__":
    c()

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

if N == 0:
    print(X)

else:
    p = list(map(int, input().split()))
    q = [i for i in range(-1, 102)]

    for r in p:
        idx = q.index(r)
        del q[idx]

    if X in q:
        print(X)

    else:
        q.sort()
        mindif = 1000

        for num in q:
            dif = abs(X - num)
            if mindif <= dif:
                break
            else:
                mindif = dif
                ans = num
        print(ans)

Solution (Python):
x, n = list(map(int, input().split()))
if n == 0:
  print(x)
  exit()
p = list(map(int, input().split()))
d = 1e9
ans = 0
for e in range(200, -1, -1):
  dd = abs(e - x)
  if e not in p and dd <= d:
    d = dd
    ans = e
print(ans)

Solution (Python):
X, N = map(lambda x: int(x), input().split(" "))
if N != 0:
    Ps = set(map(lambda x: int(x), input().split(" ")))
    result = 0
    for i in range(1, 102):
        if i in Ps:
            continue
        if abs(X-result) > abs(X-i):
            result = i
else:
    input()
    result = X

print(result)

Solution (Python):
x, n = map(int, input().split())
p = list(map(int, input().split()))
d = [0]*102
for i in p: d[i] = 1
if d[x] == 0:
    print(x)
else:
    i = 1
    while True:
        if x-i>=0:
            if d[x-i] == 0:
                print(x-i)
                break
        if x+i<=101:
            if d[x+i] == 0:
                print(x+i)
                break
        i += 1

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

Solution (Python):

def iput(): return int(input())
def mput(): return map(int, input().split())
def lput(): return list(map(int, input().split()))

def solve():
    x, n = mput()
    p = lput()
    ans = []
    for i in range(x, x-n-1, -1):
        boo = i in p
        if boo != True:
            ans.append(i)
            break
    for i in range(x, x+n+1):
        boo = i in p
        if boo != True:
            ans.append(i)
            break
    if abs(x-ans[0]) <= abs(x-ans[1]):
        print(ans[0])
    else:
        print(ans[1])
    return 0

if __name__ == "__main__":
    solve()

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














ans = None
for n in range(100):
    plus = X +n
    if plus not in P:
        ans = plus
    minus = X -n
    if minus not in P:
        ans = minus
    if ans is not None:
        print(ans)
        exit()

Solution (Python):


import sys
import math
from decimal import Decimal, ROUND_DOWN


debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        
        
        lines.append(input())
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]

    (x, n) = [int(e) for e in lines[0].split(' ')]
    if n >= 1:
        p = [int(e) for e in lines[1].split(' ')]
    else:
        p = []

    return (x, n, p)


def solve(x, n, p):
    
    pp = set(p)
    result = None
    for i in range(0, 99):
        xa = x - i
        xb = x + i

        if xa in pp:
            pass
        else:
            result = xa
            break

        if xb in pp:
            pass
        else:
            result = xb
            break


    return result
    


def main():
    
    result = solve(*parse_input())
    if isinstance(result, list):
        for r in result:
            print("%s" % r, sep='')
    else:
        print("%s" % result, sep='')

if __name__ == '__main__':

    main()

Solution (Python):
X,N = map(int,input().split())
try:
    li = list(map(int,input().split()))
except:
    li = []
flg=0
d=1
if X not in li:
    print(X)
    flg=1
while flg==0:
    if X+d in li and X-d in li:
        d+=1
    elif X+d not in li and X-d not in li:
        print(X-d)
        flg=1
    elif X+d not in li:
        print(X+d)
        flg=1
    else:
        print(X-d)
        flg=1

Solution (Python):
import sys

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

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

    if not x in ps:
        print(x)
        return

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

        if not x+i in ps:
            print(x+i)
            return

main()

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

else :
    for i in range(0,200):
        s=x+i
        if s in p:
            pass
        else:
            ans = s
            break

    for n in range(0,200):
        m =x-n
        if m in p:
            pass
        else:
            anss = m
            ansss = x + n
            break
    if ansss <= ans:
        print(anss)
    else :
        print(ans)

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

for i in range(200):
    Y = X - i
    Z = X + i
    if Y not in p:
        print(Y)
        break
    elif Z not in p:
        print(Z)
        break

Solution (Python):
[X, N] = list(map(int, input().split()))
P = list(map(int, input().split()))
answer = 0
c = 0
N_min = X
N_max = X
while c == 0:
    if N_min not in P:
        answer = N_min
        c += 1
    elif N_max not in P:
        answer = N_max
        c += 1
    N_min = N_min - 1
    N_max = N_max + 1
print(answer)

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

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

  for i in range(N+100):
    if (X-i) not in set_p:
      print(X-i)
      return True

    if (X+i) not in set_p:
      print(X+i)
      return True

if __name__ == "__main__":
  resolve()

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

Solution (Python):
import collections
import sys

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

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

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

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

queue = collections.deque([X-1, X+1])

while True:
  cur = queue.popleft()
  if cur in p:
    if cur < X:
    	queue.append(cur-1)
    else:
    	queue.append(cur+1)
  else:
  	print(cur)
  	break

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

Solution (Python):
x,n = map(int,input().split())
p = list(map(int,input().split()))
ans = 1000000
a = 0
if x not in p:
    a = 1
else:
    for i in range(n):
        ch = abs(x-p[i])
        ans = min(ans,ch)
count = x-ans-1
if a == 1:
    print(x)
elif count not in p:
    print(count)
else:
    for j in range(ans,10000,1):
        if (x-j>=0) and x-j not in p:
            print(x-j)
            break
        elif x+j not in p:
            print(x+j)
            break

Solution (Python):
import sys
x, n = (int(i) for i in input().split())
try:
    ps = [int(i) for i in input().split()]
    ps.sort()
    
    
    result = 0
    d = 0
    while x-d > 0:
        if x-d not in ps:
            print(x-d)
            sys.exit()
        elif x+d not in ps:
            print(x+d)
            sys.exit()
        d += 1
    print(0)
except EOFError:
    print(x)

Solution (Python):
import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
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())
x, n = M()
if n == 0:
    print(x)
else:
    n_l = LI()
    suchi_list = [i for i in range(-300, 300)] 
    ans = -1
    for i in n_l:
        suchi_list.remove(i)
    if x in suchi_list:
        ans = x
    else:
        for j in range(1, 101):
            if x-j in suchi_list:
                ans = x-j
            elif x+j in suchi_list:
                ans = x+j
            if ans != -1:
                break
    print(ans)

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

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

okList = [-1]*(300)
for i in range(len(okList)):
  okList[i] = i-150
for i in range(len(p)):
  okList[p[i]+150] = -1000

ans = 0
ans2 = 10000
for i in range(len(okList)):
  if okList[i] != -1000:
    if ans2 > abs(okList[i]-x):
      ans2 = abs(okList[i]-x)
      ans = okList[i]
print(ans)

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

        maxP = max(P)

        numList = [0 for i in range(maxP+2)]

        for num in P:
            numList[num] += 1
        
        maxRes = 101
        maxCount = 0
        minRes = 101
        minCount = 0

        for i in range(x, maxP+2):
            maxCount += 1
            if numList[i] == 0:
                maxRes = i
                break
        
        for i in range(x, -1, -1):
            minCount += 1
            if numList[i] == 0:
                minRes = i
                break

        if maxCount < minCount:
            print(maxRes)
        else:
            print(minRes)

    else:
        print(x)

    

if __name__ == '__main__':
    main()

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

if n == 0:
  print(x)
  exit(0)
  
p = [int(x) for x in input().split()]

a = x
b = x

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

for i in range(1,101):
  a = a + 1
  b = b - 1
  if b not in p:
    print(b)
    exit(0)
  elif a not in p:
    print(a)
    exit(0)

Solution (Python):
X,N=map(int,input().split())
p=list(map(int,input().split()))
p_bar=[]
for i in range(0,102):
  if i not in p:
    p_bar.append(i)

d_min=1000
i_min = 0
for i in p_bar:
  d = abs(X-i)
  if d < d_min:
    d_min = d
    i_min = i
print(i_min)

Solution (Python):
import sys
x,n=map(int,input().split())
if n==0:
    print(x)
    sys.exit()
else:
    p=list(map(int,input().split()))
    res=1000
    ans=0
    for i in range(101,-101,-1):
        p.append(i)
        if len(p)==len(set(p)):
            if res>=abs(x-i):
                res=abs(x-i)
                ans=i
        del p[-1]
    print(ans)

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

ntmp = X-1
ptmp = X+1
while 0 <= ntmp or ptmp <= 100:
  if not ntmp in nList:
    print(ntmp)
    exit()
  if not ptmp in nList:
    print(ptmp)
    exit()
  ntmp -= 1
  ptmp += 1

Solution (Python):
import numpy as np
x,n = map(int,input().split())
if n!=0:
    p = list(map(int,input().split()))
    q = [i for i in range(-101,201)]
    r = set(q)-set(p)

    a = np.array(list(r))
    f = [x]*(len(list(r)))
    b = np.array(f)

    c = a-b
    d  = np.abs(c)
    e = np.argmin(d)

    print(int(c[int(e)])+x)
else:
    print(x)

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

pidx = 0
ansabs = 1000
for i in range(102):
    if pidx < n and i == p[pidx]:
        pidx += 1
        continue
    if ansabs > abs(i - x):
        ansabs = abs(i - x)
        ans = i

print(ans)

Solution (Python):
import sys

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

X,N = LI()
P_jyogai = LI()

P = list(range(-10000,10000))

P_difference = set(P)-set(P_jyogai)
P_difference = list(P_difference)
P_difference.sort()

sabun = 100000000
ans = 0
for p_diff in P_difference:
    temp = abs(X-p_diff)
    if sabun > temp:
        sabun = temp
        ans = p_diff
print(ans)

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

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

P_L = []
P_R = []







A = True
i = 0

while A:
    if x - i not in P:
        print(x - i)
        A = False
    elif x + i not in P:
        print(x + i)
        A = False
    else:
        i += 1

Solution (Python):
x,n = map(int,input().split())
if n!=0:
    p = list(map(int,input().split()))
    li = set([i for i in range(102)])
    li = li-set(p)
    k=10**9
    m=0
    li=sorted(list(li))
    for i in li:
        if k>abs(x-i):
            k=abs(x-i)
            m=i
    print(m)
else:
    print(x)

Solution (Python):
X, N = map(int, input().split())
p = list(map(int, input().split()))
tip = 0
for i in range(3 * N):
    s = X - i
    t = X + i
    s_a = s not in p
    t_a = t not in p
    if tip == 0:
        if s_a:
            ans = s
            tip = 1
        elif t_a:
            ans = t
            tip = 1
if tip == 0:
    ans = X
print(ans)

Solution (Python):
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from math import factorial, sqrt, ceil, gcd, cos, radians, floor
from functools import lru_cache, reduce
from decimal import Decimal
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def dijkstra_heap(s, edge, n):
    
    d = [10**20] * n
    used = [True] * n 
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr


def lcm(x, y):
    return (x * y) // gcd(x, y)


def lcm_list(numbers):
    return reduce(lcm, numbers, 1)


def gcd_list(numbers):
    return reduce(gcd, numbers)


def is_prime(n):
    if n <= 1:
        return False
    p = 2
    while True:
        if p ** 2 > n:
            break
        if n % p == 0:
            return False
        p += 1
    return True



def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P


def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret



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

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









    
        
    
    
    
        


ans = -1
gap = INF
for i in range(102):
    if i in p:
        continue
    if abs(x - i) < gap:
        gap = abs(x - i)
        ans = i
print(ans)

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

ans = 10000000
for i in ans_can:
    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()))

c = 0
while True:
    if X - c not in p:
        print(X - c)
        break
    elif X + c not in p:
        print(X + c)
        break
    c += 1