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())
line = list(map(int, input().split()))
notLine = [i for i in range(-100, 201) if i not in line]
left = -1
right = len(notLine)
while abs(right - left) > 1:
    middle = (right + left) // 2
    if notLine[middle] >= X:
        right = middle
    else:
        left = middle

if X - notLine[left] <= notLine[right] - X:
    print(notLine[left])
else:
    print(notLine[right])

Solution (Python):
X, N = map(int, input().split())
if N:
  P = set(map(int, input().split()))
else:
  P = set()
c = []
for i in range(102):
  if i not in P:
    c.append((abs(i - X), i))
print(min(c)[1])

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

    if not n:
        print(x)
        return

    ps = list(map(int, input().split()))
    flgs = [1] * 102

    for p in ps:
        flgs[p] = 0

    ansr = 101
    ansl = 101
    index = x
    while 1:
        if flgs[index] == 1:
            ansr = index
            break
        else:
            index += 1

    index = x
    while 1:
        if flgs[index] == 1:
            ansl = index
            break
        else:
            index -= 1

    if abs(ansr - x) >= abs(ansl - x):
        print(ansl)
    else:
        print(ansr)


solve()

Solution (Python):
x,n=map(int,input().split())
p=set(map(int,input().split()))
l=set(range(-100,201))-p
ans=0
tmp=1000
for i in l:
    if tmp>abs(x-i):
        ans=i
        tmp=abs(x-i)
print(ans)

Solution (Python):
X,N = map(int, input().split())
num_list = list(map(int, input().split()))
if (len(num_list) == 0) or X not in num_list:
    print(X)
else:
    d = 1
    while True:
        if X - d not in num_list:
            print(X -d)
            break
        elif X + d not in num_list:
            print(X + d)
            break
        else:
            d +=1

Solution (Python):


def main():

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

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

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

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
import sys
from bisect import bisect_left
def bin(a, x):
    i = bisect_left(a, x) 
    if i != len(a) and a[i] == x: 
        return True
    else: 
        return False

input = sys.stdin.readline

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

lst = sorted(lst)
i = 0
while True:
    if not(bin(lst, x - i)):
        print(x - i)
        break
    elif not(bin(lst, x + i)):
        print(x + i)
        break
    i += 1

Solution (Python):
X,N=map(int,input().split())
A=set(map(int,input().split()))
i=0
while True:
  if not X-i in A:
    print(X-i)
    break
  if not X+i in A:
    print(X+i)
    break
  
  i+=1

Solution (Python):

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

P.sort()
olp=lowp=min(P)-2
ohp=hip=max(P)+2
l=len(P)-1
for i in range(len(P)):
    if P[i]>x :
        if olp<x :
            lowp=x
        break
    if P[i]-olp>1:
        lowp = P[i]-1
    olp=P[i]

for i in range(len(P)):
    if P[l-i]<x :
        break
    if ohp-P[l-i]>1:
        hip = P[l-i]+1
    ohp=P[l-i]



ans = lowp
if x-lowp > hip-x :
    ans = hip
print( ans )

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

for i in range(100):
    if x - i in p:
        if x + i in p:
            continue
        else:
            print(x + i)
            exit()
    else:
        print(x - i)
        exit()
else:
    print(x)

Solution (Python):
x,n=map(int,input().split())
if n==0:
    print(x)
else:
    A=list(map(int,input().split()))
    C=[]
    for i in range(n):
        C.append(abs(A[i]-x))
    C.append(0)
    B=[x for x in set(C) if C.count(x) > 1]
    s=0
    ok=0
    for i in range(len(B)):
        if B[i]-i!=0:
            s=i
            ok=1
            break
    if ok==0:
        s=B[-1]+1
    d=x-s
    for i in range(n):
        if A[i]==d:
            d=x+s
    print(d)

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

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

l = [i for i in range(102)]
l = list(set(l) - set(P))

print(min(l, key=lambda n: abs(X - n)))

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

    
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]

if M==0:
    print(N)
else:
    check_set=set(map(int, input().split()))
    ans_set = set([i for i in range(-1,102)])
    lst = list(ans_set-check_set)
    sorted_lst=sorted(lst)
    print(getNearestValue(sorted_lst, N))

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

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

