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())
if n != 0:
    p = list(map(int, input().split()))
    flag = False
    for i in range(100):
        for j in range(n):
            if p[j] == x - i:
                break
            if j == n-1:
                print(x - i)
                flag = True
                break
        if flag:
            break
        for h in range(n):
            if p[h] == x + i:
                break
            if h == n-1:
                print(x + i)
                flag = True
                break
        if flag:
            break
else:
    print(x)

Solution (Python):
X, N = list(map(int, input().strip().split()))
l = list(map(int, input().strip().split()))
l = sorted(l, reverse = False)

rslt = 200


if N == 0: rslt = X
if N != 0:
  if l[0] > X: rslt = X
  elif l[-1] < X: rslt = X
  elif (l[0]<=X) and (l[-1]>=X):
    e_min = int(l[0]-1)
    e_max = int(l[-1]+1)
    e_l = [i for i in range(e_min, e_max+1) if i not in l]
    for n in e_l[::-1]:
      if abs(X-n) <= abs(X - rslt): rslt = n
  
print(rslt)

Solution (Python):
x, n = map(int, input().split())
p = set(map(int, input().split()))
l = set(range(102))
l = l - p
a = list(l)
a = sorted(a, reverse=True)
t = 101; ans=-1
for i in a:
    if(t >= abs(x-i)):
        t = abs(x-i)
        ans = i
print(ans)

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

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

dif = 100
ans = 0

for i in range(min(p) - 1, max(p) + 2):
    if not (i in p):
        if dif > abs(x - i):
            dif = abs(x - i)
            ans = i

print(ans)

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



X,N= map(int,input().split())
p= list(map(int,input().split()))
A= list(range(-200,200))

for i in range(N):
    A.remove(p[i])

D = 201
ans = -100
for j in range(len(A)):
    if D > abs(X - A[j]):
        D = abs(X - A[j])
        ans = A[j]

    else:
        pass
print(ans)

Solution (Python):
X,N = map(int,input().split())
if N != 0:
  num = list(map(int,input().split()))
  num.sort()
b = 1000
if N == 0:
  print(X)
else:
  for i in range(N):
    a = abs(int(num[i])-X)
    if a <= b:
      b = a
      ans = int(num[i]) - b
  low = ans
  high = ans
  while low in num:
    low -= 1
  
  while high in num:
    high += 1
  loo = abs(low-ans)
  hii = abs(high-ans)
  if loo > hii:
    print(high)
  else:
    print(low)

Solution (Python):


x,n = map(int, input().split())
if n > 0:
    p = list(map(int , input().split()))
else:
    p  = []
a = list(set(list(range(-100,102))) - set(p))
values = []
for i in a:
    values = values +  [[abs(x-i), i]]
values.sort(key=lambda x: x[0])
mins = values[0][0]
b = []
for i in values:
    if i[0] > mins:
        break
    b += [i[1]]
b.sort()
print(b[0])

Solution (Python):
n = input().split()
X = int(n[0])
N = int(n[1])

try:
    n2 = input()
except:
    pass

if N == 0:
    print(X)

else:
    n2 = n2.split()
    p = [int(item) for item in n2]

    for i in range(101):
        if i == 0:
            if X not in p:
                print(X)
                break
        tmp = []

        if (X + i not in p ):
            tmp.append(X + i)

        if (X - i not in p ):
            tmp.append(X - i)
    
        if len(tmp)!=0:
            print(min(tmp))
            break

Solution (Python):
X, N = map(int,input().split())
if N > 0:
  p = list(map(int, input().split()))
else:
  p=[]

p.sort()

ans_1 = X
ans_2 = X
for i in range(N) :
  pi = p[i]
  if pi == ans_1:
    ans_1 += 1

p.reverse()
for i in range(N) :
  pi = p[i]
  if pi == ans_2:
    ans_2 -= 1

ans = X
if abs(ans_1 - X) < abs(ans_2 - X):
  ans = ans_1
elif ans_1 - X == -abs(ans_2 - X):
  ans = ans_1
else:
  ans = ans_2
print(ans)

Solution (Python):
import sys

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

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

all_list = [int(x) for x in range(0, 102)]
target_list = sorted(list(set(list_p) ^ set(all_list)))

ans = [abs(num - X) for num in target_list]




print(target_list[ans.index(min(ans))])

Solution (Python):
x,n=map(int,input().split())
p=set([int(i) for i in input().split()])
low=x
high=x
if not x in p:
  print(x)
  exit()
