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):
from math import *
from bisect import bisect_left

def cin(): 
    return map(int,input().split())

def cins(): 
    return input.split()

def cino(test=False): 
    if not test:
        return int(input())
    else: 
        return input()

def cina(): 
  return list(map(int,input().split()))

def ssplit(): 
    return list(input().split())

def printlist(l): 
    for i in l:
        print(i,end=" ")

def bs(arr, l, r, x): 
    while l <= r: 
        mid = l + (r - l) // 2; 
        if arr[mid] == x: 
            return mid 
        elif arr[mid] < x: 
            l = mid + 1
        else: 
            r = mid - 1
    return -1


def main():
    a,b = cin()
    if b==0:
        c = cino(True)
        print(a)
    else:
        arr = cina()
        arr.sort()
        init = 1
        if bs(arr,0,b-1,a)==-1:
            print(a)
        else:
            o,t = bs(arr,0,b-1,a-init),bs(arr,0,b-1,a+init)
            while o>=0 and t>=0:
                init+=1
                o,t = bs(arr,0,b-1,a-init),bs(arr,0,b-1,a+init)
            if o==-1:
                print(a-init)
            else:
                print(a+init)




if __name__ == '__main__':
    main()

Solution (Python):
import sys
x,n=map(int,input().split())
q=list(map(int,input().split()))
q=q+[100000000]
p=list(map(lambda i:abs(x-i),q))

p.sort()
if n==0:
  print(x)
  sys.exit()
for i in range(len(p)):
  if p[i]!=(i+1)//2:
    if i==0:
      print(x)
      sys.exit()
    elif i==1:
      print(x-1)
      sys.exit()
    elif p[i-1]==p[i-2]:
      print(x-p[i-1]-1)
      sys.exit()
    else:
      if x-p[i-1] in q:
        print(x+p[i-1])
      else:
        print(x-p[i-1])
      sys.exit()

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

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

P.sort()
for i in range(N):
	if P[i] > X:
		print(X)
		break
	elif P[i] == X:
		
		under = X
		underflag = False
		upper = X
		upperflag = False
		for j in range(i):
			if P[i - j - 1] != X - j - 1:
				under = X - j - 1
				underflag = True
				break
		if underflag == False:
			under = P[0] - 1

		for j in range(N - i - 1):
			if P[i + j + 1] != X + j + 1:
				upper = X + j + 1
				upperflag = True
				break
		if upperflag == False:
			upper = P[N - 1] + 1
		print(under if abs(X - under) <= abs(X - upper) else upper)
		break

Solution (Python):
x,n=map(int,input().split())
if n==0:
  print(x)
else:
  p=list(map(int,input().split()))
  dic={}
  for i in p:
    d=abs(i-x)
    if d in dic:
      dic[d].append(i)
    else:
      dic[d]=[i]
  sortdic = sorted(dic.items(), key=lambda x:x[0])
  chk=0
  ans=-1
  for k,v in sortdic:
    if chk==k:
      if chk!=0 and len(v)!=2:
        if v[0]>x:
          ans=x-k
        else:
          ans=x+k
        break
    else:
      ans=x-chk
      break
    chk+=1
  if ans==-1:
    ans=x-chk
  print(ans)

Solution (Python):
X,N= map(int, input().split())
if N==0 :
    print(X)
else:
    
    p=list(map(int,input().split()))
    mylist = list(range(0,10000))


    for i in range(N):
        if (p[i] in mylist)==True:
            mylist.remove(p[i])

    mylist2 = list(map(lambda a: abs(a - X), mylist))

    
    p=mylist2.index(min(mylist2))

    print(mylist[p])

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

num_list = list(range(-200,201))
y = (num_list + p)

counter = Counter(y)
result =  [elem for elem in y if counter[elem] < 2]


ans = 10 *100000000000

for i in result:
    temp = abs(i - x)
    if ans > temp:
        ans = temp
        res = i
