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):
"""
    こんにちは。これはクシャルです
    
    Author : thekushalghosh (クシャル)
    Team   : CodeDiggers
 
    I prefer Python language over the C++ language :p :D
        
    Visit my website : thekushalghosh.github.io
"""
import sys,math,cmath,time
start_time = time.time()



def solve():
    x,n = invr()
    a = inlt()
    a.sort()
    if x not in a:
        print(x)
        return
    q = []
    for i in range(len(a)):
        q.append(abs(x - a[i]))
    q.sort()
    w = counter(q)
    qw = -1
    for i in range(1,len(a)):
        if q[i] - q[i - 1] > 1:
            qw = q[i - 1] + 1
            break
        if w[q[i]] == 1:
            qw = q[i]
            break
    if qw != -1:
        if x - qw not in a:
            print(x - qw)
        else:
            print(x + qw)
    else:
        print(x - max(q) - 1)
            


 
def main():
    global tt
    if not ONLINE_JUDGE:
        sys.stdin = open("input.txt","r")
        sys.stdout = open("output.txt","w")
    t = 1
    for tt in range(t):
        solve()
    if not ONLINE_JUDGE:
        print("Time Elapsed :",time.time() - start_time,"seconds")
        sys.stdout.close()
    

def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    return(input().strip())
def invr():
    return(map(int,input().split()))
 

def counter(a):
    q = [0] * (max(a) + 1)
    for i in range(len(a)):
        q[a[i]] = q[a[i]] + 1
    return(q)
 
def string_counter(a):
    q = [0] * 26
    for i in range(len(a)):
        q[ord(a[i]) - 97] = q[ord(a[i]) - 97] + 1
    return(q)