while True:
  low-=1
  if not low in p:
    print(low)
    exit()
  high+=1
  if not high in p:
    print(high)
    exit()

Solution (Python):

x, n = map(int, input().split())
aa = 0
if n == 0:
   aa = 1
if aa == 0:
    p = list(map(int, input().split()))
    p.sort()
    i = 0
    flg = 0
    dis = []
    while flg == 0:
        if i > 100:
            flg = 1
        if i in p:
            dis.append(5000)
        else:
            dis.append(abs(x-i))
        i += 1
    for i in range(len(dis)):
        if dis[i] == min(dis):
            print(i)
            break
else:
    print(x)

Solution (Python):
a = list(map(int,input().split()))
x =a[0]
n =a[1]
if n==0:
  print(x)
else:
  p = list(map(int,input().split()))
  p.sort()
  out_p = []
  for i in range(p[n-1]-p[0]+1):
    if not i+p[0] in p:
      out_p.append(i+p[0])
  if min(p)>x or max(p)<x:
    print(x)
  else:
    re_p =[]
    for j in range(len(out_p)):
      re_p.append(abs(out_p[j]-x))
    if re_p:
      print(out_p[re_p.index(min(re_p))])
    else:
      if abs(max(p)-x)>=abs(min(p)-x):
        print(min(p)-1)
      else:
        print(max(p)+1)

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

for i in range(n):
    p[i] = int(p[i])

for i in range(100):
    min_flag = 0
    max_flag = 0
    for j in range(n):
        if p[j] != x - i:
            min_flag += 1
        if p[j] != x + i:
            max_flag += 1

    if min_flag == n:
        ans = x-i
        break
    elif max_flag == n:
        ans = x+i
        break

print(ans)

Solution (Python):


from queue import Queue
from queue import LifoQueue as Stack
from math import sqrt, floor, ceil, log2, log10, pi
from fractions import gcd
from itertools import permutations, combinations
from operator import itemgetter
from functools import cmp_to_key


INF=1001001001
__MOD__=(10**9)+7
yn = 'YNeos'
judge = False
cnt = 0
ans = None


def lcm(a, b):
    return (a*b) // gcd(a,b)

def intinput():
    return int(input())

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

def lineinputs(func=intinput):
    datas = []
    while True:
        try:
            datas.append(func())
        except EOFError:
            break
    return datas

class ModInt():
    def __init__(self, x):
        self.__x = (x % __MOD__)
    def __add__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x + other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x + other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __radd__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x + self.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x + self.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __sub__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x - other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x - other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __rsub__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x - self.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x - self.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __mul__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x * other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x * other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __rmul__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x * self.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x * self.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __truediv__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x * other.__modinv())%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x * other.__modinv())%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __rtruediv__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x * self.__modinv())%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x * self.__modinv())%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __pow__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__(pow(self.__x, other.__x, __MOD__)))
        elif type(other) == ModInt:
            return self.__class__(pow(self.__x, other.__x, __MOD__))
        else:
            raise Exception("Not Int or Not ModInt")
    def __rpow__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__(pow(other.__x, self.__x, __MOD__)))
        elif type(other) == ModInt:
            return self.__class__(pow(other.__x, self.__x, __MOD__))
        else:
            raise Exception("Not Int or Not ModInt")

    def __modinv(self, m=__MOD__):
        a = self.__x
        if a == 0:
            raise ZeroDivisionError()
        if gcd(a, m) != 1:
            raise Exception("%sの逆数は求まりません。" % a)
        b, u, v = m, 1, 0
        while b != 0:
            t = a//b;
            a -= t*b
            a, b = b, a
            u -= t * v
            u, v = v, u
        u %= m
        if u < 0:
            u += m
        return u
    def __int__(self):
        return self.__x
    def __str__(self):
        return str(self.__x)



if __name__ == '__main__':
    X, N = mulinputs()
    ps = set(mulinputs())

    
    
    
    
    
    
    
    
    
    
    
    
    

    
    
    
    
    
    

    if X not in ps:
        print(X)
        exit()
    for i in range(1,100):
        p1, p2 = X-i, X+i
        if p1 not in ps:
            print(X-i)
            exit()
        if p2 not in ps:
            print(X+i)
            exit()

Solution (Python):
def f(x, P):
    y = x
    z = x
    while y > 0 or z <= 100:
        if y not in P:
            return y
        y -= 1
        if z not in P:
            return z
        z += 1


x, N = map(int, input().split())
if N:
    P = list(map(int, input().split()))
    print(f(x, P))
