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):



import sys
X, N = map(int, input().split())
p = []
for i in sys.stdin:
    p = list(map(int, i.split()))

for i in range(X, -51, -1):
    l = i
    if i not in p:
        break
for j in range(X, 151):
    r = j
    if j not in p:
        break
print(l if abs(l-X) <= abs(r-X) else r)

Solution (Python):



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

lst = [i for i in range(-101,200)]

anslst = []
for n in lst:
    if not n in pl:
        anslst.append(n)



an = 1000
idx = 0
for i in range(len(anslst)):
    tmp = abs(X - anslst[i])
    if tmp < an:
        an = tmp
        idx = i


ans = anslst[idx]
print(ans)

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

cnt1 = 0
cnt2 = 0
ans1 = 0
ans2 = 0

for i in range(x,102):
    cnt1 += 1
    if not i in p:
        ans1 = i
        break

for i in range(x,-1,-1):
    cnt2 += 1
    if not i in p:
        ans2 = i
        break

if cnt1 < cnt2:
    print(ans1)
elif cnt1> cnt2:
    print(ans2)
else:
    print(ans2)

Solution (Python):
import sys

X, N = map(int, input().split(" "))
try:
    P = list(map(int, input().split(" ")))
except:
    P = []

def check(n, X, P):
    if not X - n in P:
        print(X - n)
        sys.exit()
    
    if not X + n in P:
        print(X + n)
        sys.exit()

for n in range(0, 101):
    check(n, X, P)

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

Solution (Python):



ha = input()
kita = ha.split(" ")
roop = 0
isR = False
if(int(kita[1]) == 0):
    print(kita[0])
else:
    koi = input()
    n = koi.split(" ")

    while(True):
        a = True
        for num in n:
            if(int(kita[0])-roop == int(num)):
                a = False
        if(a):
            print(int(kita[0])-roop)
            break
        a = True
        for num in n:
            if(int(kita[0])+roop == int(num)):
                a = False
        if(a):
            print(int(kita[0])+roop)
            break
        roop += 1

Solution (Python):
x,n = map(int, input().split())
if n == 0:
  print(x)
else:
  p_list = list(map(int, input().split()))
  if x in p_list:
    p_list.sort()
    pos = p_list.index(x)
    tmp1 = p_list[-1]+1
    tmp2 = p_list[0]-1
    for i, val in enumerate(p_list[pos+1:]):
      if val != p_list[pos + i] + 1:
        tmp1 = p_list[pos + i]+1
        break
    for i, val in enumerate(p_list[pos-1::-1]):
      if val != p_list[pos - i] - 1:
        tmp2 = p_list[pos - i]-1
        break
    if tmp1 - x < x - tmp2:
      print(tmp1)
    else:
      print(tmp2)
  else:
    print(x)

Solution (Python):
x, n = (int(e) for e in input().split())
i = 0
if(n != 0):
    p = list(map(int, input().split()))
else:
    p = -1
flag_f = False
for j in range(n):
    if(p[j] == x):
        flag_f = True
if(flag_f == False):
    print(x)

while(flag_f == True):
    i += 1
    flag_p = False
    flag_m = False
    for j in range(n):
        if(p[j] == x+i):
            flag_p = True
        elif(p[j] == x-i):
            flag_m = True
    if(flag_m == False):
        print(x-i)
        break
    elif(flag_p == False):
        print(x+i)
        break

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

def judge(p_,x_):
    p_d = list(set(sorted(map(lambda y: np.abs(x_-y),p_))))
    if p_d == []:
        return x_
    for delta in range(100):
        if (x_-delta not in p_):
            return x_-delta
        if (x+delta not in p_):
            return x_+delta
    return x_

print(judge(p,x))

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
def main():
    x, n = map(int, readline().split())
    P = [int(i) for i in readline().split()]
    notP = [i for i in range(-100, 200) if i not in P]
    abcxP = [abs(x-i) for i in notP]
    mi = 10000000
    idx = 0
    for i in range(len(abcxP)):
        if abcxP[i] < mi:
            mi = abcxP[i]
            idx = i
    print(notP[idx])