Solution (Python):
import sys
X,N=map(int, input().split())
p = list(map(int, input().split()))
a=X
for i in range(0,101):
    if (a-i in p)==False:
        print(a-i)
        sys.exit()
    if (a+i in p)==False:
        print(a+i)
        sys.exit()

Solution (Python):
import sys

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

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

sub, up = x, x

while True:
  if sub not in p:
    print(sub)
    sys.exit()
  elif up not in p:
    print(up)
    sys.exit()
  sub -= 1
  up += 1

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

for d in range(x + 1):
	for s in [-1, 1]:
		a = x + s * d 
		if p.count(a) == 0:
			print(a)
			exit(0)

Solution (Python):
X, N = map(int, input().split())
if N>0:
  P = list(map(int, input().split()))
else:
  P = []
i = 0
while True:
  if X-i not in P:
    print(X-i)
    break
  if X+i not in P:
    print(X+i)
    break
  i += 1

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

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

small = X
while small in p:
    small -= 1

large = X
while large in p:
    large += 1

if X - small <= large - X:
    print(small)
else:
    print(large)

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

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

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



ans_list = []

for i in range(-10,110):
    if i not in ps:
        ans_list.append(i)



initial = 10 ** 4
abs_sabun = abs(initial - X)

for ans in ans_list:

    if(abs(ans - X) < abs_sabun):
        abs_sabun = abs(ans - X)
        initial = ans

print(initial)

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

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

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

d = {i: 1 for i in p}
idx = X
while True:
    if d.get(idx) is None:
        ans_plus = idx
        break
    else:
        idx += 1

idx = X
while True:
    if d.get(idx) is None:
        ans_minus = idx
        break
    else:
        idx -= 1

if abs(X - ans_plus) < abs(X - ans_minus):
    print(ans_plus)
else:
    print(ans_minus)

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

Solution (Python):
x,n=map(int,input().split())
if n!=0:
 s=set(list(map(int,input().split())))
else:
 s=[]
diff=10**18
ans=10**18
for i in range(-10000,10000):
 if i in s:
   continue
 else:
   if abs(x-i)<diff:
     ans=i
     diff=abs(x-i)
print(ans)

Solution (Python):
x,n=map(int,input().split())
if n!=0: 
 s=set(list(map(int,input().split())))
else:
 s=[]
diff=10**18
ans=10**18
for i in range(-10000,10000): 
 if i in s: 
   continue
 else:
   if abs(x-i)<diff: 
     ans=i
     diff=abs(x-i)
print(ans)

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

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

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 :
    P = list(map(int, input().split()))
else:
    P = []

P.sort()

L = []
for p in P:
    L.append(p - X)

Ls = sorted(L, key=abs)

for m in range(100):
    if m*(-1) not in Ls:
        print(X - m)
        break
    elif m not in Ls:
        print(X + m)
        break

Solution (Python):

x,n = map(int,input().split())
if n != 0:
    p = list(map(int,input().split()))
    tmp_p = [0] * 102
if n == 0:
    print(x)
else:
    for i in range(n):
        tmp_p[p[i]] += 1
    if tmp_p[x] == 0:
        print(x)
    else:
        j = 1
        stop_min = 0
        stop_max = 0
        while stop_min == 0 or stop_max == 0:
            if x-j >= 0:
                if tmp_p[x-j] == 0:
                    print(x-j)
                    break
            else:
                stop_min += 1
            if x+j <= 101:
                if tmp_p[x+j] == 0:
                    print(x+j)
                    break
            else:
                stop_max += 1
            j += 1

Solution (Python):
x,n = map(int,input().split())
if n != 0:
    p = list(map(int,input().split()))
    tmp_p = [0] * 102
if n == 0:
    print(x)
else:
    for i in range(n):
        tmp_p[p[i]] += 1
    if tmp_p[x] == 0:
        print(x)
    else:
        j = 1
        stop_min = 0
        stop_max = 0
        while stop_min == 0 or stop_max == 0:
            if x-j >= 0:
                if tmp_p[x-j] == 0:
                    print(x-j)
                    break
            else:
                stop_min += 1
            if x+j <= 101:
                if tmp_p[x+j] == 0:
                    print(x+j)
                    break
            else:
                stop_max += 1
            j += 1

