Problem:
 Score : 300 points    Problem Statement Given are an integer X and an integer sequence of length N : p_1, \ldots, p_N .  Among the integers not contained in the sequence p_1, \ldots, p_N (not necessarily positive), find the integer nearest to X , that is, find the integer whose absolute difference with X is the minimum. If there are multiple such integers, report the smallest such integer.      Constraints  1 \leq X \leq 100  0 \leq N \leq 100  1 \leq p_i \leq 100  p_1, \ldots, p_N are all distinct.  All values in input are integers.         Input Input is given from Standard Input in the following format:  X  N  p_1  ...  p_N       Output Print the answer.        Sample Input 1 6 5
4 7 10 6 5      Sample Output 1 8  Among the integers not contained in the sequence 4, 7, 10, 6, 5 , the one nearest to 6 is 8 .       Sample Input 2 10 5
4 7 10 6 5      Sample Output 2 9  Among the integers not contained in the sequence 4, 7, 10, 6, 5 , the ones nearest to 10 are 9 and 11 . We should print the smaller one, 9 .       Sample Input 3 100 0      Sample Output 3 100  When N = 0 , the second line in the input will be empty. Also, as seen here, X itself can be the answer.

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

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

p.sort()

if x not in p:
    print(x)
    exit()
    
for i in range(len(p)):
    
    if p[i] == x:
        index = i
        break

right = x + 1
for i in p[index + 1:]:
    if i != right:
        break
    right += 1

left = x - 1
for i in reversed(p[:index]):
    if i != left:
        break
    left -= 1

if x - left <= right - x:
    print(left)
else:
    print(right)

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

Solution (Python):
x,n= map(int,input().split())
u = 100
num_str=input().split()
s=list(map(int, num_str))
m  = list(range(-100,200)) 
for k in s:
    m.remove(k)
for l in m:
    a = l - x
    if abs(u) > abs(a):
        u = a
print(u+x)

Solution (Python):
s = {i+1 for i in range(-101,101)}

x, n =map(int,input().split())
 
if n == 0:
  print(x)
  exit()
  
il = list(map(int,input().split()))
 
for i in range(n):
  s.discard(il[i])
s = list(s)
s.sort()

 
absmin = 10000000
ans = 0
 
for i in range(len(s)):
  j = abs(x-int(s[i]))
  if j < absmin:
    ans = s[i]
    absmin = j
    if j == 0:
      break
 
print(ans)

Solution (Python):

X,N = map(int,input().split())
p = list(map(int,input().split()))
r = 101
for i in range(101,-1,-1):
    if i in p:
        pass
    else:
        if abs(r-X) >= abs(i-X):
            r = i
print(r)

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)
        exit()
    elif x+i not in p:
        print(x+i)
        exit()

Solution (Python):
first_input = input().split()
x = int(first_input[0])
n = int(first_input[1])
if n != 0:
    second_input = map(int, input().split())
    p_a = list(map(int, second_input))
else:
    second_input = input()

def create_full_array(minimum, maximum):
    full_list = []
    for i in range(minimum,maximum+1):
        full_list.append(int(i))
    return full_list

if n == 0:
    print(x)
elif x > max(p_a) + 1 or x < min(p_a):
    ans = x - 1
    print(ans)
elif x == max(p_a) + 1:
    ans = x + 1
    print(ans)
else:
    full_array = create_full_array(min(p_a), max(p_a))
    if x in p_a:
        target_list = list(set(p_a)^set(full_array))
        abs_key = {}
        if len(target_list) == 0:
            if abs(x - min(p_a)) <= abs(x - max(p_a)):
                print(min(p_a) - 1)
            else:
                print(max(p_a) + 1)
        else:
            for i in target_list:
                abs_key[i] = abs(x-i)
            minimum = min(abs_key.values())
            t_k = []
            t_v = []
            [t_k.append(k) for k, v in abs_key.items() if v == minimum]
            print(min(t_k))

    else:
        print(x)

Solution (Python):
num_input = [input() for i in range(2)]
x = int(num_input[0].split()[0])
n = int(num_input[0].split()[1])