if __name__ == '__main__':
    main()

Solution (Python):
x, y = map(int, input().split())
li = list(map(int, input().split()))

if y == 0:
    print(x)
    quit()

ans=[]
for i in range(-101,201):
    if not i in li:
        ans.append(abs(i - x))

if not x - min(ans) in li:
    print(x-min(ans))
elif not min(ans) + x in li:
    print(min(ans) + x)

Solution (Python):
import collections
X, N = map(int, input().split())
list = list(map(int, input().split()))
c = collections.Counter(list)
res1=-1000
res2=-1000
for i in range (0, 100):
  if(c[X+i]==0):
    res1=X+i
    if(c[X-i]==0):
      res2=X-i
    break
  if(c[X-i]==0):
    res2=X-i
    break
if(res1==-1000 and res2!=-1000):
  print(res2)
elif(res2==-1000 and res1!=-1000):
  print(res1)
elif(abs(X-res1)<abs(X-res2)):
  print(res1)
elif(abs(X-res2)<=abs(X-res1)):
  print(res2)

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

for r in range (0,102):
    if (r not in p):
        if (abs(x - int(r)) < k):
            A = int(r)
            k = abs(x - int(r))
if (A > x):
    if (2*x-A not in p):
        A = 2*x-A

print (A)

Solution (Python):
temp = list(map(int, input().split()))
X = temp[0]
N = temp[1]
if N > 0:
  num = list(map(int, input().split()))
  nums = [i for i in range(102) if i not in num]
  ans = 0
  for j in nums:
    if abs(j-X) < abs(ans-X):
      ans = j
  print(ans)
else:
  print(X)

Solution (Python):
import sys

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

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

smallest = int(2 ** 63 - 1)
ans = x
for i in range(-1000, 1000):
  if i in p:
    continue

  tmp = abs(x - i)
  if tmp < smallest:
    smallest = tmp
    ans = i

print(ans)

Solution (Python):
x, n = map(int, input().split())
if n == 0:
  print(x)
else:
  p_list = [int(x) for x in input().split()]
  x_list = list(range(102))
  for i in range(n):
    p_i = p_list[i]
    if p_i in x_list:
      x_list.remove(p_i)
  for i in range(51):
    x_hiku = x - i
    x_tasu = x + i
    if x_hiku in x_list:
      print(x_hiku)
      break
    elif x_tasu in x_list:
      print(x_tasu)
      break

Solution (Python):
x, n = map(int, input().split())
if n==0:
    print(x)
else:
    p = list(map(int, input().split()))
    p.sort()
    i = 0
    while i < n and p[i] < x:
        i += 1

    if p[i] != x:
        print(x)
    else:
        j = 1
        up = x+j
        down = x-j
        while True:
            if i-j>=0 and p[i-j] != x-j:
                print(x-j)
                break
            elif i-j < 0:
                print(x-j)
                break
            if i+j<n and p[i+j] != x+j:
                print(x+j)
                break
            elif i+j >= n:
                print(x+j)
                break
            j += 1

Solution (Python):
from collections import defaultdict
if __name__ == "__main__":
    x,n = map(int,input().split())
    l = list(map(int,input().split()))
    if n == 0 :
        print(x)
    else :
        l.sort()
        count = 0
        dist = 999
        ans = -100
        for i in range(-100,201) :
            if i in l :
                continue
            if dist > abs(x - i) :
                dist = abs(x - i)
                ans = i 
        print(ans)

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

    min_val = 0
    diff = abs(x-min_val)
    for i in range(1, 102):
        if diff > abs(x-i) and not(i in p):
            min_val = i
            diff = abs(x-min_val)
        elif diff < abs(x-i) and not(i in p):
            break

    print(min_val)

Solution (Python):
X,N = map(int,input().split())
P = list(map(int,input().split()))
m = {}
for i in range(102):
    if i in P:
        continue
    ab = abs(i - X)
    m[i] = ab