else:
    print(x)

Solution (Python):
a = input().split(" ")
x = int(a[0])
if a[1] == "0":
    print(a[0])
else:
    b = input().split(" ")
    c = []
    for i in b:
        c.append(int(i))
    d = sorted(c)
    e = 0
    while True:
        y = x - e
        if d.count(y) == 0:
            print(x-e)
            break
        y = x + e
        if d.count(y) == 0:
            print(x+e)
            break
        e += 1

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
import bisect
import numpy as np
import math
from collections import deque
from collections import defaultdict
from math import gcd


def main():
    X, N = map(int, input().split())
    P = list(map(int, input().split()))
    P = np.array(P)
    
    P = np.sort(P)
    ind = bisect.bisect_right(P, X)

    if len(P) == 0 or P[ind-1] != X:
        return X
    
    if len(P) == 1:
        if P[0] != X:
            return X
        else:
            return X-1
    
    Left = P[:ind-1] - X
    Right = P[ind:] - X

    Left = abs(Left[::-1])

    diff = 1
    Left_over = False
    Right_over = False

    if len(Left) == 0:
        Left_over = True
    if len(Right) == 0:
        Right_over = True

    while True:
        if not Left_over and Left[0] != diff:
            return X - diff
        elif Left_over:
            return P[0] - 1
        elif not Right_over and Right[0] != diff:
            return X + diff
        elif Right_over:
            return P[-1] + 1
        diff += 1
        if len(Left) >= 2:
            Left = Left[1:]
        else:
            Left_over = True
        if len(Right) >= 2:
            Right = Right[1:]
        else:
            Right_over = True

        if Left_over and Right_over:
            return P[0]-1


print(main())

Solution (Python):
[X,N] = [int(i) for i in input().split()]
if N == 0:
  print(X)
else:
  PA = [int(i) for i in input().split()]
  if not X in PA:
    print(X)
  else:
    i = 1  
    while True:
      [m,p] = [X-i,X+i]
      if not m in PA:
        print(m)
        break
      elif not p in PA:
        print(p) 
        break
      i += 1

Solution (Python):
x, n = map(int, input().split())
p_list = [i for i in map(int, input().split())]
p_list.sort()
plus_count = 1
minus_count = -1
while True:
    m_p = x + minus_count in p_list
    p_p = x + plus_count in p_list
    if x not in p_list:
        print(x)
        break
    elif m_p is False:
        print(x + minus_count)
        break
    elif p_p is False:
        print(x + plus_count)
        break
    else:
        minus_count -= 1
        plus_count += 1

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

num = [0,101]
for i in range(100):
  num.append(i + 1)
num.sort()

if n == 0:
  ans = x
else:
  p = list(map(int, input().split()))
  if p.count(x) == 0:
    ans = x
  else:
    for i in range(n):
      num.remove(p[i])
    for i in range(len(num)):
      num[i] -= x
    
    max_m = -200
    for i in range(len(num)):
      if num[i] < 0 and max_m < num[i]:
        max_m = num[i]
    
    min_p = 200
    for i in range(len(num)):
      if num[i] > 0 and min_p > num[i]:
        min_p = num[i]
    
    if abs(min_p) < abs(max_m):
      ans = min_p
    else:
      ans = max_m
    ans += x
print(ans)

Solution (Python):
X, N = map(int, input().split())
p = list(map(int, input().split()))
ans = 10000
flg = 200
for i in range(X - 100, X + 101):
    if i in p:
        continue
    if flg > abs(X - i):
        flg = abs(X - i)
        ans = i
print(ans)

Solution (Python):
X , N = map(int,input().split())
if N == 0:
    print(X)
elif N == 1:
    P = int(input())
    if P == X:
        print(X - 1)
    elif X + 1 == P or X - P > 1:
        print(X - 1)
    else:
        print(X + 1)

else:
    P = list(map(int,input().split()))
    j = 1
    if X not in P:
        print(X)
    else:
        while True:
            
            if X - j not in P:
                print(X - j)
                break
            if X + j not in P:
                print(X + j)
                break
            j += 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
  if r not in p:
    print(r)
    break
  l-=1
  r+=1

Solution (Python):
from sys import stdin
import sys

MAX_N = 100;

X, N = [int(x) for x in stdin.readline().rstrip().split()]
if N==0:
  print(X)
  sys.exit()
p = [int(x) for x in stdin.readline().rstrip().split()]