print(res)

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

Solution (Python):
x, n = [int(i)  for i in input().split()]
if n == 0:
  print(x)
  exit()
p = list(input().split())
p = [int(i) for i in p]

  
s1=1000
s2=1000
i=0

for ii in range(n+1):
  
  if (x+i) not in p:
    s1 = (x+i)
  if (x-i) not in p:
    s2= (x-i)
  i+=1
  
  if s1 != 1000 or s2 != 1000:
    break

if s1 > s2:
  if s2 != 1000:
    print(s2)
  else:
    print(s1)
else:
  if s1 != 1000:
    print(s1)
  else:
    print(s2)

Solution (Python):
x,n = map(int, input().split())
if n ==0:
  num =[0]
else:
  num = input().split()
num = [int(x) for x in num]
min_num = min(num)
max_num = max(num)
num_list = list(range(min_num-1, max_num+2))
for de in range (len(num)):
  num_list.remove(num[de])
num_list.append(x)
num_list.sort()
tar = num_list.index(x)
if tar == 0:
  li = x
else:
  li = num_list[tar-1]
if tar == (len(num_list)-1):
  bi = x
else:
  bi = num_list[tar+1]
if x-li ==  bi - x:
  print(li)
elif x-li > bi-x:
  print(bi)
else:
  print(li)

Solution (Python):
from bisect import bisect_left,bisect

x,N,*p = map(int,open(0).read().split())
dif = 300
near = 300
all_ = set(range(0,102))

for i in p:
    d = abs(i - x)
    if dif > d:
        dif = d
        near = i
left = list(all_ - set(p))        

dif2 = 300
near = 300
for i in left:
    d = abs(x-i)
    if d < near:
        near = d
        dif2 = i
print(dif2)

Solution (Python):


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

    if N == 0:
        print(X)
        return

    setP = set(Ps)

    ans = float("inf")
    for x in range(0, 102):
        if not x in setP:
            if abs(X-ans) > abs(X-x):
                ans = x

    print(ans)


if __name__ == "__main__":
    solve()

Solution (Python):
x, n = map(int,input().split())
lis = list(map(int,input().split()))
lis.sort()
if n == 0:
    print(x)
else:
    for i in range(lis[n-1]+2):
        
        if i < x and i not in lis:
            a = i
        if i >= x and i not in lis:
            b = i
            if abs(a-x) <= abs(b-x):
                print(a)
            else:
                print(b)
            break

Solution (Python):
import sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**20
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()

def resolve():
    X, N = LI()
    if N == 0:
        print(X)
        return

    p = LI()

    p_max = max(p)
    p_min = min(p)

    if X < p_min or p_max < X:
        print(X)
        return
    else:
        d = [abs(i-X) for i in range(0, 102) if i not in p]
        d_min = min(d)
        for i in range(0, 102):
            if i not in p:
                if abs(i-X)==d_min:
                    print(i)
                    return

if __name__ == '__main__':
    resolve()

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

Solution (Python):
s = input().split()

x = int(s[0])
n = int(s[1])

s = {i for i in range(-1,102)}

p1 = input().split()

p = set()

for i in p1:
    p.add(int(i))

t = s - p

answer = 20000

for i in t:
    if (abs(x - int(i)) < abs(x - answer)) or (abs(x - int(i)) == abs(x - answer)) and i < answer:
        answer = int(i)

print(answer)

Solution (Python):
x , n =  map(int, input().split())
P = [int(i) for i in input().split()]
test = [int(i) for i in range(0,102)]
a = []
for i in range(n):
    test.remove(P[i])
for j in test:
    a.append( abs(x-j) )
ind = a.index(min(a))
print(test[ind])

Solution (Python):
li = []
for i in range(102):
    li.append(i)
lis = set(li)
x,n = map(int,input().split())
if n == 0:
    print(x)
    exit()