num_list = [int(n) for n in num_input[1].split()]
num_list.sort()

ans=x

if n!=0 and n!=1 and n!=100:
    if x in num_list:
        index=num_list.index(x)

        value_left=x-1
        value_right=x+1

        if index!=0:
            index_left=index-1
        if index!=n-1:
            index_right=index+1
        
        if index==0:
            ans=x-1
        elif index==n-1:
            if num_list[index-1]==x-1:
                ans=x+1
            else:
                ans=x-1
        else:
            for i in range(n):
                if num_list[index_left]!=value_left:
                    ans=value_left
                    break
                elif num_list[index_right]!=value_right:
                    ans=value_right
                    break
                if index_left!=0:
                    index_left=index_left-1
                if index_right!=n:
                    index_right=index_right+1
                value_left=value_left-1
                value_right=value_right+1

if n==1:
    ans=x-1

if n==100:
    if x<=50:
        ans=0
    if x>50:
        ans=101

print(ans)

Solution (Python):
def resolve():
    x, n = map(int, input().split())
    if n == 0:
        print(x)
        return
    else:
        p = [int(i) for i in input().split()]

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

resolve()

Solution (Python):
import sys

x, n = map(int, input().split())
p = list(map(int, input().split()))
list_p = [i for i in range(-1, 102)] 
t = x
num = x

for i in p:
  list_p[i + 1] = -2

for i in range(len(list_p)):
  if(list_p[i] == -2):
    continue
  else:
    if(abs(list_p[i] - x) <= t):
      if(abs(list_p[i] - x) < t):
        t = abs(list_p[i] - x)
        num = list_p[i]
      elif(abs(list_p[i] - x) == t):
        t = abs(list_p[i] - x)
        num = min(num, list_p[i])
print(num)

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


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

r=0
while True:
  if X-r not in p:
    print(X-r)
    exit()
  elif X+r not in p:
    print(X+r)
    exit()
  else:
    r+=1

Solution (Python):


import sys
import pprint

sys.setrecursionlimit(10 ** 6)

class Logger:
	def __init__(self, debug):
		self.debug = debug
	def print(self, *args):
		if self.debug:
			pprint.pprint(args)


def main():
	log = Logger(0)
	x, n = map(int, sys.stdin.readline().split())
	p = list(map(int, sys.stdin.readline().split()))
	p.sort()
	i = x - 1
	lower = 0
	while i >= 0:
		if not i+1 in p:
			lower = i+1
			break
		i -= 1
	i = x - 1
	upper = 101
	while i <= 101:
		if not i+1 in p:
			upper = i+1
			break
		i += 1
	if abs(x - lower) == abs(x - upper):
		print(lower)
	elif abs(x - lower) < abs(x - upper):
		print(lower)
	else:
		print(upper)

main()

Solution (Python):
x, n = map(int, input().split())
p = list(map(int, input().split()))
ans = []
sortlist = []
if n == 0:
    print(x)
else:
    p.sort()
    p1 = p[0]
    pn = p[n-1]
    new = [i for i in range(0, 102)]
    nolist = set(new) ^ set(p)
    nolist = list(nolist)

    for i in range(0, len(nolist)):
        d = abs(nolist[i] - x)
        sortlist.append(d)

        k = sortlist.index(min(sortlist))
    print(nolist[k])

Solution (Python):

import sys
import numpy as np


def solve(X: int, N: int, p: "List[int]"):
    ii = [i for i in range(102)]
    iii = sorted(list(set(ii) - set(p)))
    idx = np.abs(np.asarray(iii) - X).argmin()
    print(iii[idx])
    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):
import sys
x, n = list(map(int, input().split()))
p = list(map(int, input().split()))

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

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):
x,n=map(int,input().split())
p=list(map(int,input().split()))
l=r=x
while 1:
  if l not in p: print(l); break
  l-=1
  if r not in p: print(r); break
  r+=1

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


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

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

for a in range(110):
    if not((x-a) in p):
        print(x-a)
        exit()
    if not((x+a) in p):
        print(x+a)
        exit()