for i in range(MAX_N//2+1):
  a=X-i
  if not a in p:
    print(a)
    break
  a=X+i
  if not a in p:
    print(a)
    break

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

Solution (Python):

import numpy as np
x,n=map(int,input().split())
ans=0
b_list=[]
if n==0:
    ans=x
else:
    p_list=list(map(int,input().split()))
    
    s=x-int(n/2)-1
    g=x+int(n/2)+1
    ans_list=[]
    for i in range(s,g+1):
        if i not in p_list:
            b_list.append(i)
    
    ans=b_list[0]
    for i in b_list[1:]:
        if abs(x-i)<abs(x-ans):
            ans=i
        else:  
            break

                
print(ans)

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

    p = list(map(int, input().split()))
    p.sort()
    i = 0  
    s_i = 0
    l_i = n
    while i < n:
        if p[i] == x: break
        elif p[i] > x: 
            print(x)
            return
        else: i += 1

    s_i = i-1
    l_i = i+1

    ans = 0
    diff = 1
    while True:
        if s_i < 0 or p[s_i] < x-diff:
            ans = x-diff
            break
        elif l_i >= n or p[l_i] > x+diff:
            ans = x+diff
            break
        else:
            s_i -= 1
            l_i += 1
            diff += 1

    print(ans)

resolve()

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

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

    p_set = set(p_list)
    new_list = []
    new_list.append(0)
    new_list.append(101)
    for i in range(1, 101):
        if i in p_set:
            pass
        else:
            new_list.append(i)



    min_x = 100 
    min_diff = 100
    for x in new_list:
        if abs(x - X) <= min_diff:
            if min_diff == abs(x - X):
                if x < min_x:
                    min_x = x
            else:
                min_x = x
                min_diff = abs(x - X)
            
        else:
            pass
    print(min_x)

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

ans = X
if N !=0:
  P = list(map(int,input().split()))
  ansR = X
  ansL = X
  while True:
    if ansR in P and ansL in P:
      ansR +=1
      ansL -=1
    else:
      ans = min(ansR,ansL)
      if ans in P:
        print(max(ansR,ansL))
        break
      else:
        print(ans)
        break
else:
  print(ans)

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

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

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

arr2 = []
arr3 = []

for i in range(-50, 110):
    if not i in arr:
        arr2.append(i)
        arr3.append(abs(x - i))

n2 = min([i for i, v in enumerate(arr3) if v == min(arr3)])
print(arr2[n2])

Solution (Python):
x, n = map(int, input().split())
if n != 0:
    p = set(map(int, input().split()))
    nums = set([])
    for i in range(0, 102):
        nums.add(i)
    rest = nums.difference(p)
    minVal = 1000
    for j in rest:
        if abs(x - j) < abs(x - minVal):
            minVal = j
        else:
            pass
    print(minVal)
else:
    print(x)

Solution (Python):
import math
a,b=map(int,input().split(" "))
c=input()
if c=="":
    print(a)
else:
    c = list(map(int,c.split(" ")))
    c.sort()
    
    inaria=list(range(min(c)-1,max(c)+2))
    add1=c+inaria
    add1=sorted(add1)
    l_all_only = [x for x in add1 if add1.count(x) == 1]
    
    min=4000000
    min_data=0
    for n in l_all_only:
        abn=abs(a-n)
        
        if abn<min:
            min=abn
            min_data=n
    print(min_data)

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

p = list(map(int,input().split()))
ans = 0
tmp = []
tmpans = 0

for i in range(102):
    if i in p:
        continue
    else:
        if abs(X-ans)>abs(X-i):
            ans = i
            tmp.append(i)
            
            
            
            
            
            
            
            




print(ans)

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

candidates = list(map(lambda elm: (abs(x - elm), elm), range(102)))
for p_i in p:
    candidates[p_i] = (10000, p_i)

sorted_candidates = sorted(candidates, key=lambda elm: elm[0])
min_val = sorted_candidates[0][0]
res = []
for candidate in sorted_candidates:
    if min_val == candidate[0]:
        res.append(candidate[1])
print(sorted(res)[0])

Solution (Python):
from bisect import bisect

X, N = [int(n) for n in input().split()]
if N==0:
    print(X)
else:
    P = sorted([int(n) for n in input().split()])
    if X not in P:
        print(X)
        exit()
    idx = bisect(P, X)
    ans_r = 101
    ans_l = 0
    for i in range(P[idx-1], 101):
        if i not in P:
            ans_r = i
            break
    for j in range(1, P[idx-1]):
        if j not in P:
            ans_l = j
    if abs(X-ans_l) == abs(ans_r-X):
        print(min([ans_l, ans_r]))
    else:
        print(ans_l if abs(X-ans_l) < abs(ans_r-X) else ans_r)

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

for i in range(0,102):
    if (i in p):
        continue
    else:
        tmp=(x-i)**2
        if tmp<ans:
            ans=tmp
            c=i
print(c)

Solution (Python):
x,n=map(int,input().split())
if n==0:
    print(x)
    exit()
elif n==100:
    if abs(-1-x)<=abs(101-x):
        print(0)
    else:
        print(101)
    exit()
List=list(map(int,input().split()))
num=list(range(0,102))
min_num=1000000000
for i in range(len(List)):
    if num.count(List[i])>=1:
        num.remove(List[i])
for i in range(len(num)):
    if (abs(num[i]-x)<abs(min_num-x)) or (abs(num[i]-x)==abs(min_num-x) and num[i]<min_num):
        min_num=num[i]
print(min_num)

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

table = [0 for i in range(102)]
for i in p:
    table[i] = 1

mx = 10000
ans = mx
dis = mx
for i in range(len(table)):
    idx = 101-i
    if (table[idx] == 0) and (dis >= abs(idx-x)):
        ans = idx
        dis = abs(idx-x)
print(ans)

Solution (Python):
c,x = map(int,input().split())
if not x:
    print(c)
    exit()
a = list(map(int,input().split()))
s = list(range(0,105))
for i in a:
    s.remove(i)

diffB = 99999
n = 9999

for i in s:
    if diffB > abs(c-i):
        diffB = abs(c-i)
        n = i
print(n)

Solution (Python):
import sys

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

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

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

for i in range(1000):
    m = X - ((i//2 +1) * (-1)**i)
    if m not in p:
        print(m)
        break

Solution (Python):
x,n = map(int,input().split())
p = list(map(int,input().split()))
ans = []
i = 1
if x not in p:
  print(x)
else:
  while len(ans)==0:
    if x+i not in p and x-i not in p:
      ans.append(x+i)
      ans.append(x-i)
    elif x+i not in p:
      ans.append(x+i)
    elif x-i not in p:
      ans.append(x-i)
    else:
      i+=1
  print(min(ans))

Solution (Python):
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  

x, n= na()
p = na()
a = x
b = x
for i in range(100):
  if (b in p) == False:
    print(b)
    break
  elif (a in p) == False:
    print(a)
    break
  else:
    a = a+1
    b = b-1

Solution (Python):
x, n = map(int, input().split())
p=list(map(int,input().split()))
for i in range(100):
    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):
  p = list(map(int, input().split()))
else:
  print(x)
  exit()

kouho = list(range(-200, 200))


for i in range(len(p)):
  if p[i] != x:
    del kouho[kouho.index(p[i])]

kouho_num = kouho.index(x)
right = kouho_num + 1
left = kouho_num - 1

if (x not in p):
  print(x)
elif abs(kouho[right] - kouho[kouho_num]) > abs(kouho[kouho_num] - kouho[left]):
  print(kouho[left])
elif abs(kouho[right] - kouho[kouho_num]) == abs(kouho[kouho_num] - kouho[left]):
  print(kouho[left])
else:
  print(kouho[right])

Solution (Python):
import sys
input=sys.stdin.readline
x,n=map(int,input().split())
if n==0:
    print(x)
else:
    p=list(map(int,input().split()))
    d=0
    while True:
        if x-d in p:
            if x+d in p:
                d+=1
            else:
                a=x+d
                break
        else:
            a=x-d
            break
    print(a)

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


x  = (N % 2)
if x == 0:
    n = N // 2
else:
    n = N // 2 + 1
i = 1

while i <= n:
    ans_l.append(X - i)
    ans_l.append(X + i)
    i += 1
l = len(array)

for j in range(l):
    try:
        ans_l.remove(array[j])
    except ValueError:
        pass
print(ans_l[0])

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

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

    p_ = [abs(x - n) for n in p]

    m_p_ = p_.index(min(p_))

    start = p[m_p_]

    for v in range(100):
        a = start - v - 1
        b = start + v + 1
        if (a not in p) and (b in p):
            ans = a
            break

        elif (a in p) and (b not in p):
            ans = b
            break
            
        elif (a not in p) and (b not in p):
            if a > b:
                ans = b
                break
            else:
                ans = a
                break
                
else:
    ans = x
    
print(ans)

Solution (Python):
x,n=map(int,input().split())
p=list(map(int,input().split()))
j=0
while(1):
    if((x-j in p)==False):
        print(x-j)
        break
    elif((x+j in p)==False):
        print(x+j)
        break
    j+=1

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

if N == 0: print(X)
else:
    p.sort()
    if X in p:
        index = p.index(X)
        c = 1
        while True:
            if index - c >= 0 and p[index - c] != X - c:
                print(X - c)
                break
            elif index - c < 0:
                print(X - c)
                break
            elif index + c >= N:
                print(X + c)
                break
            elif index + c < N and p[index + c] != X + c:
                print(X + c)
                break
            else:
                c += 1

    else: print(X)

Solution (Python):
X,N = map(int,input().split())
p = list(map(int,input().split()))
xp = X
xm = X
for i in range(101):
  if (xp not in p) and (xm not in p):
    print(min(xp,xm))
    break
  if xp not in p:
    print(xp)
    break
  if xm not in p:
    print(xm)
    break
  xp += 1
  xm -= 1

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

m=100
a=x
for i in range(-101,201):
    if i not in p:
        z=abs(i-x)
        if m>z:
            m=z
            a=i

print(a)

Solution (Python):
import sys
import math
def I():return int(sys.stdin.readline().replace("\n",""))
def I2():return map(int,sys.stdin.readline().replace("\n","").split())
def S():return str(sys.stdin.readline().replace("\n",""))
def L():return list(sys.stdin.readline().replace("\n",""))
def Intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split()))