Solution (Python):
X,N = list(map(int,input().split()))
if N == 0:
    print(X)
    exit()
p = list(map(int,input().split()))
sorted_p = sorted(p)
minDelta = 1000
minI = 0
for i in range(102):
    if not (i in sorted_p):
        delta = abs(X - i)
        if minDelta > delta:
            minDelta = delta
            minI = i
print(minI)

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


def solve():
    memo = [0] * M
    for a in A:
        d = a - X
        if d >= 0:
            memo[d*2] = 1
        else:
            memo[-d*2-1] = 1
    for i, m in enumerate(memo):
        if m == 0:
            if i % 2 == 0:
                return i//2 + X
            else:
                return -(i+1)//2 + X

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

Solution (Python):
X, N =map(int, input().split())
if N != 0:
  p = list(map(int, input().split()))
  p.sort(reverse=True)
  abs_ans = 1000
  ans = 0
  j = 0
  for i in range(p[0]+1, p[len(p)-1]-2, -1):
    abs_i = abs(X-i)
    if i != p[j] and abs_ans >= abs_i:
      abs_ans = abs_i
      ans = i
    if i <= p[j] and j < len(p) -1:
      j += 1

  print(ans)
  
else:
  print(X)

Solution (Python):
import math
def facts(n):
    ans = []
    for  i in range(1, int(math.sqrt(n)+1)):
        if(n%i==0):
            ans.append(i)
            ans.append(n//i)
    ans = sorted(list(dict.fromkeys(ans)))
    if(ans[-1]==n):
        ans = ans[:-1]
    return ans

x,n = map(int, input().split())
nums = sorted(list(map(int, input().split())))
ans = 101
bfnd, ffnd = False, False
s1, s2 = 0,0
a, b = x,x
while(not bfnd):
    if(x-s1 not in nums):
        a = x-s1
        bfnd = True
        break
    else:
        s1+=1
while(not ffnd):
    if(x+s2 not in nums):
        b = x+s2
        ffnd = True
        break
    else:
        s2+=1
ans = 0
if(abs(x-a) <= abs(x-b)):
    ans = a
else:
    ans = b
print(ans)

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

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

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

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

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


def main():
  X, N = list(map(int, input().split()))
  P = set(list(map(int, input().split())))

  min_ = float('inf')
  for i in range(102):
    if i not in P and abs(X - i) < min_:
      min_ = abs(X - i)

  cand = []

  for i in range(102):
    if i not in P and abs(X - i) == min_:
      cand.append(i)

  print(min(cand))


if(__name__ == '__main__'):
  main()

Solution (Python):
x,n=map(int,input().split())
if(n==0):
    print(x)
else:
    ar=list(map(int,input().split()))
    if x not in ar:
        print(x)
    else:           
        ar.sort()
        di={}
        for i in range(ar[0]-1,ar[n-1]+2):
            if(i not in ar):
                di[i]=abs(x-i)
        
        ans=(2**31)
        for i in di.keys():
            if(di[i]<ans):
                k=i
                ans=di[i]
        print(k)

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

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

for d in range(x + 2):
	if x - d not in p:
		print(x-d)
		exit()
	if x + d not in p:
		print(x+d)
		exit()

Solution (Python):
X, N = map(int, input().split())
P = list(map(int, input().split()))
sub_min = 100
P_bar = [x for x in range(102)]

for p in P:  
    P_bar.remove(p)

for p_bar in P_bar:
    sub = abs(X - p_bar)
    if sub < sub_min:
        sub_min = sub
        answer = p_bar

print(answer)

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

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

for d in range(x + 2):
	for s in [-1, 1]:
		a = x + s * d
		if a not in p:
			print(a)
			exit()

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

Solution (Python):
x,n=map(int,input().split())
I=list(map(int,input().split()))
S=[]
T=[]
ans=[]
for i in range(-200,200):
    S.append(i)
    if i in I:
        S.remove(i)
for j in range(len(S)):
    if j==0:
        T.append(S[0])
    elif abs(x-S[j-1])>abs(x-S[j]):
        T.clear()
        T.append(S[j])
print(min(T))

Solution (Python):

def inputlist(): return [int(j) for j in input().split()]

X,N = inputlist()
ans = 0
m = 10**9+7
p = inputlist()
for i in range(110):
    flag = 0
    for j in range(N):
        if i == p[j]:
            flag = 1
            break
    if flag:
        continue
    d = abs(X-i)
    if d < m:
        m = d
        ans = i
print(ans)

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

ans = 0

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

print(ans)

Solution (Python):
x,n = map(int, input().split())
if n==0:
  print(x)
  quit()
p = list(map(int, input().split()))
ans = 0
for i in range(x+1):
  x1,x2 = x+i,x-i
  if (x1 in p) and (x2 in p):
    continue
  elif not((x1 in p) or (x2 in p)):
    ans = min(x1,x2)
    break
  elif not(x1 in p):
    ans = x1
    break
  else:
    ans = x2
    break
print(ans)

Solution (Python):
x,n=map(int,input().split())
p=sorted(map(int,input().split()))
ans=x
for i in range(n+1):
    if not (x-i) in p:
        ans=x-i
        break
    elif not (x+i) in p:
        ans=x+i
        break

print(ans)

Solution (Python):
X, N = map(int, input().split())
p = list(map(int, input().split()))
 
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 = list(map(int, input().split()))
p = list(map(int, input().split()))
ans = 0
dist = 100
for i in range(102):
    if not i in p:
        if abs(x-i)<dist:
            dist = abs(x-i)
            ans = i
print(ans)

Solution (Python):
n, m = map(int, input().split())
if m == 0:
  lst = []
else:
  lst = [int(i) for i in input().split()]

nums = []
min_l = 1000
for i in range(103):
  if i in lst:
    continue
  l = abs(i - n)
  if l < min_l:
    min_l = l
    min_num = i
  elif l >= min_l:
    break
print(min_num)

Solution (Python):
x,n=map(int,input().split())
if n!=0:
  a=list(map(int,input().split()))	
else:
  print(x)
  exit()
  
b=[]

for i in a:
  b.append(abs(i-x))

m=min(b)
  
if m==0:
  for i in range(max(b)+2):
    if a.count(x-i)==0:
      print(x-i)
      exit()
    if a.count(x+i)==0:
      print(x+i)
      exit()
else:
  print(x)

Solution (Python):
X, N = map(int, input().split())
lst = [0] * 102
p = list(map(int, input().split()))
for i in p:
    lst[i] += 1
if lst[X] == 0:
    print(X)
else:
    up = 1
    dn = 1
    while lst[X+up] == 1:
        up += 1
    while lst[X-dn] == 1:
        dn += 1
    if up >= dn:
        print(X-dn)
    else:
        print(X+up)

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

Solution (Python):
xn = input().split()
data_2 = []
x = int(xn[0]) 

if int(xn[1]) == 0:
    print(x)
else:
    data_str = input().split()
    data = [int(s) for s in data_str] 
    
    
    a = int(xn[0])
    
    while True: 
        while True: 
            for i in range(len(data)):
                if data[i] != a:
                    continue
                else:
                    a -= 1
                    break 
            else:
                data_2.append(a)
                break 

        if len(data_2) == 1: 
            break 


    
    b = int(xn[0])
    while True: 
        while True: 
            for i in range(len(data)):
                if data[i] != b:
                    continue
                else:
                    b += 1
                    break 
            else:
                data_2.append(b)
                break 

        if len(data_2) == 2: 
            break 


    
    if abs(x-a) <= abs(b-x):
        print(a)
    else:
        print(b)

Solution (Python):
xn = input().split()
data_2 = []
x = int(xn[0]) 

if int(xn[1]) == 0:
    print(x)
else:
    data_str = input().split()
    data = [int(s) for s in data_str] 
    data.sort() 
    
    a = int(xn[0])
    
    while True: 
        while True: 
            for i in range(len(data)):
                if data[i] != a:
                    continue
                else:
                    a -= 1
                    break 
            else:
                data_2.append(a)
                break 

        if len(data_2) == 1: 
            break 


    
    b = int(xn[0])
    while True: 
        while True: 
            for i in range(len(data)):
                if data[i] != b:
                    continue
                else:
                    b += 1
                    break 
            else:
                data_2.append(b)
                break 

        if len(data_2) == 2: 
            break 


    
    if abs(x-a) <= abs(b-x):
        print(a)
    else:
        print(b)

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

    ans = 0
    for i in range(102):
        if i in p:
            continue
        if abs(x - ans) > abs(x - i):
            ans = i
    print(ans)

if __name__ == "__main__":
    resolve()

Solution (Python):
xn=input().split()
x=int(xn[0])

data=input().split()
for i in range(100):
    for d in data:
        if int(d) == x-i:
            break
    else:
        print(x-i)
        break
    
    for d in data:
        if int(d) == x+i:
            break
    else:
        print(x+i)
        break

Solution (Python):
def forbidden_list():
    
    X, N = map(int, input().split())
    P = list(map(int, input().split()))
    
    min_abs_list = list()
    
    if N == 0:
        return X
    
    i = 0
    while True:
        if X + i in P:
            i += 1
        else:
            min_abs_list.append(X + i)
            break
    
    i = 0
    while True:
        if X + i in P:
            i -= 1
        else:
            min_abs_list.append(X + i)
            break
    
    if abs(X - min_abs_list[0]) > abs(X - min_abs_list[1]):
        return min_abs_list[1]
    elif abs(X - min_abs_list[0]) == abs(X - min_abs_list[1]):
        return min(min_abs_list)
    elif abs(X - min_abs_list[0]) < abs(X - min_abs_list[1]):
        return min_abs_list[0]

result = forbidden_list()
print(result)

Solution (Python):






















































global FLAG_LOG
FLAG_LOG = False


def log(value):
    
    FLAG_LOG = False
    if FLAG_LOG:
        print(str(value))


def calculation(lines):
    
    
    X, N = list(map(int, lines[0].split()))
    if N == 0:
        return [X]
    else:
        values = list(map(int, lines[1].split()))
    
    
    
    
    
    
    

    mi = min(values)
    ma = max(values)

    distance = None
    
    for i in range(mi-1, ma+2):
        if i not in values:
            tmp = abs(X-i)
            if distance is None:
                result = i
                distance = tmp
            elif distance > tmp:
                result = i
                distance = tmp

    return [result]



def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines



def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['6 5', '4 7 10 6 5']
        lines_export = [8]
    if pattern == 2:
        lines_input = ['10 5', ' 4 7 10 6 5']
        lines_export = [9]
    if pattern == 3:
        lines_input = ['100 0', '']
        lines_export = [100]
    return lines_input, lines_export



def get_mode():
    import sys
    args = sys.argv
    global FLAG_LOG
    if len(args) == 1:
        mode = 0
        FLAG_LOG = False
    else:
        mode = int(args[1])
        FLAG_LOG = True
    return mode



def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(2)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    
    
    
    
    
    
    
    
    
    
    



if __name__ == '__main__':
    main()

Solution (Python):
X, N = map(int, input().split())
P = list(map(int, input().split()))
Q = [i for i in range(-150, 150)]
P = list(set(Q) - set(P))
P.sort()
dif = 100
for p in P:
    if abs(X-p) < dif:
        dif = abs(X-p)
        ans = p
print(ans)

Solution (Python):
from collections import defaultdict

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

exist_P = defaultdict(int)

for p in P:
    exist_P[p] = 1

diff = X + 1
ans = -1
for i in range(0, 102):
    if exist_P[i] == 0:
        if abs(X - i) < diff:
            ans = i
            diff = abs(X - i)
print(ans)

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

p.sort()

arr = [False] * 102

for i in range(len(p)):
    arr[p[i]] = True

dist = 10*10

ans = -99

search = list(range(-100,102))
search.reverse()

for i in search:
    if arr[i] == False:
        dist = min(abs(x - i), dist)
        if dist == abs(x - i):
            ans = i
print(ans)

Solution (Python):
X,N=map(int,input().split())
if N==0:
  print(X)
else:
  p=set(map(int,input().split()))
  for i in range(N+1):
    if X-i not in p:
      print(X-i)
      break
    elif X+i not in p:
      print(X+i)
      break

Solution (Python):
import bisect
X, N = map(int, input().split())
P = list(map(int, input().split()))
R = []
for i in range(105):
    R.append(i)
for p in P:
    R.remove(p)
a = bisect.bisect_right(R, X)
if X - R[a - 1] > R[a] - X:
    print(R[a])
else:
    print(R[a-1])

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

p = list(map(int, input().split()))
tmp = 10**9
ans = 0
for i in range(-1, 102):
    if i not in p:
        if tmp > abs(i-X):
            ans = i
            tmp = abs(i-X)
print(ans)

Solution (Python):
import bisect,collections,copy,heapq,itertools,math,string
import numpy as np
import sys
sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
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 = LI()
_p = LI()





p = set(_p)
for i in range(100):
    if X - i not in p:
        print(X - i)
        exit()
    if X + i not in p:
        print(X + i)
        exit()

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

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

diff = 10000
candidate = -100000
for i in range(-101, 102):
    if abs(i - x) < diff and i not in set(A):
        diff = abs(i - x)
        candidate = i
print(candidate)

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

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

print(ans)

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



list2 = sorted(p)

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

Solution (Python):


from typing import *
import itertools
import math
import sys

INF = float('inf')


def solve(X: int, N: int, p: "List[int]"):
    return min(set(p) ^ set(range(0, 101 + 1)), key=lambda v: abs(v-X))


def main():

    sys.setrecursionlimit(10 ** 6)

    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)]  
    print(solve(X, N, p))