Solution (Python):
import sys

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

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

l = list(range(0, 102))
for p in P:
    l.pop(l.index(p))

dis_min = 1000
n = 1000
for i in l:
    dis = abs(i - X)
    if dis_min > dis:
        dis_min = dis
        n = i
    elif dis_min == dis:
        if n > i:
            n = i

print(n)

Solution (Python):
x,n,*p=map(int,open(0).read().split())
l=r=x
while 1:
  if l not in p: print(l); break
  l-=1
  if r not in p: print(r); break
  r+=1

Solution (Python):
X,N=[int(x) for x in input().strip().split(" ")]
P=list(map(int,input().split()))
f=0
if len(P)==0:
    print(X)
else:
    for i in range(int(N/2)+2):
        if X-i not in P:
            print(X-i)
            f=1
        elif X+i not in P:
            print(X+i)
            f=1
        if f==1:
            break

Solution (Python):
x,n = map(int,input().split())
p = list(map(int,input().split()))
tmp = []
for i in range(-101,102):
    tmp.append(i)

if n == 0:
    print(x)
else:
    for i in p:
        tmp.remove(i)
    
    ans = []
    for i in tmp:
        a = abs(x-i)
        ans.append(a)
 
    b = min(ans)
    
    c = x+b
    d = x-b
 
    if c and d in tmp:
        print(d)
    elif c in tmp:
        print(c)
    elif d in tmp:
        print(d)

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

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 = (int(i) for i in input().split())
p_vals = [int(i) for i in input().split()]

Xp = Xn = X

while True:
    if Xn not in p_vals:
        print(Xn)
        break
    if Xp not in p_vals:
        print(Xp)
        break
    Xp += 1
    Xn -= 1

Solution (Python):
import sys

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

a = []
b = []

for i in range(0, 102):
    if i not in p:
        a.append((x - i)**2)
        b.append(i)
ans = min(a)
bb = a.index(ans)
print(b[bb])

Solution (Python):
X,N=[int(x) for x in input().strip().split(" ")]
P=list(map(int,input().split()))
f=0
if len(P)==0:
    print(X)
else:
    for i in range(int(N/2)+2):
        if X-i not in P:
            print(X-i)
            f=1
        elif X+i not in P:
            print(X+i)
            f=1
        if f==1:
            break

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

p = set(map(int, readline().split()))

ans = x
tmp = 300
for i in reversed(range(-1, 102)):
    if i not in p:
        if tmp >= abs(x - i):
            tmp = 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()))
    abs_list = []
    re_list = []
    min = 1000
    min_index = 0

    for i in range(250):
        abs_list.append(-100+i)
    for j in p:
        abs_list.remove(j)
    for i in range(len(abs_list)):

        re_list.append(abs(abs_list[i] - X))
    for i in range(len(re_list)):
        if min > re_list[i]:
            min = re_list[i]
            min_index = i
    if re_list[min_index] > X:
        print(0)
    else:
        print(abs_list[min_index])

Solution (Python):
import numpy as np
 
X,N = map(int,input().split())
p = input()
 
if N != 0:
    
    p_list = [int(n) for n in p.split()]
    
    X_near = np.array(list(range(int(np.ceil(X - N/2 - 1)), int(np.floor(X + N/2)) + 2)))
 
    remain_list = []
 
    for i in X_near:
        if i not in p_list:
            remain_list.append(i)
        
 
    remain_array = np.array(remain_list)
    min_bool = np.abs(X - remain_array).min() == np.abs(X - remain_array)
    print(remain_array[min_bool].min())
    
if N == 0:
    print(X)

Solution (Python):

x, n = map(int, input().split())
seisulist = list(map(int, input().split()))
numlist = [i for i in range(0,102) if i not in seisulist]
xretu = [x]*len(numlist)
hikizan = [abs(s-t) for (s, t) in zip(numlist, xretu)]
sa = min(hikizan)
if x-sa not in seisulist:
    print(x-sa)
else:
    print(x+sa)

Solution (Python):
x, n = map(int, input().split())
 
p = list(map(int, input().split()))
p = sorted(p)
 