min_k_list = [kv[0] for kv in m.items() if kv[1] == min(m.values())]
print(min(min_k_list))

Solution (Python):
x, n = map(int, input().split())
p = sorted(list(map(int, input().split())), reverse=True)
q = sorted([i for i in range(-102, 102)], reverse=True)

ans = {'diff':1000, 'ans':0}

for i in q:
    if not i in p:
        if abs(x-i) <= ans['diff']:
            ans['diff'] = abs(x-i)
            ans['ans'] = i

print(ans['ans'])

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

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

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

Solution (Python):
x, n = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]
if n == 0:
    ans = x
else:
    p = sorted(p)
    min_p = min(p)
    max_p = max(p)
    j = 0
    ans = 0
    if x < min_p:
        ans = x
    elif x > max_p:
        ans = x
    elif x == min_p:
        ans = min_p-1
    elif x == max_p:
        if max_p-1 == p[len(p)-2]:
            ans = max_p+1
        else:
            ans = max_p-1
    else:
        for i in range(min_p-1, max_p+1):
            if i == p[j]:
                j += 1
                if len(p) == j:
                    im_i = p[j-1] +1
                    if abs(ans-x) > abs(im_i-x):
                        ans = im_i
            else:
                if abs(ans-x) > abs(i-x):
                    ans = i
print(ans)

Solution (Python):
x, n = map(int, input().split())
if n > 0:
    ps = list(map(int, input().split()))
else:
    print(x)
    exit()
nums = [n for n in range(-1, 102) if n not in ps]

abs_plus = sorted([n-x for n in nums if n-x >= 0])
abs_minus = sorted([-(n-x) for n in nums if n-x < 0])
if abs_plus == []:
    print(x-abs_minus[0])
elif abs_minus == []:
    print(x+abs_plus[0])
elif abs_plus[0] >= abs_minus[0]:
    print(x-abs_minus[0])
else:
    print(x+abs_plus[0])

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

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

p.sort()

t = []
t.append(p[0] - 1)

for i in range(p[0], p[N-1]+1):
    if i not in p:
        t.append(i)
t.append(p[N-1]+1)

_min = 1000000000000
res = 100000000000
for i in t:
    if abs(X - i) == _min:
        res = min(res, i)
    if abs(X - i) < _min:
        _min = abs(X - i)
        res = i

print(res)

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

  l100 = list(range(102))
  for i in p:
    if i in l100:
      l100.remove(i)
  sa = []
  for i in l100:
    sa.append(abs(x-i))

  idx = sa.index(min(sa))
  print(l100[idx])

Solution (Python):
x,n=map(int,input().split())
if n==0:
    print(x)
    exit()
p=list(map(int,input().split()))
a=x
b=x
while a in p:
    a-=1
while b in p:
    b+=1
if abs(x-a)>abs(x-b):
    print(b)
elif abs(x-a)<abs(x-b):
    print(a)
else:
    print(min(a,b))

Solution (Python):
x , n= map(int,input().split())
p = list(map(int,input().split()))
ans = []
if n == 0:
    print(x)
else:
    for i in range(-10,102):
        if i in p:
            pass
        else:
            ans.append(i)
    sa = []
    for i in range(len(ans)):
        sa.append(abs(ans[i]-x))
    MIN=min(sa)
    for i in range(len(ans)):
        if MIN == abs(ans[i]-x):
            print(ans[i])
            break

Solution (Python):
x, n = map(int, input().split())
if(n > 0):
  p = list(map(int, input().split()))
  lists = list(range(102))
  del lists[0]
  sa = []
  for i in lists:
    if(i in p):
      sa.append(999)
    else:
      sa.append(abs(x-i))
    ind = sa.index(min(sa))
    ans = lists[ind]
else :
  ans = x
if (x <= ans - x):
  ans = 0
print(ans)

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

dps = set(ps)

i = X
j = X

while True:
    if i not in dps:
        print(i)
        break
    if j not in dps:
        print(j)
        break
    i -= 1
    j += 1

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