def power_two(n):
    if n == 1:
        return(True)
    sttr = str(n)
    len_str = len(sttr)
    sttr = list(sttr)
    num = 0
    if (len_str == 1 and sttr[len_str - 1] == '1'): 
        return(False)
    while (len_str != 1 or sttr[len_str - 1] != '1'):
        if ((ord(sttr[len_str - 1]) - ord('0')) % 2 == 1):
            return(False)
        j = 0; 
        for i in range(len_str):  
            num = num * 10 + (ord(sttr[i]) - ord('0')); 
            if (num < 2): 
                if (i != 0):  
                    sttr[j] = '0'
                    j += 1
                continue
  
            sttr[j] = chr((num // 2) + ord('0'))
            j += 1; 
            num = (num) - (num // 2) * 2
        len_str = j
    return(True)

def getLeftmostBit(n): 
    m = 0
    while (n > 1) : 
        n = n >> 1
        m += 1
    return(m)
def getNextLeftmostBit(n, m) : 
    temp = 1 << m 
    while (n < temp) : 
        temp = temp >> 1
        m -= 1
    return m
def bitcounter(n) :
    m = getLeftmostBit(n) 
    return _countSetBits(n, m) 
def _countSetBits(n, m) :
    if (n == 0) : 
        return 0
    m = getNextLeftmostBit(n, m)
    if (n == (1 << (m + 1)) - 1) : 
        return ((m + 1) * (1 << m))
    n = n - (1 << m)
    return (n + 1) + bitcounter(n) + m * (1 << (m - 1)) 

def log_two(n): 
    return(math.log(n) / math.log(2))


        
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
    input = sys.stdin.readline
    
main()

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

Solution (Python):
X, N = map(int, input().split())
A = list(map(int, input().split()))
loki = 0
while loki >= 0:
    if A.count(X - loki) == 0:
        print(X - loki)
        loki = -1
    elif A.count(X + loki) == 0:
        print(X + loki)
        loki = -1
    else:
        loki += 1

Solution (Python):
import sys

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

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

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


cnt=1
a=0
b=0

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

  if (x+i) not in p:
    print(x+i)
    break

Solution (Python):

X , N = map(int,input().split())
P = list(map(int,input().split()))
ans = (X,0)
for i in range(1010):
    if P.count(i)==0:
        
        if ans[0] > abs(X-i):
            ans = (abs(X-i),i)
print(ans[1])

Solution (Python):
x,n = map(int,input().split())
if n != 0:
  a = list(map(int,input().split()))
else:
  print(x)
  exit(0)
b = [0]*100
c = [0]*100
for i in range(n):
  if a[i]-x > 0:
    b[a[i]-x] += 1
  elif a[i] -x <0:
    c[abs(a[i]-x)] += 1
  else:
    b[0]+=1
    c[0]+=1
for i in range(100):
  if b[i] == 0 and c[i] == 0:
    print(x-i)
    exit(0)
  elif b[i] == 0:
    print(x+i)
    exit(0)
  elif c[i] == 0:
    print(x-i)
    exit(0)

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

A.sort()


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

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


l = r = X
while True:
  l -= 1
  if not l in A:
    ans = l
    break

  r += 1
  if not r in A:
    ans = r
    break

print(ans)

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

p = list(map(int, input().split()))
if len(p) == 0:
    print(x)
    exit(0)
for abs in range(n+1):
    if (x - abs) not in p:
        print(x-abs)
        exit(0)
    elif (x + abs) not in p:
        print(x+abs)
        exit(0)

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

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

Solution (Python):
def binarySearch (arr, l, r, x): 
  
    
    if r >= l: 
  
        mid = l + (r - l) // 2
  
        
        if arr[mid] == x: 
            return mid 
          
        
        
        elif arr[mid] > x: 
            return binarySearch(arr, l, mid-1, x) 
  
        
        
        else: 
            return binarySearch(arr, mid + 1, r, x) 
  
    else: 
        
        return -1

l=list(map(int, input().split(' ')))

find=l[0]
n=l[1]

if n==0:
    print(find)
else:
    l=list(map(int, input().split(' ')))
    l=sorted(l)

    a=find
    b=find
    
    while True:
        if binarySearch(l, 0, n-1, b)==-1:
            print(b)
            break
        elif binarySearch(l, 0, n-1, a)==-1:
            print(a)
            break
        else:
            a+=1
            b-=1

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

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

P.sort()

result = 0
for i in range(0, 101):
    if X - i not in P:
        result = X - i
        break
    if X + i not in P:
        result = X + i
        break

print(result)

Solution (Python):
x, n = map(int, input().split())
p = list(map(int, input().split()))
if n == 0:
    print(x)
    exit()
for i in range(101):
    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_list = list(map(int, input().split()))
ref_list = [i for i in range(0, 102)]
res = 0
val_abs = 1000
for i in ref_list:
  if i not in p_list:
    val = abs(x - i)
    if val < val_abs:
      val_abs = val
      res = i
print(res)

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

sp = set(p)
ans = -200
for i in range(-100, 102):
    if abs(x-i) <= abs(x-ans) and not i in sp:
        if abs(x-i)==abs(x-ans):
            ans = min(ans, i)
        else:
            ans = i
print(ans)

Solution (Python):
x, n = [int(i) for i in input().split()]
flag = [0 for i in range(105)]
if (n != 0):
    p = [int(i) for i in input().split()]

    for i in p:
        flag[i] = 1



for i in range(100):
    if x-i >=0:
        if flag[x-i] == 0:
            ans = x-i
            break
    else:
        ans = -1
        break

    if flag[x+i] == 0:
        ans = x+i
        break
    
print(ans)

Solution (Python):
x, n = map(int,input().split())
p = list(map(int,input().split()))
a = 0
b = 0
for i in range(100):
    a = x - i
    b = x + i
    if p.count(a) == 0:
        print(x - i)
        exit()
    else:
        if p.count(b) == 0:
            print(x + i)
            exit()

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

if N == 0:
    print(X)
else:
    p = list(map(int, input().split()))
    nums = {i for i in range(0, 102)}
    nothings = nums - set(p)
    differences = {}
    for i in nothings:
        difference = abs(X - i)
        if difference in differences:
            differences[difference].append(i)
        else:
            differences[difference] = [i]
    ans = sorted(differences.items())
    print(min(ans[0][1]))

Solution (Python):
import math

x, n = map(int, input().split(" "))
ps = input()
if ps == "":
    print(x)
    exit()
ps = sorted(list(map(int, ps.split(" "))))

if not x in ps or len(ps) == 0:
    print(x)
    exit()

g = 1
while True:
    if not (x - g in ps):
        print(x - g)
        exit()
    if not (x + g in ps):
        print(x + g)
        exit()
    g += 1
    if g == 101:
        print(0)
        exit()

Solution (Python):
import itertools,sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
X,N = LI()
p = set(LI())
ans,distance = 0,float('INF')
for x in range(-202,202)[::-1]:
    if x in p:
        continue
    now_distance = abs(X-x)
    if now_distance<=distance:
        ans = x
        distance = now_distance
print(ans)

Solution (Python):
import sys
X, N = [int(x) for x in input().split()]
if(N != 0):
  p = [int(x) for x in input().split()]
else:
  print(X)
  sys.exit()

i = 0
x = 0
while True:
  delta1 = X - i
  delta2 = X + i
  if((delta1 in p)==False):
    x = delta1
    print(x)
    sys.exit()
  elif((delta2 in p)==False):
    x = delta2
    print(x)
    sys.exit()
  i += 1

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

all_set = set(range(102))
diff_set = all_set - P

min_value = -1
min_diff = 100
for e in diff_set:
    difference = abs(x - e)
    if difference < min_diff:
        min_value = e
        min_diff = difference
print(min_value)

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

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



b = 1000
p = -1
if n == 0:
	print(x)
else:
	for i in range(-101,102):
		if abs(x-i) < b and i not in arr:
			p = i
			b = abs(x-i)
	print(p)

Solution (Python):
x,n=map(int,input().split())
arr=[int(x) for x in input().split()]
i,j=(x-50),(x+50)
min=10**9
z=x
for t in range(i,j+1):
    if abs(t-x)<min and t not in arr:
        z=t
        min=abs(t-x)
print(z)

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

Solution (Python):
import copy
n, k = map(int, input().split())
a = list(map(int, input().split()))
N_min = copy.copy(n)
N_max = copy.copy(n)

while True:
    if not(N_min in a):
        print(N_min)
        break
    if not(N_max in a):
        print(N_max)
        break
    N_min -= 1
    N_max += 1

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


if n == 0:
    print(x)
elif x < min(arr):
    print(x)
elif x > max(arr):
    print(x)
elif not x in arr:
    print(x)
else:
    res = -1
    min_diff = 8491654891598
    for i in range(-1,102):
        if i in arr:
            continue
        
        if abs(x - i) < min_diff:
            min_diff  = abs(x - i)
            res = i
    print(res)

Solution (Python):

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

ans = x

min_num = 10**9
for i in range(-200,301):
    if p.count(i) == 0:
        if min_num > abs(x-i):
            min_num = abs(x-i)
            ans = i

print(ans)

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

for i in range(N//2 + 2):
    A = X - i
    if A not in P:
        print(A)
        exit() 
    B = X + i
    if B not in P:
        print(B)
        exit()

Solution (Python):
X, N = map(int, input().split())
p = list(input().split())
p = [int(p[i]) for i in range(N)]
ans = float('inf')
dif = float('inf')

for i in range(0, 102):
    if i not in p and abs(i - X) < dif:
        ans = i
        dif = abs(i-X)

print(ans)

Solution (Python):
import sys
from collections import deque
si = sys.stdin.readline


def main():
    l = [int(e) for e in si().split()]
    pn = set()
    if l[1] != 0:
        pn = set(int(e) for e in si().split())

    d = 0
    x = l[0]
    if x not in pn:
        print(x)
    else:
        while True:
            d += 1
            if x-d not in pn:
                print(x-d)
                break
            if x+d not in pn:
                print(x+d)
                break


if __name__ == '__main__':
    main()

Solution (Python):
import sys
def input():
    return sys.stdin.readline()[:-1]


def main():
    X, N = map(int,input().split())
    p = list(map(int,input().split()))
    p_new = [i - X for i in p]
    num = 0
    while num in p_new and -num in p_new:
        num += 1
    if X - num in p:
        print(X + num)
    else:
        print(X - num)

    
if __name__ == "__main__":
    main()

Solution (Python):
import numpy as np

XN=np.array(input().split(" "),dtype=np.int32)
X=XN[0]
N=XN[1]

if(N==0):
    print(X)
else:
    p=np.array(input().split(" "),dtype=np.int32)
    p=np.sort(p)
    ABS=0
    results=[]
    length=0
    while(True):
        upper=X+ABS
        lower=X-ABS
        
        if(upper in p):
            pass
        else:
            results.append(upper)
            length+=1
        if(lower in p):
            pass
        else:
            results.append(lower)
            length+=1
        
        if(length>0):
            break
        ABS+=1
    print(min(results))

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

if N == 0:
    P = []
else:
    P = [int(x) for x in input().split()]

for i in range(100):
    q = X - i
    if q not in P:
        print(q)
        break
    q = X + i
    if q not in P:
        print(q)
        break

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

check = [0 for i in range(110)]
for i in range(N):
    check[P[i]-1] = 1
    
dx_ls = [1000 for i in range(110)]
ans = []
for i in range(110):
    if check[i] == 0:
        dx_ls[i] = abs(X-(i+1))
            
dx_min = min(dx_ls)
for i in range(110):
    if dx_ls[i] == dx_min:
        ans.append(i+1)
        
ans_plus = min(ans)

if abs(ans_plus-X) >= abs(X - 0):
    print(0)
else:
    print(ans_plus)

Solution (Python):
X, N = map(int, input().split())
*P, = map(int, input().split())
l = set([i for i in range(-200, 200)]) - set(P)
m = 100000000
ans = 0
for i in l:
    if abs(i-X) < m:
        ans = i
        m =abs(i - X)
print(ans)

Solution (Python):

import sys

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


p_set = set(p_list)
delta = 0

while True:
    for d in [-delta, delta]:
        n = X + d
        
        if n in p_set:
            continue
        else:
            print(n)
            sys.exit()
    
    delta += 1

Solution (Python):
import sys
X, N = map(int, input().split())
p = list(map(int, input().split()))
P = set(p)
a = 1000
c = -101
if N == 0:
    print(X)
    sys.exit()
if X not in P:
    print(X)
    sys.exit()
for i in range(-1, 102):
    if i in P:
        continue
    if abs(i - X) == a:
        c = min(c, i)
    elif abs(i - X) < a:
        c = i
        a = abs(i - X)
print(c)

Solution (Python):
x,n=map(int,input().split(" "))
if n==0:
  print(x)
else:
  line=list(map(int,input().split(" ")))
  a=0
  b=0
  while a==0:
    if x-b not in line:
      min=x-b
      a=1
    elif x+b not in line:
      min=x+b
      a=1
    else:
      b=b+1
  print(min)

Solution (Python):

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

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

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

if n==0:
    print(x)

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

Solution (Python):





import sys
import heapq

def main():
    x, n = map(int, input().split()) 
    nums = list(map(int, sys.stdin.readline().split()))
    if x not in nums:
        print(x)
        return
    
    
    ans = None
    diff = 1
    while True:
        if x - diff not in nums:
            ans = x - diff
            break
        elif x + diff not in nums:
            ans = x + diff
            break
        diff += 1

    print(ans)
        
        
    
    return

if __name__ == "__main__":
    main()

Solution (Python):
XN = [int(x) for x in input().split()]
p = [int(x) for x in input().split()]
tmp=100
tmp_i=0
for i in range(102):
  if not i in p:
    if abs(XN[0]-i)<tmp:
      tmp=abs(XN[0]-i)
      tmp_i=i
print(tmp_i)

"""
10 5
4 7 10 6 5
"""

Solution (Python):
x,n=list(map(int,input().split()))
if(n==0):
    print(x)
else:
    p=list(map(int,input().split()))
    mini=min(p)-1
    maxi=max(p)+1

    m=abs(maxi-x)
    val=maxi
    i=maxi
    while(i>=mini):
        if(i in p):
            pass
        else:
            
            
            if(abs(i-x)<=m):
                m=abs(i-x)
                val=i
        i-=1        

    print(val)

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

flag = 0
if N == 0:
    print(X)
else:
    X1 = X
    X2 = X
    ans = []
    while flag ==0:
        
        if not(X1 in p):
            ans.append(X1)
            flag = 1
        if not(X2 in p):
            ans.append(X2)
            flag = 1
        if flag == 1:
            print(min(ans))
            
        else:
            X1-= 1
            X2+= 1

Solution (Python):

import sys


def solve(X: int, N: int, p: "List[int]"):
    for i in range(N):
        if X - i not in p:
            print(X-i)
            return
        elif X + i not in p:
            print(X+i)
            return
    if N == 0:
        print(X)
    else:
        print(X-1)
    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):
X, N = map(int , input().split())
p = list(map(int, input().split()))
k = 0
hugou = 1
hantei = 0
while(hantei == 0):
    if(hugou == -1):
        X -= k
    elif(hugou == 1):
        X += k

    if(X not in p):
        print(X)
        hantei = 1
    else:
        if(hugou == 1):
            hugou = -1
        elif(hugou == -1):
            hugou = 1
        k += 1

Solution (Python):
num = input().split()
num=[int(i) for i in num]

if num[1]!=0:
  line = input().split()
  line=[int(i) for i in line]

  m=0
  while m>=0:
    if num[0]-m not in line:
      print(num[0]-m)
      break
    elif num[0]+m not in line:
      print(num[0]+m)
      break
    else:
      m+=1

else:
  print(num[0])

Solution (Python):
X, N = [ int(i) for i in input().strip().split(' ')]

if N == 0:
    _ = input()
    print(X)
else:
    p = { int(i) for i in input().strip().split(' ')}

    all_set = { n for n in range(-1, 101+1, 1)}
    candidates = list(all_set - p)
    best_distance = 1000
    cand = -2
    for c in candidates:
        distance = abs(c-X)
        if best_distance > distance:
            cand = c
            best_distance = distance
    print(cand)

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

is_exit = [False] * 101

for p in P:
    is_exit[p] = True

if not is_exit[X]:
    print(X)
else:
    l = X - 1
    r = X + 1
    while True:
        if 1 <= l:
            if not is_exit[l]:
                print(l)
                exit()
        else:
            print(l)
            exit()
        if r <= 100:
            if not is_exit[r]:
                print(r)
                exit()
        else:
            print(r)
            exit()
        l -= 1
        r += 1

Solution (Python):
def _main(x, p_list):
    p_set = set(p_list)
    diff = 0
    while True:
        t_minu = x - diff
        if t_minu not in p_set:
            print(t_minu)
            break

        t_plus = x + diff
        if t_plus not in p_set:
            print(t_plus)
            break
        diff += 1



x_a, n_a = map(int, input().split())
p_list_a = map(int, input().split())
_main(x_a, p_list_a)

Solution (Python):
from collections import defaultdict
it = lambda: list(map(int, input().strip().split()))
INF = float('inf')

def solve():
    X, N = it()
    arr = it()
    res = [False] * 102
    for i in range(N):
        res[arr[i]] = True
    
    i = X
    j = X
    while i >= 0 and j <= 101:
        if not res[i]:
            return i
        elif not res[j]:
            return j
        i -= 1
        j += 1

if __name__ == '__main__':
    print(solve())

Solution (Python):
x,n = map(int,input().split())
p = list(map(int,input().split()))
a = x-1
b = x+1

if x not in p:
    ans = x

else:
    while 1:
        if a not in p:
            ans = a
            break

        if b not in p:
            ans = b
            break

        a -= 1
        b += 1
    
print(ans)

Solution (Python):
X, N = map(int, input().split())
P = set(map(int, input().split()))
U = set(range(-200, 201))
diff = sorted(list(U - P))

ans = 0
tmp = float('inf')
for i in diff:
    if tmp > abs(X - i):
        tmp = abs(X - i)
        ans = i
print(ans)

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

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

Solution (Python):
X,N=(int(x) for x in input().split())
p=list(map(int,input().split()))
ans_sa=101
ans=-1
for n in range(-1,102):
    if n in p:
        continue
    sa=abs(X-n)
    if sa<ans_sa:
        ans_sa=sa
        ans=n
print(ans)

Solution (Python):
import numpy as np
def getNearestValue(list, num):
    """
    概要: リストからある値に最も近い値を返却する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]
x,n = map(int,input().split())
b = 0
if n == 0:
  a = 1
else:
  b = [int(i) for i in input().split()]
  b.sort(reverse = True)
if b == 0:
  print(x)
else:
  c = [int(i) for i in range(102)]
  for i in b:
    c.pop(i)
  print(getNearestValue(c,x))

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

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

else:
    if not x in p:
        print(x)
        sys.exit()
    else:
        a1 = x - 1
        a2 = x + 1
        c = 0
        while True:
            if c % 2 == 0:
                if not a1 in p:
                    print(a1)
                    break
                else:
                    a1 -= 1
            else:
                if not a2 in p:
                    print(a2)
                    break
                else:
                    a2 += 1
            c += 1

sys.exit()

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

p = set(map(int, input().split()))
a = set([i for i in range(105)])
np = a-p

ans = 0
dist = 1000000
for i in np:
  if(abs(x-i) < dist):
    dist = abs(x-i)
    ans = i
  elif(abs(x-i) == dist):
    ans = min(i, ans)
  else:
    pass
  
print(ans)

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

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

if len(p) == 0:
    print(x)
    exit(0)

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

    if not x+i in p:
        print(x+i)
        break

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

if n != 0:
    p = list(map(int,input().split()))
else:
    p = []

result = []

i = 0

while len(result) == 0:
    if not (x - i in p):
        result.append(x - i)
    if not (x + i in p):
        result.append(x + i)
    
    i += 1

print(int(min(result)))

Solution (Python):
X,N = map(int,input().split())
if(N == 0):
    print(str(X))
    exit()
p = list(map(int,input().split()))
p = sorted(p)
tmp = 200
for i in range(102):
    if(i in p):
        pass
    else:
        tmp2 = abs(X-i)
        if(tmp2 < tmp):
            tmp = tmp2
            ans = i
        elif(tmp2 == tmp):
            pass
print(str(ans))

Solution (Python):
X, N = map(int, input().split())
p = list(map(int, input().split()))
q = set(range(-1, 102))
r = list(q - set(p))
r.sort()
max = 1000
ans = X

if N == 0:
    print(X)
else:
    for i in r:
        if abs(X - i) < max:
            max = abs(X - i)
            ans = i

    print(ans)

Solution (Python):
def resolve():
    x,n = map(int, input().split())
    if n==0:
        print(x)
    else:
        a = list(map(int, input().split()))
        ans=0
        for i in range(102):
            if i not in a:
                if abs(ans-x)>abs(i-x):
                    ans=i
        print(ans)
resolve()

Solution (Python):


def main():
    X, N = tuple(int(c) for c in input().split(' '))
    if N==0:
        print(X)
        exit()
    p = set(int(c) for c in input().split(' '))
    q = [x for x in range(-2,102) if not x in p]
    q.sort()
    

    minimum = 1000
    for x in q:
        d = abs(x-X)
        d2 = abs(minimum-X)
        if d < d2:
            minimum = x
    print(minimum)

    
    


if __name__ == "__main__":
    main()

Solution (Python):

MOD = 10 ** 9 + 7
INFI = 10**10

import math
from collections import deque
import itertools
import heapq

from fractions import Fraction
import copy
from functools import lru_cache
from collections import defaultdict
import pprint


def sosuhante(n):
    for k in range(2, int(math.sqrt(n))+1):
        if n% k ==0:
            return False
    return True
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def kingaku(a,b,n):
    keta=len(str(n))
    return a*n+b*keta

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default




def ret(a):
    c=[None]*(len(a)-1)
    if len(a)==1:
        return a[0]
    elif len(a)==0:
        return 0
    for i in range(1,len(a)):
        c[i-1]=abs(a[i]-a[i-1])
    return ret(c)

def soinsubunkai(n):
    a = []
    i = 1
    while i*i <= n:
        if n % i == 0 and i!=1:
            a.append(i)
            n=n//i

        if n% i !=0 or i==1:
            i += 1
    nokori=[n]
    return a + nokori

def main():
    x,y=map(int,input().split())
    n=list(map(int,input().split()))
    n=sorted(n)
    iti=x
    minn=10000

    for i in range(iti, 102):
        if i not in n:
            if abs(x - i) < abs(minn - x):
                minn = i
                break
    for i in range(iti,-1,-1):
        if i not in n:
            if abs(x-i)<=abs(minn-x):
                minn=i
                break
    print(minn)







if __name__ == "__main__":

    main()

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

score = 1000
answer = -1
for i in range(-1, 102):
    if i in p:
        continue
    if abs(X - i) < score:
        score = abs(X - i)
        answer = i
print(answer)

Solution (Python):
import sys
x,n=map(int,input().split())
if n==0:
  print(x)
  sys.exit()
p=list(map(int,input().split()))
if not(x in p):
  print(x)
  sys.exit()
p.sort()
r=[]
for i in range(len(p)):
  if p[-1]>x: r.append(p.pop())
p.reverse()
r.reverse()
d=1
while True:
  if not(x-d in p):
    print(x-d)
    break
  elif not(x+d in r):
    print(x+d)
    break
  d+=1

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

for i in range(110):
    xm = x - i
    xp = x + i
    if xm not in p:
        ans = xm
        break
    elif xp not in p:
        ans = xp
        break
    else:
        continue
print(ans)

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

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

if x in p_list:
    while 1:
        if (x - counter) not in p_list:
            print(x - counter)
            break
        elif (x + counter) not in p_list:
            print(x + counter)
            break
        counter += 1
else:
    print(x)

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