if n == 0:
    print(x)
    exit()
 
q = [i for i in range(0, 101+1)]
r = []
 
for i in q:
    if i not in p:
        r.append(i)

s = [abs(x-i) for i in r]
 
print(r[s.index(min(s))])

Solution (Python):
import numpy as np
x,n =map(int,input().split())

if  n==0:
 print(x)
else:
 P =list(map(int,input().split()))
 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 = map(int, input().split())

d = 100
pa = 0
px = range(102)
py = list(set(px) - set(p))

for i in py:

    if d > abs(i - x):
        pa = i
        d = abs(i - x)
    elif d == abs(i - x):
        if i < pa:
            pa = i

print(pa)

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

if N==0:
  print(X)

else:
  P = list(map(int,input().split()))
  if X not in P:
    print(X)
  
  else:
      a = X+1
      b = X-1
      
      while a in P:
        a+=1
      while b in P:
        b-=1
      
      if abs(X-a)<abs(X-b):
        print(a)
      else:
        print(b)

Solution (Python):
X, N = map(int, input().split())
P = list(map(int, input().split()))
 
ans = X
for i in range(N+1):
    a = X + i
    b = X - i
    if a not in P:
        ans = a
        if b not in P:
            ans = b
        break
    if b not in P:
        ans = b
        break
print(ans)

Solution (Python):
x, n = map(int, input().split())
if n==0:
    print(x)
if n > 0:
    P = list(map(int, input().split()))
    for i in range(0,102):
        if x-i not in P or x+i not in P:
            if x-i not in P:
                print(x-i)
                exit(0)
            if x+i not in P:
                print(x+i)
                exit(0)

Solution (Python):
X, N = map(int,input().split())
P = list(map(int,input().split()))
P.sort()
diff = 10**10
for p in range(102):
    if p in P:
        continue
    if abs(X-p) < diff:
        diff = abs(X-p)
        ans = p
print (ans)

Solution (Python):
FAST_IO = 0
if FAST_IO:
    import io, sys, atexit
    read = iter(sys.stdin.read().splitlines()).next
    sys.stdout = _OUTPUT_BUFFER = io.BytesIO()
    @atexit.register
    def write():
        sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
else:
    read = raw_input
readint = lambda: int(rr())
readlist = lambda: map(int, read().split())


def solve((X, N), A):
    Aset = set(A)
    ans = 1234
    for p in range(102):
        if p not in Aset:
            d = abs(p - X)
            if d < ans:
                ans = d
                ansi = p
    return ansi

print solve(readlist(), readlist())

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

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

best = (10 ** 18, 0)

for i in range(102):
	if i not in P:
		best = min(best, (abs(X - i), i))

print(best[1])

Solution (Python):

from sys import stdin
from operator import itemgetter
from collections import deque, Counter
import math
import pprint
from functools import reduce


MOD = 1000000007
INF = float('inf')

def keta(kazu):
    kazu_str = str(kazu)
    kazu_list = [int(kazu_str[i]) for i in range(0, len(kazu_str))]
    return kazu_list

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def combination(m,n):
    
    if n > m:
        return 'すまん'
    return math.factorial(m) // (math.factorial(m-n) * math.factorial(n))

def pow_k(x,n):  
    if n == 0:
        return 1
    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2
    return K * x
    
def main():
    x,n = [int(x) for x in stdin.readline().rstrip().split()]
    
    if n == 0:
        print(x)
    else:
        table = [i - 1 for i in range(103)]

        target = INF
        p = list(map(int,[int(x) for x in stdin.readline().rstrip().split()]))
        for i in range(len(p)):
            table.remove(p[i])
        for i in range(len(table)):
            target = min(target,abs(x-table[i]))
        ans_a = x-int(target)
        ans_b = x+int(target)
        if ans_a in table:
            print(ans_a)
        else:
            print(ans_b)
        
main()

Solution (Python):
X, N = map(int, input().split())
if N == 0:
    print(X)
elif N == 100:
    if X <= 50:
        print(0)
    else:
        print(101)