i = 0
while True:

    a = (x + i) in p
    b = (x - i) in p

    if a == False:
        if b == False:
            print(x - i)
            break
        else:
            print(x + i)
            break

    elif b == False:
        if a == False:
            print(x + i)
            break
        else:
            print(x - i)
            break

    i += 1

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


def func():
    if N == 0:
        return X

    P = list(map(int, input().split()))
    
        
    diff = 0
    while True:
        if X - diff not in P:
            return X - diff
        if X + diff not in P:
            return X + diff
        diff += 1


print(func())

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

i = X
ans_big = X

while(True):
  
  if((i in p_list)==True):
    pass
  else:
    ans_big = i
    break
  i = i + 1
    
i = X
ans_small = X
while(True):
  
  if((i in p_list)==True):
    pass
  else:
    ans_small = i
    break
  i = i - 1


if(abs(X-ans_small)>abs(X-ans_big)):
  print(ans_big)
else:
  print(ans_small)

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

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

if n!=0:
    a=list(map(int,input().split()))
    a.sort
    x_p=x
    x_n=x
    
    while True:
        if all(elem != x_p for elem in a) and all(elem != x_n for elem in a):
            print(x_n)
            break;
        elif all(elem != x_p for elem in a):
            print(x_p)
            break;
        elif all(elem != x_n for elem in a):
            print(x_n)
            break;
        x_n-=1
        x_p+=1
            
else:
  print(x)

Solution (Python):
def main():
  X, N = map(int, input().split()) 
  p = [int(x) for x in input().split()]
  a = 1
  
  if N == 0:
    print(X)
  else:
    if X in p:
      while True:
        if X - a in p and X + a in p:
          a += 1
          continue
        elif X - a in p:
          print(X + a)
          break
        else:
          print(X - a)
          break
    else:
      print(X)

    
if __name__ == '__main__':
  main()

Solution (Python):
import math

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



def main(X, N):
  if N == 0:
    print(X)
    return
     
  p = list(map(int, input().strip().split()))
  if not X in p:
    print(X)
    return
    
  for i in range(math.ceil((N-1)/2)+1):
    a = X-i-1
    b = X+i+1
    if not a in p:
      print(X-i-1)
      return
    if not b in p:
      print(X+i+1)
      return
   
  
main(X, N)

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

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

  for i in range(100):
  
  
    if p.count(x-i) == 0:
      print(x-i)
      break
    elif p. count(x+i) == 0:
      print(x+i)
      break
else:
  print(x)

Solution (Python):
import sys

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

if n == 0 or not x in p:
    print(x)
    sys.exit()

d = 101

for k in p:
    if d > abs(x - k):
        d = abs(x - k)

for i in range(101):
    if not x - (d + i) in p:
        print(x - (d + i))
        sys.exit()
    elif not x + (d + i) in p:
        print(x + (d + i))
        sys.exit()

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

Solution (Python):
X,N=map(int,input().split())
P=list(map(int,input().split()))
m=100
ans=0
lis=list(range(101,-1,-1))
for k in lis:
    for l in range(N):
        if k==P[l]:
            lis[101-k]=0
for i in lis:
    if abs(i-X)<=m:
        m=abs(i-X)
        ans=i
print(ans)

Solution (Python):
x,n=list(map(int,input().split()))
if n==0:
  print(x)
  exit()
P=list(map(int,input().split()))
P.append(x)
PP=sorted(P)
if PP.count(x) == 1:
  print(x)
else:
  i=PP.index(x)
  k=1
  high=x
  low=x
  while k>0:
    if PP.count(x+k)==0:
      high=x+k
    if PP.count(x-k)==0:
      low=x-k
    k+=1
    if low!=x:
      print(low)
      exit()
    elif high!=x:
      print(high)
      exit()

Solution (Python):
x, n = map(int, input().split())
if n ==0:
    print(x)
    
else:
    p = list(map(int, input().split()))
    p.sort()
    
    ans = 1000
    xx = 0
    for i in range(102):
        if not i in p:
            if x-i>=0 and ans>x-i:
                ans = x-i
                xx = i
            elif i-x>0 and ans>i-x:
                ans = i-x
                xx = i
    print(xx)