lia = list(map(int,input().split()))
lias = set(lia)
seta = lis - lias
li = list(seta)
li.reverse()
a = 1000
for i in range(102-n):
    if abs(li[i]-x) <= a:
        a = abs(li[i]-x)
        b = li[i]
print(b)

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

result = 0
if N == 0:
    result = X
else:
    list = [i for i in range(201)]
    for i in P:
        list.remove(i)
    if len(list) == 0:
        result = 0
    else:
        min = 100
        for i in list:
            if min > abs(X-i):
                min = abs(X - i)
                result = i
print(result)

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

p1 = [abs(i-x) for i in p]

p = set(p)
p1.sort()
if len(p1) ==0:
    print(x)
else:
    if p1[0] != 0:
        print(x)
    else:
        cnt = 1
        while(cnt < len(p1)):
            
            
            
            if p1[cnt] != int((cnt+1)/2):
                break
            else:
                cnt +=1
        
        if x-int((cnt+1)/2) in p:
            print(x+int((cnt+1)/2))
        else:
            print(x-int((cnt+1)/2))

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

if x in listp:
    for i in range(1,101):
        a = x + i
        b = x - i
        if a in listp and b in listp:
            continue
        else:
            if not a in listp:
                ans.append(a)
            
            if not b in listp:
                ans.append(b)

            if len(ans) > 0:
                break
else:
    print(x)
    exit()

print(min(ans))

Solution (Python):
a,b=map(int,input().split())
if b==0:
  print(a)
  exit()
s=list(map(int,input().split()))

lst=[i for i in range(0,202)]
for j in range(b):
  lst.remove(s[j])


n=100
for k in lst:
  m=abs(a-k)
  n=min(n,m)

if (a-n) in lst:
  print(a-n)
  exit()
else:
  print(a+n)

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

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

P = [int(i) for i in input().split()]
mn = 1000
for i in reversed(range(102)):
	if i in P:
		continue
	if mn >= abs(X-i):
		ans = i
		mn = min(mn,abs(X-i))

print(ans)

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

Solution (Python):
import bisect
X,N=map(int,input().split())
if N==0:
    print(X)
    exit()
P=sorted(list(map(int, input().split())))
key=bisect.bisect_right(P,X)
small=101
large=0

for i in range(N):
    if P[key-1]-i not in P:
        small=P[key-1]-i
        break
for i in range(N):
    if P[key-1]+i not in P:
        large=P[key-1]+i
        break
print(small if abs(X-small)<=abs(X-large) else large)

Solution (Python):
def main():
    import sys
    X, N = map(int, sys.stdin.readline().split())
    P = list(map(int, sys.stdin.readline().split()))
    
    i = 0
    while True:
        if X-i in P:
            pass
        else:
            print(X-i)
            break
        if X +i in P:
            pass
        else:
            print(X+i)
            break
        i+=1
    


if __name__=='__main__':
    main()

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

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

for i in range(101):
    p = X - i not in P
    p1 = X + i not in P
    if p1 or p:
        if p:
            print(X - i)
            exit()
        print(X + i)
        exit()

Solution (Python):
X,N=list(map(int,input().split()))
src=list(map(int,input().split()))
all_diff_src = [X-n for n in range(0,102) if n not in src]
ans = 101
for s in all_diff_src:
  if ans > abs(s):
    ans = s
print(X-ans)

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

px = x + 1
mx = x - 1
if n == 0:
    print(x)
    exit()
elif x not in p:
    print(x)
    exit()

while True:
    if mx not in p:
        print(mx)
        exit()
    elif px not in p:
        print(px)
        exit()
    px += 1
    mx -= 1

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

INF = 999
x_flg = True
x_plus = []
x_minus = []
for i in range(0, n):
    x_plus.append(x+i+1)
    x_minus.append(x-(i+1))

for p_num in p:
    if p_num == x:
        x_flg = False

    if p_num in x_plus:
        x_plus.remove(p_num)

    if p_num in x_minus:
        x_minus.remove(p_num)