else:
    p = list(map(int, input().split()))
    abs_list = []
    re_list = []
    min = 1000
    min_index = 0

    for i in range(250):
        abs_list.append(-100+i)
    for j in p:
        abs_list.remove(j)
    for i in range(len(abs_list)):

        re_list.append(abs(abs_list[i] - X))
    for i in range(len(re_list)):
        if min > re_list[i]:
            min = re_list[i]
            min_index = i
    if re_list[min_index] > X:
        print(0)
    else:
        print(abs_list[min_index])

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

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

diff = 1000
ans = x
for i in range(-300, 300):
    xx = x + i
    if abs(i) < diff and xx not in p:
        ans = xx
        diff = abs(i)

print(ans)

Solution (Python):


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

P2 = []

for i in range(0, 102):
    if i in P:
        continue
    P2.append(i)
sa = 10**9
ret = -1
for p in P2:
    if abs(X-p) < sa:
        sa = abs(X-p)
        ret = p

print(ret)

Solution (Python):
tmp = list(map(int, input().split()))
x = tmp[0]
n = tmp[1]
if n == 0:
    print(x)
    exit()

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):
x,n,*p=map(int,open(0).read().split())
p=set(p)
l=r=x
while 1:
  if l not in p: print(l); break
  l-=1
  if r not in p: print(r); break
  r+=1

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

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

s = 1000000000

for i in range(-100,102):
    if i in p:
        continue
    s = min(abs(x-i),s)
    

if not x-s in p:
    print(x - s)
else:
    print(x + s)

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

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

f = [1]*200
sa = x
ans = 0

for i in p:
    f[i-1] = 0

for i in range(200):
    if f[i] == 1 and sa > abs(i+1-x):
        sa = abs(i+1-x)
        ans = i+1

print(ans)

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

Solution (Python):
X, N = map(int, input().split())
P = list(map(int, input().split()))
 
ans = X
for i in range(101):
    a = X + i
    b = X - i
    if a not in P:
        ans = a
        if b not in P:
            ans = b
        break
    if b not in P:
        ans = b
        break
print(ans)

Solution (Python):
X, N = map(int, input().split())
if N == 0:
    print(X)
else:
    P = list(map(int, input().split()))
    for i in range(1000):
        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()
else:
    P = list(map(int,input().split()))
L = [i for i in range(0,102) if i not in P]

if X in L:
    ANS = X
else:
    L.append(X)
    L = sorted(L)
    n = L.index(X)
    if (L[n+1]-L[n] < L[n] - L[n-1]):
        ANS = L[n+1]
    else:
        ANS = L[n - 1]

print(ANS)

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

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

    p_under = list(filter(lambda v: v<=x, p))
    p_upper = list(filter(lambda v: v>=x, p))
    p_under.sort(reverse=True)
    p_upper.sort()

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

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

for _ in range(300):
    if X - dif not in P:
        print(X - dif)
        exit()
    elif X + dif not in P:
        print(X + dif)
        exit()

    else:
        dif += 1

Solution (Python):
import sys
x,n = map(int, input().split())
if n == 0:
  print(x)
  sys.exit()
else:
  p = input().split()
  p1 = [int(i) for i in p]
  if x not in p1:
    print(x)
  else:
    for c in range(1,n+1):
      u = x + c
      d = x - c
      if d not in p1:
        print(d)
        sys.exit()
      elif u not in p1:
        print(u)
        sys.exit()

Solution (Python):

def nears_impl(x, dis, is_minus):
    def cal(x, dis):
        if is_minus:
            r = x - dis
            return r
        else:
            r = x + dis
            return r

    res = cal(x, dis)
    return res


def nears(start_x):
    yield start_x
    i = 1
    while True:
        yield nears_impl(start_x, i, True)
        yield nears_impl(start_x, i, False)
        i += 1


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

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

for near in nears(x):
    if near not in p:
        print(near)
        break

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

if X in L:
    ANS = X
else:
    L.append(X)
    L = sorted(L)
    n = L.index(X)
    l = len(L) - 1


    if (0 < n < l):
        if (L[n+1]-L[n] < L[n] - L[n-1]):
            ANS = L[n+1]
        else:
            ANS = L[n - 1]
    elif (n == l):
        ANS = L[l - 1]