Solution (Python):
x, n = map(int, input().split())
p = list(map(int, input().split()))
cnt = 0
while True:
    tmp = []
    if x+cnt not in p:
        tmp.append(x+cnt)
    
    if x-cnt not in p:
        tmp.append(x-cnt)
    


    if len(tmp) != 0:
        print(min(tmp))
        break

    cnt += 1

Solution (Python):
X,N = list(map(int,input().split()))
if N != 0:
  p = list(map(int,input().split()))
else:
  p = [X+1]
def f(p):
  global X
  return p - X

p2 = list(map(f,p))

p3 = list(map(abs,p2))

OK = 2
j = 0


if min(p3) ==0:
  while(OK==2):
    j+=1
    OK = p3.count(min(p3)+j)
  if OK == 1:
    print(X-p2[p3.index(min(p3)+j)])
  else:
    print(X-j)
else:
  print(X)

Solution (Python):
import sys
input1 = list(map(int, input().split()))
X = input1[0]
N = input1[1]
p = list(map(int, input().split()))

if N == 0:
    print(X)
    sys.exit()
elif (X in p) == False:
    print(X)
    sys.exit()


flag = True
diff = 1

while(flag):
    if ((X - diff) in p) == False:
        answer = X - diff
        flag = False
    elif ((X + diff) in p) == False:
        answer = X + diff
        flag = False
    else:
        diff += 1

print(answer)

Solution (Python):
x, n = map(int, input().split())
p = list(map(int, input().split()))
min = 0
min_dis = 10**10
ch = [0 for i in range(102)]
for i in range(len(p)):
    ch[p[i]] = 1
for i in range(102):
    idx = 101-i
    if ch[idx] == 0 and abs(x-idx) <= min_dis :
        min = idx
        min_dis = abs(x-idx)
print(min)

Solution (Python):
x,n = map(int,input().split())
if n == 0:
  print(x)
  exit()
line = sorted(list(map(int,input().split())))
anss = [i for i in range(max(line)+2)]
for i in range(n):
  anss.remove(line[i])
anss.append(x)
ans = sorted(anss)
a = []
for i in range(len(ans)):
  if ans[i] == x:
    a = ans[i-1:i+2]
    break
low = a[1]-a[0]
high = a[2] - a[1]
if high < low:
  print(a[2])
else:
  print(a[0])

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

if x not in p:
    print(x)
else:
    t = [i for i in range(-101,201)]
    for i in range(n):    
        t.remove(p[i])


    res = 100
    s = 1000
    for i in range(len(t)):

        if s >= abs (x - t[len(t)-1-i]):
            s = abs (x - t[len(t)-1-i])
            res = t[len(t)-1-i]
    print(res)

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


l = [0]*200

for i in range(N):
  l[abs(p[i] - X)] += 1



if N == 0:
  print(X)
else:
  for i in range(N+1):
    if i == 0:
      if l[0] == 1:
        continue
      else:
        print(X)
        break
    else:
      if l[i] == 0:
        print(X-i)
        break
      elif l[i] == 1:
        try:
          p_index = p.index(X-i)
          print(X+i)
        except:
          print(X-i)
        break

Solution (Python):
import math
import string
import collections
from collections import Counter
from collections import deque
from decimal import Decimal
import sys
import fractions
from operator import itemgetter


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


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor



dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
x, n = map(int, input().split())
if n == 0:
    print(x)
    exit()
p = readints()
tmp = list(range(-200, 201))

for i in range(n):
    tmp.remove(p[i])

ans = [None]*500

for i in range(len(tmp)):
    ans[tmp[i]] = abs(tmp[i]-x)

x = 10**5
for i in range(len(ans)):
    if ans[i] != None:
        x = min(x, ans[i])

print(ans.index(x))