x,n = I2()
if n != 0:
    p = Intl()
else:
    p = []
p.sort()
if not x in p:
    print(x)
else:
    b,e = 0,n-1
    r = []
    s = []
    for i in range(min(p)-1,max(p)+2):
        if i not in p:
            r.append(i)
            s.append(abs(x-i))
    print(r[s.index(min(s))])

Solution (Python):
import sys

x, n = map(int, input().split())
p = list(map(int, input().split()))
flag = [False]*102
for i in p:
    flag[i] = True
for j in range(0, 102):
    l = max(0, x-j)
    r = min(101, x+j)
    if not flag[l]:
        print(l)
        sys.exit()
    if not flag[r]:
        print(r)
        sys.exit()

Solution (Python):
x, n = map(int, input().split())
p = list(map(int, input().split()))
ans = x
mn = 10 ** 18
for i in range(-201, 201):
    if i not in p:
        if abs(x-i) < mn:
            mn = abs(x-i)
            ans = i
print(ans)

Solution (Python):
import sys

X,N=map(int,input().split())
if N==0:
  print(X)
  sys.exit()
lis=[int(_) for _ in input().split()]
for i in range(200):
  s=X-i
  u=X+i
  if not(s in lis):
    print(s)
    sys.exit()
  if not (u in lis):
    print(u)
    sys.exit()