print(ANS)

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

D = 10000
res = 0
for i in range(-100,200):
  if i in P:
    continue
  X2 = abs(X-i)
  if X2 < D:
    D = X2
    res = i

print(res)

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

if X not in nums:
  print(X)
  exit(0)

diff_dict = {}
for n in nums:
  diff = abs(X - n)
  if diff in diff_dict.keys():
    diff_dict[diff].append(n)
  else:
    diff_dict[diff] = [n]

keys = list(diff_dict.keys())
keys.sort()

for i in range(1, max(keys)+2):
  if i not in keys:
    print(X - i)
    break
  else:
    targets = diff_dict[i]
    length = len(targets)
    if length > 1:
      continue
    else:
      t = targets[0]
      print(X - i if t > X else X + i)
      break

Solution (Python):
import sys
L = []
for l in sys.stdin:
    L.append(l)
X, N = map(int, L[0].split())
p_N_list = map(int, L[1].split())

def calc_sub(n):
    return n - X

sub =  map(calc_sub, p_N_list)
abs_sort = sorted(sub, key=abs)

num = 0
check = 1
while(check):
  if (- num) not in abs_sort:
    print(X - num)
    check = 0
  elif num not in abs_sort:
    print(X + num)
    check = 0
  else:
    num += 1

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

for i in range(0,101):
    if (X-i in p) == False: 
        print(X-i)
        break
    elif (X+i in p) == False: 
        print(X+i)
        break

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

if X not in p:
    print(X)
else:
    for i in range(1, 101):
        if X - i not in p:
            print(X - i)
            exit()
        elif X + i not in p:
            print(X + i)
            exit()

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

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

for i in range(-10, 200):
    if i not in p:
        q.append(i)

ans = 1000000

for i in q:
    if abs(x - ans) > abs(x - i):
        ans = i
    elif abs(x - ans) == abs(x - i):
        if i < ans:
            ans = i

print(ans)

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




else:
    lst=list(map(int,input().split()))[:n]
    for j in range(1,100000):
        x1=abs(abs(x)+abs(j))
        x2=abs(abs(x)-abs(j))
        if x not in lst:
            print(x)
            break
        if x2 not in lst:
            print(x2)
            break
        elif x1 not in lst:
            print(x1)
            break
        else:
            continue

Solution (Python):
X, N = map(int, input().split())
P=list(map(int, input().split()))
A=[]
A.append(X)
if N==0:
   print(X)