Solution (Python):
X, N = map(int, input().split())
ans = X
if N>0:
  P = list(map(int, input().split()))
  P.sort()
  if X in P:
    ans = 0
    x = P.index(X)
    i = 1
    a = x-1
    b = x+1
    m = min(P[N-1]-X, X-P[0])
    for i in range(1,m+2):
      if a < 0:
        a = 0
      if b > N-1:
        b = N-1
      if X-i != P[a]:
        ans = X-i
        break
      elif X+i != P[b]:
        ans = X+i
        break
      else:
        a -= 1
        b += 1
print(ans)

Solution (Python):


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

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

Solution (Python):
import sys

def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
from bisect import bisect_left
from operator import lt, le
def find_nearst_value(lst, val, left=True):
    """ソート済のリストから，valに最も近い要素を返す.
    @param lst: ソート済のリスト
    @param left:
        lv < val < rv，val-lv == rv-val のとき，
        Trueならばlvを，Falseならばrvを選択する
    @return もっともvalに値が近いlstの要素
    """
    pos = bisect_left(lst, val)
    if pos == 0: return lst[0]
    if pos == len(lst): return lst[-1]
    lv, rv = lst[pos-1:pos+1]
    op = le if left else lt
    return lv if op(val-lv, rv-val) else rv

def main():
    x, n = MII()
    pp = MII()
    setp = set(pp)
    qq = [i for i in range(200) if not i in setp]
    qq.sort()
    
    print(find_nearst_value(qq,x))

if __name__ == '__main__':
    main()

Solution (Python):
import bisect, collections, copy, heapq, itertools, math, numpy, string
import sys
from bisect import bisect_left, bisect_right, insort
from collections import deque
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def MS(): return map(str, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())



import bisect


x,n =MI()
p =LI()
j = 0
while x+j in p and x-j in p:
    j += 1

if not(x+j in p) and not(x-j in p):
    print(x-j)
elif x+j in p:
    print(x-j)
else:
    print(x+j)

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

    sample = list(range(0,max(p)+2)) 
    reject = list(set(p))

    for i in range(len(reject)):
        sample.remove(reject[i])

    champ = abs(sample[0] - x)
    ans = sample[0]
    for i in range(1, len(sample)):
        if abs(sample[i] - x) < champ:
            champ = abs(sample[i] - x)
            ans = sample[i]
        elif abs(sample[i] - x) == champ:
            if ans >= sample[i]:
                ans = sample[i]
            else:
                pass
        else:
            pass

    print(ans) 

else:
    print(x)

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

ans = x

for i in range(101):
    tmp1 = x - i
    tmp2 = x + i
    if not tmp1 in p:
        ans = tmp1
        break
    elif not tmp2 in p:
        ans = tmp2
        break

print(ans)

Solution (Python):
def challenge(X, numlist, vec):
  while True:
    try:
      numlist.index(X)
    except:
      return(X)
    if vec:
      X -= 1
    else:
      X += 1

list1 = input().split()
X = int(list1[0])
N = int(list1[1])
  
if N == 0:
  print(X)
else:
  list2 = input().split()
  numlist = []
  for i in list2:
    numlist.append(int(i))

  num1 = challenge(X, numlist,True)
  num2 = challenge(X, numlist,False)
  wk1 = abs(X - num1)
  wk2 = abs(X - num2)
  if wk1 > wk2:
    print(num2)
  else:
    print(num1)

Solution (Python):
import bisect

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

p.sort()

index = bisect.bisect_left(p,x)

if n==0:
    print(x)
else:
    p= p+[p[n-1]+2]
    for i in range(n):
        
        if p[max(index-i,0)] != x-i:
            print(x-i)
            break
        elif p[min(index+i,n)] != x+i:
            print(x+i)
            break
    else:
        print(p[0]-1)

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

x = int(x)
n = int(n)

def check(x,n):
    
    if int(n) == 0:
        print(x)
        return

    
    p_list = input().split()

    
    for i in range(0, 100):
        min_x = str(x - int(i))
        max_x = str(x + int(i))

        
        if min_x not in p_list or max_x not in p_list:
            if min_x not in p_list:
                print(min_x)
                return
            
            if max_x not in p_list:
                print(max_x)
                return
        
        
        if min_x not in p_list and max_x not in p_list:
            print(min_x)