if __name__ == '__main__':
    main()

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

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

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

ans = 101
i = 101

while i != -1:
    a = 0
    for j in range(0,N):
        if i == p[j]:
            a = 1
    if a == 0 and abs(i-X) <= abs(ans-X):
        ans = i
    i -= 1

print(ans)

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

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

  for i in range(100):
    if x-i not in a:
      ans=x-i
      break
    elif x+i not in a:
      ans=x+i
      break
    
  print(ans)

Solution (Python):
x, n = map(int, input().split())
p = list(map(int, input().split()))
ans = 0
xhigh=0
xlow=0
if n==0:
    ans = x
else:
    if x not in p:
        ans=x
    else:
        xhigh=x+1
        xlow=x-1
        while xhigh in p and xlow in p:
            xhigh +=1
            xlow -=1
        else:
            if xlow in p:
                ans =xhigh
            else:
                ans = xlow
print(ans)

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

P = set(P)

diff = float('INF')
ans = None
for i in range(0, 102):
    if i in P:
        continue
    d = abs(X - i)
    if d < diff:
        diff = d
        ans = i

print(ans)

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

P = set(P)

diff = float('INF')
ans = None
for i in range(-100, 102):
    if i in P:
        continue
    d = abs(X - i)
    if d < diff:
        diff = d
        ans = i

print(ans)

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

x = xn[0]
n = xn[1]

kMax = int(n/2)
bl = False
for k in range(kMax+1):
     if (x - k) not in P:
         ans = x - k
         bl = True
         break
     elif (x + k) not in P:
         ans = x + k
         bl = True
         break

if not bl:
    ans = x - (kMax + 1)     

print(ans)

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

P = set(P)

diff = float('INF')
ans = None
for i in range(-100, 300):
    if i in P:
        continue
    d = abs(X - i)
    if d < diff:
        diff = d
        ans = i

print(ans)

Solution (Python):
import sys
X,N=map(int, sys.stdin.readline().split())
P=map(int, sys.stdin.readline().split())
L=[ 0 for _ in range(102) ]
for p in P:
    L[p]=1

d=float("inf")
ans=None
for i,x in enumerate(L):
    if x==0:
        if abs(X-i)<d:
            d=abs(X-i)
            ans=i
print ans