else:
   for i in range(N+1):
      A.append(X+(1+(i//2))*(-1)**(i+1))
   for i in range(N+1):
      if A[i] not in P:
         ans=A[i]
         print(ans)
         break

Solution (Python):
[X, N] = list(map(int, input().split()))
A = []
try:
  P = list(map(int, input().split()))
  list_int = [x for x in range(0, 102)]
  list_int_d = list(set(list_int) - set(P))
  list_int_d.sort()
  for i in list_int_d:
    A.append(abs(X - i))
  if 0 in A:
    print(X)
  else:
    Index = A.index(min(A))
    print(list_int_d[Index])
except EOFError:
  print(X)

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

S=[i for i in range(-1,102)]

for j in range(N):
    S.remove(A[j])
    
n=1000  
x=0
for k in S:
    if abs(k - X) < n:
        n=abs(k - X)
        x=k
    elif n == abs(k - X):
        x=min(x,k)
print(x)

Solution (Python):
x,n = map(int, input().split())
if n==0:
  print(x)
else:
  p = list(map(int, input().split()))
  p.append(0)
  while True:
    if p[n]%2==1:
      s = x-((p[n]+1)/2)
      
    else:
      s = x+(p[n]/2)
      
    if s not in p:
      print(int(s))
      break
    else:
      p[n]+=1

Solution (Python):
a,b= map(int,input().split())
N = list(map(int,input().split()))
S =[]
key = 0
while(1):
	if a-key in N:
		if a +key in N:
			key +=1
		else:
			print(a+key)
			break
		
	else:
		print(a-key)
		break

Solution (Python):
x, n = map(int,input().split())
if n != 0:
  p = list(map(int,input().split()))
p_change = []
m = 0
if n == 0:
  print(x)
else:
    for i in p:
        p_change.append(abs(i-x))
 
    if x in p:
        for i in range(n+1):
            if i != 0 and p_change.count(i) != 2:
                m = i
                break
        if x-m in p:
            print(x+m)
        else:
            print(x-m)
    else:
        print(x)

Solution (Python):
X,N=map(int,input().split())
if N==0: print(X)
else:
    p=list(map(int,input().split()))
    m=10000
    ans=N
    for i in range(-101,101):
        if m>abs((i+1)-X) and not i+1 in p:
            m=abs((i+1)-X)
            ans=i+1
    print(ans)

Solution (Python):
import math
def main():
    x, n = map(int, input().split())
    if n==0:
        out = x
    else:
        p_l = [int(_) for _ in input().split()]

        c_l = []
        for i in range(-101, 105):
            c_l.append(i)
        
        for p in p_l:
            if p in c_l:
                c_l[c_l.index(p)]=1000
        
        abs_c_l = []
        for i in range(-101, 105):
            abs_c_l.append(i)

        for i, c in enumerate(c_l):
            abs_c_l[i] = abs(c_l[i] - x)
        
        m = min(abs_c_l)
        out = c_l[abs_c_l.index(m)]
        
    print(out)

main()

Solution (Python):
X, Y = map(int, input().split())
if Y == 0:
    answer = X
else:
    list_1 = list(map(int, input().split()))

    mylist = list(range(-100, 200))

    list_2 = list(filter(lambda x: x not in list_1, mylist))
    
    list_3 = list(map(lambda x: x - X, list_2))

    import numpy as np

    abslist = np.abs(list_3)

    min_num = min(abslist)

    answer_lisbef = [X - min_num, X + min_num]
    
    answer_lisaf = list(filter(lambda x: x not in list_1, answer_lisbef))
    
    answer = min(answer_lisaf)
print(answer)

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

n = X
i = 1

while 1 <= i:
    if n in p:
        if i % 2 == 0:
            n += i
        else:
            n -= i   
    else:
        print(n)
        break
    i += 1

Solution (Python):
x,n,*p=map(int,open(0).read().split())
if n==0:
    print(x)
else:
    q=[i for i in range(102) if not(i in p)]
    m=[]
    for j in q:
        m.append(abs(j-x))
    a,b=x-min(m),x+min(m)
    if a in q:
        print(a)
    else:
        print(b)

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

Solution (Python):

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

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

i = 0            
while True:
    a = x - i
    b = x +i
    if not a in num_list:
        min_num = a
        break
    elif not b in num_list:
        min_num = b
        break
    else:
        i += 1
            
print(min_num)

Solution (Python):
X,N=list(map(int,input().split()))
if N>0:p=list(map(int,input().split()))
else:p=[]
memo=[False for i in range(105)]
for i in range(N):memo[p[i]]=True


riget=X+1
left=X-1
ans_r=0
ans_l=0

while(True):
    if memo[X]==False:
        ans_r=X
        break
    
    if memo[riget]==False:
        ans_r=riget
        break
    riget+=1
    
while(True):
    
    if memo[X]==False:
        ans_l=X
        break
    
    if memo[left]==False:
        ans_l=left
        break
    left-=1
    
if N==0:print(X)
elif abs(X-ans_r)>=abs(X-ans_l):print(ans_l)
else:print(ans_r)

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

cand = []
for i in range(102):
    if i in p:
        continue
    else:
        cand.append(abs(i-x))
q = min(cand)
print(x-q if x-q not in p else x+q)

Solution (Python):
X, N = map(int, input().split())
try:
  list_  = list(map(int, input().split()))
except:
  print(X)

else:
    for i in range(0, 101):
        if not (X-i) in list_:
            print(X-i)
            break
        
        elif not(X+i) in list_:
            print(X+i)
            break