if x_flg:
    print(x)
else:
    x_plus_min = min(x_plus) if len(x_plus) > 0 else INF
    x_minus_max = max(x_minus) if len(x_minus) > 0 else INF
    xp = abs(x-x_plus_min)
    xm = abs(x-x_minus_max)
    if xp < xm:
        print(x_plus_min)
    elif xp >= xm:
        print(x_minus_max)

Solution (Python):
x,n = map(int,input().split())
nump = list(map(int,input().split()))
nump.sort()
x_ind = -1
nump_io = [0]*103
for i in range(n):
    nump_io[nump[i]-1] = 1
    if(nump[i]==x):
        x_ind = i
if(x_ind == -1):
    print(x)
else:            
    for i in range(1,51):
        if(nump_io[(x-1)-i] == 0):
            print(x-i)
            break
        if(nump_io[(x-1)+i] == 0):
            print(x+i)
            break

Solution (Python):
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
import math
from copy import deepcopy
import queue
import numpy as np

Mod = 1000000007
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1] 
for i in range(2, 10**5 + 1):
    fact.append((fact[-1] * i) % Mod)
    inv.append((-inv[Mod % i] * (Mod // i)) % Mod)
    factinv.append((factinv[-1] * inv[-1]) % Mod)
    
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n - r] % p
    
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[y] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)

def main():  
    x, n = map(int, input().split())
    numlist = [i for i in range(102)]
    p = list(map(int, input().split()))
    for i in range(101):
        if numlist[i] in p:
            numlist[i] = -1
    ans = float("inf")
    memo = 101
    for i in range(102):
        if numlist[i] == -1: continue
        if ans > abs(numlist[i] - x):
            ans = abs(numlist[i] - x)
            memo = i
    print(memo)
if __name__ == "__main__":
    main()

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

for i in range(1000):
    if X-i not in p:
        print(X-i)
        break
    if X+i not in p:
        print(X+i)
        break

Solution (Python):
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007



def main():
	
	x, n = tin()
	
	al = set(lin())
	mm=5000
	mv=-1000
	for i in range(-100,200):
		if abs(i-x) < mm and i not in al:
			mm = abs(i-x)
			mv = i
	print(mv)
	
	
	
	

isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		
			
	ret = main()
	if ret is not None:
		print(ret)

Solution (Python):
X, N = map(int,input().split())
P = list(map(int,input().split()))
ans = 0
def f(X,N,P):
  if(N==0):
    ans = X
    return ans
  else:
    for i in range(N+1):
      if(not (X-i in P)):
        ans = X-i
        return ans
      elif(not (X+i in P)):
        ans = X+i
        return ans
print(f(X,N,P))

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

cnt=0

while True:
    if x-cnt not in l:
        print(x-cnt)
        break
    elif x+cnt not in l:
        print(x+cnt)
        break
    else:
        cnt+=1

Solution (Python):

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

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

    ans = 0
    
    for i in range(100):
        numm = x - i
        nump = x + i

        if not(numm in arg):
            ans = numm
            break
        
        elif not (nump in arg):
            ans = nump
            break

    print(ans)

Solution (Python):




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

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

z=101
p_list = list(map(int,input().split()))
pp_list = [i for i in range(102)]

for j in p_list:
    pp_list.remove(j)

for k in pp_list:
    zettaiti = abs(x-k)

    if z > zettaiti:
        z = zettaiti
        ans = k

print(ans)

Solution (Python):

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


if n == 0:
    print(x)
else:
    ps = sorted(p)
    tmp = list(range(-201, 200))
    ans_list = list(set(tmp) ^ set(ps))
    ans_list = sorted(ans_list)
    
    diff = []

    for i in ans_list:
        diff.append(abs(i - x))

    print(ans_list[diff.index(min(diff))])

Solution (Python):
def main():
  X, N = map(int, input().split())
  if N == 0:
    return X
  
  P = list(map(int, input().split()))
  
  delta = []
  for n in range(-1, 102):
    if n in P:
      delta.append(float('inf'))
    else:
      delta.append(abs(X - n))
      
  minD = min(delta)
  for i, d in enumerate(delta):
    if d == minD:
      return i - 1


print(main())

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

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

  p.sort()
  q=list(range(-5,102))

  for i in p:
    q.remove(i)

  Z=1000
  for i in q:
    if( abs(X-i)<Z):
      Z=abs(X-i)
      ans=i
  
  print(ans)

Solution (Python):
X, N = map(int, input().split())
if N == 0:
  print(X)
else:
  p = list(map(int, input().split()))
  flag = True
  i = 0
  ans_min = 2**8
  while flag:
    cand = X - i
    if not cand in p:
      ans_min = cand
      flag = False
    cand = X + i
    if not cand in p:
      ans_max = cand
      flag = False
    i += 1
    
  if ans_min != 2**8:
    print(ans_min)
  else:
    print(ans_max)

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

if X not in p:
    print(X)


else:
    c = list(set([i for i in range(102)]) ^ set(p))
    c_x = [abs(c_-X) for c_ in c]
    print(c[c_x.index(min(c_x))])

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

for i in range(101):
    a = int(x - i)
    b = int(x + i)
    if a not in p:
        print(a)
        exit()
    elif b not in p:
        print(b)
        exit()

Solution (Python):
def main():
    X,N = map(int, input().split())
    if N ==0:
        print(X)
        return 0
    p = list(map(int, input().split()))
    for i in range(51):
        if not (X-i) in p:
            print(X-i)
            return 0
        elif not (X+i) in p:
            print(X+i)
            return 0
          
main()

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

def calc():
    x, n = [int(x) for x in input().split()]

    if n == 0:
        q = [x for x in range(102)]
    else:
        p = [int(x) for x in input().split()]
        q = [x for x in range(102) if x not in p]
    diffs = [abs(x - qk) for qk in q]
    mindiff = min(diffs)
    idx = diffs.index(mindiff)
    print(q[idx])

calc()

Solution (Python):
x, n = map(int, input().split())
if n == 0:
  print(x)
else:
  p = list(map(int, input().split()))
  absv = x
  value = x
  for i in range(-1, 102):
    if i in p:
      pass
    else:
      if absv > abs(x - i):
        absv = abs(x - i)
        value = x - i
  print(x - value)

Solution (Python):
[_x, _n] = list(map(int, input().split(" ")))
if _n == 0:
  print(_x)
else:
  _list = list(map(int, input().split(" ")))
  _answer = 0
  _flag = False

  if _x not in _list or _n == 0:
    _answer = _x
    _flag = True
  else:
    for _i in range(_n):
      if _i % 2 == 0:
        if _x - _i//2 - 1 not in _list and _flag == False:
          _answer = _x - _i//2 - 1
          _flag = True
      else:
        if _x + _i//2 + 1 not in _list and _flag == False:
          _answer = _x + _i//2 + 1
          _flag = True
  print(_answer)

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

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

Solution (Python):



import sys


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


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

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

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

    max_p = 100
    not_p_list = []


    flag = False
    for j in range(-max_p-1, max_p):
        j1 = j+1
        if j1 in p_list:
            pass
        else:
            not_p_list.append(j1)
    not_p_list.append(101)
    

    min_num = 999
    ans = 0

    for i in not_p_list:

        m = abs(x - i)
        if min_num >= m:
            if min_num == m:
                continue
            min_num = m
            ans = i

    print(ans)

if __name__ == "__main__":
    resolve()

Solution (Python):
def main():
	x, n = map(int, input().split())
	P = list(map(int, input().split()))
	if n == 0:
		print(x)
		return
	ans = 0
	min_dis = 1000
	for item in range(102):
		if item in P:
			continue
		dis = abs(item - x)
		if min_dis > dis:
			min_dis = dis
			ans = item
	print(ans)
	return

if __name__ == "__main__":
	main()

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

ps = list(map(int, input().split()))
if not x in ps:
    print(x)
    quit()

m_diff = 0
b_diff = 0

m = x
while m in ps:
    m_diff += 1
    m -= 1

b = x
while b in ps:
    b_diff += 1
    b += 1

if (m_diff > b_diff):
    print(b)
else:
    print(m)

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

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

if N == 0:
    print(X)
else:
    for i in range(110):
        if X - i not in p:
            print(X - i)
            break
        elif X + i not in p:
            print(X + i)
            break

Solution (Python):






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

if n == 0:
    print(x)

else:
    max = -1
    i = -1
    while(max == -1):
        i = i + 1
        if p.count(x+i) == 0:
            max = x+i

    min = -1
    j = -1
    while(min == -1):
        j = j + 1
        if p.count(x-j) == 0:
            min = x-j

    if (abs(x-max) < abs(x-min)):
        print(max)
    else:
        print(min)

Solution (Python):

MOD = 10**9+7

X,N = map(int, input().split())
if N == 0:
    print(X)
    quit()

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

p = []
for i in range(102):
    p.append(i)

for i in range(N):
    p[P[i]] = MOD

tmp = 0
m = MOD
ans = 0
for i in reversed(range(0,102)):
    tmp = abs(X-p[i])
    m = min(tmp,m)
    if m == tmp:
        ans = p[i]

print(ans)

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

nyuryoku = []

try:
    while True:
        p = list(map(int,input().split()))
        if p == '':
            break
        nyuryoku.append(p)

except EOFError:
    pass








L = []
for i in range(1, 100):
    for j in ['-', '']:
        
        a = (j + str(i))
        
        L.append(a)


if N == 0:
    print(X)
elif X not in p:
    print(X)
else:
    for i in L:
        if (X + int(i)) not in p:
            print(X + int(i))
            break

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


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

Solution (Python):
from collections import defaultdict
x,n=map(int,input().split())
p_array=map(int,input().split())
p_map=defaultdict(bool)

for p in p_array:
    p_map[p]=True
ans=0
for i in range(51):
    if not p_map[x-i]:
        ans=x-i
        break
    elif not p_map[x+i]:
        ans=x+i
        break
print(ans)

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

i=0
p=X+1
q=X-1
while True:
    if N==0:
        print(int(X))
        break
    if X not in P:
        print(int(X))
        break
    if q not in  P:
        print(int(q))
        break
    if p not in P:
        print(int(p))
        break
    i+=1
    p+=1
    q-=1

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

p = list(map(int, input().split()))
pp = set(p)
numlist = [i for i in range(-1000, 1000)]
numlistt = set(numlist)
newlist = numlistt - pp
newlistt = list(newlist)
absn = 1000
ans = 1000
 
for i in newlistt:
    if absn > abs(X-i):
        ans = i
        absn = abs(X-i)
    elif absn == abs(X-i) and i < ans:
        ans = i
        absn = abs(X-i)

print(ans)

Solution (Python):
X,N = map(int,input().split())
p = list(map(int,input().split()))
number = X
j = 0
while j<100:
    if (X-j in p)== False:
        number = X-j
        break
    if (X+j in p) == False:
        number = X+j
        break
    j = j + 1
print(number)

Solution (Python):

import numpy as np
from functools import *

import sys
sys.setrecursionlimit(100000)



def gcd(a, b):
	while b:
		a, b = b, a % b
	return a


def acinput():
    return list(map(int, input().split(" ")))


X,N=acinput()
if N>0:
    
    p=sorted(acinput())
else:
    print(X)
    sys.exit()

res=0
res_v=2000
for i in range(0,102):
    
    
    d=abs(X-i)
    if res_v>=d and not (i in p):
        if i<X:
            res_v=d
            res=i
        elif d<res_v:
            res_v=d
            res=i
        
print(res)

Solution (Python):
x,n = map(int, input().split())
a = list(map(int,input().split()))
c = -1
b = 0
d = 101
e = 0
for w in range(103):
  if c not in a:
    b = abs(x - c)
    if b < d:
      d = b
      e = c
      c += 1
    else:
      c += 1
  else:
    c += 1
print(e)

Solution (Python):
import math

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

pnt_big = 0
pnt_small = 0
ans_big = 100
ans_small = 100
for i in range(101):
    if p.count(x+i) == 0:
        ans_big = x+i
        pnt_big = 1
    if p.count(x-i) == 0:
        ans_small = x-i
        pnt_small = 1
    if pnt_small == 1 or pnt_big == 1:
        break

if pnt_big ==1 and pnt_small == 1:
    print(ans_small)
if pnt_big == 0 and pnt_small == 1:
    print(ans_small)
if pnt_big == 1 and pnt_small == 0:
    print(ans_big)

Solution (Python):




def serchBup(list,n):
    if n in list:
        return 1+serchBup(list,n+1)
    else:
        return 1
        
    
def serchBdown(list,n):
    if n in list:
        return -1+serchBdown(list,n-1)
    else:
        return -1

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

if n == 0:
    print(x)
else:
    p = list(map(int, input().split()))
    p.sort()
    min = 1000000000
    ans =0

    for i in range(n):
        if abs(x-p[i])<min:
            min  = abs(x-p[i])
            ans = p[i]
            pos=i
    
    if ans in p:
        
        tmp1=serchBup(p,ans+1)
        tmp2=serchBdown(p,ans-1)
        
        if abs(tmp1) < abs(tmp2):
            print(ans+tmp1)
        else:
            print(ans+tmp2)
        
    else:
        print("Fasle")
        print(ans)

Solution (Python):
nums=[int(s) for s in input().split()]

x=nums[0]
n=nums[1]

if n==0:
  print(x)
else:
  row=[int(s) for s in input().split()]
  ls=[]
  for i in range(0,220):
    if i not in row:
      ls.append(abs(i-x))

  ls.sort()

  if x-ls[0] not in row:
    print(x-ls[0])
  else:
    print(x+ls[0])

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

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

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


for i in range(100) :
    i1=x-i
    i2=x+i
    
    if i1 not in p and i2 not in p :
        print(i1)
        sys.exit()
        
    
    if i1 not in p and i2 in p :
        print(i1)
        sys.exit()
    
    if i2 not in p and i1 in p :
        print(i2)
        sys.exit()

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

  i=0
  while(True):

    Xi = X - i
    if Xi not in p_list:
      break

    Xi = X + i
    if Xi not in p_list:
      break

    i = i + 1

  print(Xi)

Solution (Python):
s=input().rstrip().split(' ')
x=int(s[0])
n=int(s[1])

if(n>0):
    s=input().rstrip().split(' ')
    p=[]
    
    for i in s:
        p.append(int(i))
    
    p.sort()
    cur1=x
    count1=0
    
    if(p[n-1]>x):
        while(cur1 in p):
            cur1+=1
            count1+=1
    elif(p[n-1]==x):
        cur1+=1
        count1+=1
        
    cur2=x
    count2=0
    
    if(p[0]<x):
        while(cur2 in p):
            cur2-=1
            count2+=1
    elif(p[n-1]==x):
        cur2-=1
        count2+=1
        
    if(count1>=count2):
        print(cur2)
    else:
        print(cur1)
        
else:
    print(x)

Solution (Python):

import sys
input = sys.stdin.readline


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

    ans = x
    for i in range(-1, 102):
        if i in p:
            continue

        if i <= x:
            ans = i
        else:
            if x - ans > i - x:
                ans = i
            break

    print(ans)


if __name__ == '__main__':
    main()