check(x,n)

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

Solution (Python):
x, n = map(int, input().split())
ps = sorted(list(map(int, input().split())))
if x not in ps:
    print(x)
else:
    not_ps = [i for i in range(ps[0]-1, ps[-1]+2) if i not in ps]
    ans_min = 1000
    for not_p in not_ps:
        if abs(not_p-x) < ans_min:
            ans = not_p
            ans_min = abs(not_p-x)
    print(ans)

Solution (Python):
x,n= map(int, input().split())
if n!=0:
    p = list(map(int, input().split()))
else:
    p=[]
def func(x,n,p):
    if n==0:
        print(x)
        return
    if x not in p:
        print(x)
        return
    current = x
    for d in range(1,101,1):
        if current-d not in p:
            print(current-d)
            return
        elif current+d not in p:
            print(current+d)
            return
    print(x-101)
    return
func(x,n,p)

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

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

if x not in p:
    print(x)
    exit()


ans1=ans2=101
flag=0


for i in range(1,len(p)+1):


    if x+i not in p:
        ans1=x+i
        flag=1
    if x-i not in p:
        ans2=x-i
        flag=1
    if flag==1:
        break



print(min(ans1,ans2))

Solution (Python):
l = [int(i) for i in input().split()]
n = [int(i) for i in input().split()]
a = 0

while True:
  b = l[0] - a
  c = l[0] + a
  if b not in n:
    print(b)
    break
  elif c not in n:
    print(c)
    break
  else:
    a += 1

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

Solution (Python):
import sys
X,N = map(int, input().split())
if N == 0:
  print(X)
  sys.exit()
P = list(map(int, input().split()))
P.sort()
score = P[0]-1
for n in range(P[0]-1,P[N-1]+2):
  flag = True
  for m in range(N):
    if P[m]==n:
      flag = False
  if flag and abs(X-n)<abs(X-score):
    score = n
print(score)

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



flag = 0
temp = x
while(flag == 0):
    if x in p:
        x +=1        
    else:
        ans_p = x
        flag =1

x = temp
flag = 0

while(flag == 0):
    if x in p:
        x -=1        
    else:
        ans_n = x
        flag =1

abso_p = abs(ans_p-temp)
abso_n = abs(ans_n-temp)
if abso_p >= abso_n:
    print(ans_n)
elif abso_p < abso_n:
    print(ans_p)

Solution (Python):
def main():
    x,y = list(map(int, input().split()))

    if y == 0:
        print(x)
        exit()
    nums = list(map(int, input().split()))
    ans = 0
    for i in range(1, 200):
        if i not in nums:
            ans = ans if abs(ans-x) <= abs(i-x) else i
    print(ans)



if __name__ == '__main__':
    main()

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

ab = 100
num = []
for i in range(102):
    if p.count(i)>0:
        continue
    abst = abs(i-x)
    if abst < ab:
        ab = abst
        num = [i]
    elif abst == ab:
        ab = abst
        num += [i]
print(min(num))

Solution (Python):
import math
import sys

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

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

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

p.sort()

ans = min(p, key=lambda y:abs(y-x))
idx = p.index(min(p, key=lambda y:abs(y-x)))




if x != ans:
    print(x)
    sys.exit()


cnt = idx
larger_near = p[cnt]
smaller_near = p[cnt]

while cnt < n:
    tmp = p[cnt]
    cnt += 1
    if cnt == n:
        larger_near = tmp + 1
        break
    elif p[cnt] != tmp + 1:
        larger_near = tmp + 1
        break

cnt = idx
while cnt >= 0:
    tmp = p[cnt]
    cnt -= 1
    if p[cnt] != tmp - 1:
        smaller_near = tmp - 1
        break

if abs(smaller_near - x) <= abs(larger_near - x):
    ans = smaller_near
else:
    ans = larger_near
print(ans)