Solution (Python):
from bisect import bisect
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    X, N = map(int, input().split())
    P = list(map(int, input().split()))

    if not N:
        print(X)
        return

    nums = []
    for i in range(min(P) - 1, max(P) + 2):
        if i not in P:
            nums.append(i)
    i = bisect(nums, X)
    if abs(nums[i] - X) < abs(nums[i-1] - X):
        print(nums[i])
    else:
        print(nums[i-1])


main()

Solution (Python):
X, N = map(int, input().split())
if N == 0:
    print(X)
else:
    l = list(map(int, input().split()))
    m = [i for i in range(102)]
    s = list(set(m) - set(l))
    answer_list = []
    for i in s:
        if i <= X:
            answer_list.append(X - i)
        else:
            answer_list.append(i - X)
    answer = min(answer_list)
    if X - answer in s:
        print(X - answer)
    else:
        print(X + answer)

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

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

cnt = 0
while True:
    if cnt == 0 and x not in list_:
        print(x)
        break

    if x - cnt not in list_:
        print(x - cnt)
        break

    if x + cnt not in list_:
        print(x + cnt)
        break

    cnt += 1

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


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

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(n+2):
        if x-i in p:
            if x+i in p:
                a =0
            else:
                print(x+i)
                exit(0) 
        else:
            print(x-i)
            exit(0)

Solution (Python):
import sys
X ,N = map(int,input().split())
p = list(map(int,input().split()))
min_dif = 10000
output = 10000
for i in range(10000):
  if (5000 - i in p) == False:
    if abs(X-(5000-i)) <= min_dif:
      min_dif = abs(X-(5000 - i))
      output =  5000 - i
print(output)