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.



Sample input:
6 5
4 7 10 6 5


Sample output:
8

Submission status: Accepted

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

mn = 999
ans = 0

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

    if a > mn:
        break

print(ans)

Submission status: Accepted

Solution code:
import numpy as np

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

abslis = [[]for i in range(102)]*102
for n in range(N):
    abslis[abs(p[n]-X)].append(p[n])

if len(abslis[0]) == 0 :
    print(X)
else :
    # if len(abslis[1])==0:
    #     print()
    for i in range(1,N+1):
        if len(abslis[i]) != 2: 
            if len(abslis[i]) == 0:
                print(X-i)
            elif len(abslis[i]) ==1:
                print( X+(X-abslis[i][0]) )   
            break

Submission status: Accepted

Solution code:
"""
int #整数
float #小数

#標準入力
a=input()
a,b=map(int,input().split()) #入力は行ごと
#標準出力
print(a)
ptrint("Hello")
#for
for name in fruits: #fruitの頭から操作
    print(name)
#リスト
list0 = [] #リスト生成
list0 = [1,2,3,4] #初期化
list0 = [0]*10 #[0,0,0,0,0,0,0,0,0,0]
list1 = list(map(int, input().split()))　# 複数の入力をリストに入れる
list1 = list1 + [6, 7, 8] #リストの追加
list2.append(34) #リストの追加　最後に（）内が足される
list.insert(3,10) #リストの追加　任意の位置（追加したい位置,追加したい値）
len(list4) #リストの要素数
max(sa) #list saの最小値
list5.count(2) #リスト内の2の数
abs(a) #aの絶対値
max(a,b) min(a,b) #最大値　最小値

extension_1 = []
for i in range(10):
    extension_1.append(i)
extension_1
#>>> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

comprehension_1= [i for i in range(10)]
comprehension_1
#>>> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
"""
import math
import sys
X,N=map(int,input().split())
if N==0:
    print(X)
    sys.exit()
number = list(map(int, input().split()))
d =[0]*102
for i in number:
    d[i]=101
    
for j in range(102):
    if d[j]==101:
        continue
    d[j] = abs(X-j)
ans = min(d)
k=0
for l in range(102):
    if d[l]==ans:
        break
    k=k+1
print(k)

Submission status: Accepted

Solution code:
import re
import sys
from bisect import bisect, bisect_left, insort, insort_left
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from itertools import (
    accumulate, combinations, combinations_with_replacement, groupby,
    permutations, product)
from math import (acos, asin, atan, ceil, cos, degrees, factorial, gcd, hypot,
                  log2, pi, radians, sin, sqrt, tan)
from operator import itemgetter, mul
from string import ascii_lowercase, ascii_uppercase, digits


def inp():
    return(int(input()))


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


def instr():
    s = input()
    return(list(s[:len(s)]))


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


x, n = invr()

mark = [0]*101
a = inlist()

lx = rx = res = x
while True:
    if lx not in a:
        res = lx
        break
    if rx not in a:
        res = rx
        break
    lx -= 1
    rx += 1
print(res)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
dic = {}
arr = list(map(int, input().split()))
for i in range(n):
    dic[arr[i]] = True
for i in range(1, 100):
    if x not in dic:
        print(x)
        break
    if x-i in dic:
        if x+i in dic:
            continue
        else:
            print(x+i)
            break
    else:
        print(x-i)
        break

Submission status: Accepted

Solution code:
# C - Forbidden List
def main():
    X, _, *P = map(int, open(0).read().split())
    P = set(P)
    for i in range(100):
        if X - i not in P:
            print(X - i)
            return
        if X + i not in P:
            print(X + i)
            return


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
arr = list(map(int,input().split()))
l = x
r = x
while (l in arr and r in arr):
    l-=1
    r+=1
la = abs(x-l)
ra = abs(x-r)
if (la == ra):
    if (l not in arr):
        print(l)
        exit(0)
    if (r not in arr):
        print(r)
        exit(0)
else:
    if (la < ra):
        print(l)
        exit(0)
    else:
        print(r)
        exit(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# import math
# x, y = map(int, input().split())
# a = (4 * x - y) / 2
# if a >= 0 and a <= x and a == math.ceil(a):
#     print('Yes')
# else:
#     print('No')


x, n = map(int, input().split())
p = list(map(int, input().split()))
# print(p)
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

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
if N!=0:
    p=list(map(int,input().split()))
    checkNum=[0 for j in range(102)]
    for i in range(len(p)):
        checkNum[p[i]]=1
    i=0
    while(X-i>=0 or X+i<=101):
        if X-i>=0:
            if checkNum[X-i]==0:
                print(X-i)
                break
        if X+i<=101:
            if checkNum[X+i]==0:
                print(X+i)
                break
        i+=1
else:
    print(X)

Submission status: Accepted

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


all_l = [i for i in range(0,101)]
for p in P:
    all_l.remove(p)

kouho = x
for i in range(200):
    kouho1 = x-i
    kouho2 = x+i
    if kouho1 not in P:
        print(x-i)
        break
    elif kouho2 not in P:
        print(x+i)
        break

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
if n == 0: print(x); exit()
P = [*map(int, input().split())]
for d in range(100): # [0,100)
    a = x - d
    if a not in P: print(a); exit()
    a = x + d
    if a not in P: print(a); exit()

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
P = set(map(int, input().split()))

for diff in range(1000):
  if X - diff not in P:
    print(X - diff)
    break
  elif X + diff not in P:
    print(X + diff)
    break

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
x, n = map(int, input(). split())
l = [0]*n
m = [0]*200
ans = 0
p = list()
if n > 0:
  p = list(map(int, input(). split()))
else:
  print(x)
  sys.exit()
for i in range(n):
  l[i] = abs(x-p[i])
  m[l[i]] += 1
if m[0] == 0:
  print(x)
else:
  for j in range(1, 200):
    if m[j] != 2:
      a = x-j
      A = x+j
      b = p.count(a)
      B = p.count(b)
      if b == 0:
        ans = a
      else:
        ans = A
      break
  print(ans)

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
l = [int(x) for x in input().split()]
mp = [False]*101
for i in range(n):
    mp[l[i]] = True

#xがリストになければ
if(mp[x]==False):
    print(x)
    exit()

#xより小さい整数 (x-1)から0まで
for i in range(x-1,-1,-1):
    if(i==0):
        bottom_savei = 0
        bottom_abs = abs(x) 
        break
    if(mp[i]==False):
        bottom_savei = i
        bottom_abs = abs(x-i)
        break

#xより大きい整数 (x+1)から101まで
for i in range(x+1,102):
    if(i==101):
        top_savei = 101
        top_abs = abs(101 - x)
        break
    if(mp[i]==False):
        top_savei = i
        top_abs = abs(x-i)
        break
    
if(bottom_abs <= top_abs):
    print(bottom_savei)
else:
    print(top_savei)

Submission status: Accepted

Solution code:
x, n = map(int, input(). split())
m = [0]*200
ans = 0
if n > 0:
  p = list(map(int, input(). split()))
else:
  print(x)
  quit()
for i in range(n):
  l = abs(x-p[i])
  m[l] += 1
if m[0] == 0:
  print(x)
else:
  for j in range(1, 200):
    if m[j] < 2:
      a = x-j
      A = x+j
      if a not in p:
        ans = a
      else:
        ans = A
      break
  print(ans)

Submission status: Accepted

Solution code:
import numpy as np
def read():
    return list(map(int, input().split()))
x, _ = read()
p = read()
rem = np.array(p) - x
count = 0
while True:
    if (-1) * count not in rem:
        print(x - count)
        break
    if count not in rem:
        print(x + count)
        break

    count += 1

Submission status: Accepted

Solution code:
x,y = map(int,input().split())
l = list(map(int,input().split()))

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

for i in range(200):
    if not((x - i) in l):
        print(x - i)
        exit()

    elif not((x + i) in l):
        print(x + i)
        exit()

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
if n == 0:
    print(x)
    exit()
P = [*map(int, input().split())]
ans = x
d = 1000000000
for c in range(101+1): # candidate:[0,101]
    ok = True
    for p in P:
        if p == c:
            ok = False
            break
    if ok:
        if d > abs(x - c):
            d = abs(x - c)
            ans = c
print(ans)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
if(m>0):
  l = list(map(int,input().split()))
  i=n
  j=n
  while(i in l):
    i-=1
  while(j in l):
    j+=1
  if(abs(n-i)<abs(n-j)): print(i)
  elif(abs(n-i)>abs(n-j)): print(j)
  else: print(min(i,j))
else: print(n)

Submission status: Accepted

Solution code:
import sys, os, math, bisect, itertools, collections, heapq, queue
from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict

# import fractions

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    X, N = il()
    P = il()

    if len(P) == 0:
        print(X)
        exit()

    mx = max(P)
    p = MAX
    ret = 0
    for n in range(mx + 2):
        if n not in P and p > abs(X - n):
            ret = n
            p = X - n
    print(ret)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def fun(x):
  var=1
  first=0
  while True:
     if (x-var) not in n:
        first +=(x-var)
        # print("var is",var)
        return var
    
     var +=1

def funco(x):
  var=1
  first=0
  while True:
     if (x-var) not in n:
        first +=(x-var)
        # print("var is",var)
        return first
    
     var +=1
      
      

    

def fun2(x):
  var=1
  second=0
  while True:
    if (x+var) not in n:
       second +=(x+var)
      #  print("var is",var)
       return var

    var +=1

def fun2co(x):
  var=1
  second=0
  while True:
    if (x+var) not in n:
       second +=(x+var)
      #  print("var is",var)
       return second

    var +=1


def main(x):
  if x not in n:
    print(x)
    return
  s=(fun(x))
  t=(fun2(x))
  # print(s)
  # print(t)
  if s>t:
    print(fun2co(x))
  else:
    print(funco(x))

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


if x[1]<=0:
  print(x[0])

else:
  n=list(map(int,input().split()))
  main(x[0])
# n.append(x[0])
# print(sorted(n))

Submission status: Accepted

Solution code:
X, N = [int(i) for i in input().split()]
if N == 0:
    print(X)
else:
    Ps = set([int(i) for i in input().split()])

    # 間違い。なぜ...？？？
    if X not in Ps:
        print(X)
        exit(0)

    # print(f'{X} {sorted(Ps)}')
    diff = 0
    while True:
        a = X - diff
        if a not in Ps:
            print(a)
            break
        a = X + diff
        if a not in Ps:
            print(a)
            break
        diff += 1

Submission status: Accepted

Solution code:
X, N = map(int,input().split(' '))
if N == 0:
    print(X)
    exit()

p = input().split(' ')
p =[int(i) for i in p]
if X not in p:
    print(X)
    exit()

num_list = [int(i) for i in range(102)]
[num_list.remove(p[i]) for i in range(N)]
tmp = [0] * int(len(num_list))


for i in range(len(num_list)):
    tmp[i] = abs(num_list[i] - X)

ans = tmp.index(min(tmp))

print(num_list[ans])

Submission status: Accepted

Solution code:

X,N=[int(x) for x in input().rstrip().split()]
p=[int(x) for x in input().rstrip().split()]
nai=[]
for i in range(0,102):
  if i not in p:
    nai.append(i)

nai.append(X)
nai.sort()
ind = nai.index(X)
if abs(nai[ind-1]-X)<=abs(nai[ind+1]-X):
  print(nai[ind-1])
else:
  print(nai[ind+1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
p = list(map(int,input().split()))
flag = [True] * 102

for i in p:
    flag[i] = False

for i in range(101):
    low = max(x-i, 0)
    high = min(x+i, 101)
    if flag[low]:
        print(low)
        break
    elif flag[high]:
        print(high)
        break

Submission status: Accepted

Solution code:
X ,N = [int(i) for i in input().split()]
N_list = [int(n) for n in input().split()]
count = 0
while(True):
    if not X-count in N_list:
        min_abs = X - count
        break
    elif not X+count in N_list:
        min_abs = X + count
        break
    count += 1
print(min_abs)

Submission status: Accepted

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

p = set(p)

diff = 101
indx = 0
ans = (101, 0)
if n != 0:
    for now in range(0, 102):
        if now not in p:
            now_diff = abs(now - x)
            ans = min(ans, (now_diff, now))
    print(ans[1])
else:
    print(x)

Submission status: Accepted

Solution code:
a = input().split()
b = int(a[0])
c = int(a[1])
if c == 0:
    print(b)
    
else:
    d = [int(i) for i in input().split()]
    e = sorted(d)


    f = int(e[0]-1)
    g = int(e[-1]+1)


    h = int(g-f)

    X = []
    for I in range(int(h+1)):
        J = int(f+I)
        if e.count(J) == 0:
            X.append(J)

    Y = len(X)
    H = []
    for S in range(Y):
        Q = X[S]
        if Q>=b:
            g = Q-b
            H.append(g)
        elif Q<=b:
            g = b-Q
            H.append(g)
    
    P = sorted(H)
    F = P[0]
    O = H.index(F)


    print(X[O])

Submission status: Accepted

Solution code:
X, N, *d = map(int, open(0).read().split())
if N == 0:
    print(X)
else:
    ans = -100
    for i in range(102):
        if i not in d and abs(i - X) < abs(ans - X):
            ans = i

    print(ans)

Submission status: Accepted

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

p = set(p)

diff = 101
indx = 0
if n != 0:
    for now in range(0, 102):
        if now not in p:
            now_diff = abs(now - x)
            if diff > now_diff:
                diff = now_diff
                indx = now
            else:
                break
    print(indx)
else:
    print(x)

Submission status: Accepted

Solution code:
X, N = [int(i) for i in input().split()]
if N == 0:
# if False:
    print(X)
else:
    Ps = set([int(i) for i in input().split()])
    # if not X in Ps:
    #     print(X)

    # print(f'{X} {sorted(Ps)}')
    diff = 0
    while True:
        a = X - diff
        if a not in Ps:
            print(a)
            break
        a = X + diff
        if a not in Ps:
            print(a)
            break
        diff += 1

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
if n == 0:
  print(x)
  quit()
lis = list(map(int,input().split()))
ans = 9999999
for y in range(x-101,x+101):
  if not(y in lis) and abs(x - y) < abs(x - ans):
    ans = y
  if not(y in lis) and abs(x - y) == abs(x - ans):
    if ans > y:
      ans = y
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

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


l = x
h = x

while True:
    if l not in p:
        break
    else:
        l -= 1

while True:
    if h not in p:
        break
    else:
        h += 1

if (x - l) <= (h - x):
    print(l)
else:
    print(h)

Submission status: Accepted

Solution code:
X,N = (int(i) for i in input().split())
p_list=[int(i) for i in input().split()]
for i in range(0,200):
    if p_list==[]:
        print(str(X))
        break
    if i%2==1:
        X-=i
        if X not in p_list:
            print(str(X))
            break
    elif i%2==0:
        X+=i
        if X not in p_list:
            print(str(X))
            break

Submission status: Accepted

Solution code:
x, y = map(int, input().split())
p = list(map(int, input().split()))
# 100まではOK
for diff in range(101):
    # xを軸に小さい数
    a = x - diff
    # pのなかに含まれない整数aだからnot in
    if a not in p:
        print(a)
        exit()
    # xを軸に大きい数
    a = x + diff
    if a not in p:
        print(a)
        exit()

Submission status: Accepted

Solution code:
nii=lambda:map(int,input().split())
lnii=lambda:list(map(int,input().split()))

x,n=nii()
p=lnii()

dist=1000
ans=1000
for i in range(101,-1,-1):
  if i not in p:
    t_dist=abs(x-i)
    if t_dist<=dist:
      dist=t_dist
      ans=i
print(ans)

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
if N == 0:
  print(X)
  exit()
p = list(map(int, input().split()))
numlist = []

for i in range(102):
  if not i in p:
    numlist.append(i)
m = 500
for j in numlist:
  sa = abs(X-j)
  if sa < m:
    m = sa
    num = j

print(num)

Submission status: Accepted

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

p = list(map(int, input().split()))
l = []
for i in range(-100,102):
  l.append(i)

L = []
for i in l:
  if i not in p:
    L.append(i)

l = []
for i in L:
  l.append([i, abs(x-i)])
a = min(l, key = lambda t: t[1])
print(list(a)[0])

Submission status: Accepted

Solution code:
x,n,*p=map(int,open(0).read().split())
print(min({*range(999)}-{*p},key=lambda y:abs(y-x)))

Submission status: Accepted

Solution code:
from typing import List


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

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

    p_lst: List[int] = list(map(int, input().split()))

    for i in range(51):
        if X - i not in p_lst:
            print(X - i)
            exit()
        if X + i not in p_lst:
            print(X + i)
            exit()


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import numpy as np
lis=[]
for i in range(102):
    lis.append(i)
#print(lis)
listA=[]
while True:
    try:
        listA.append(list(map(int,input().split())))
    except:
        break;
#print(listA)
 
X_=listA[0]
X=X_[0]
N=X_[1]
if N!=0:
    P =listA[1]
 
    arr = np.array(lis)
    P_max = max(P)
    P_min = min(P)-1
    arr=arr[arr<=P_max+1]
    arr=arr[arr>=P_min-1]
    lis=arr.tolist()
    for p in P:
        lis.remove(p)
    #print(lis)
    lis_=[]
    for l in lis:
        lis_.append(abs(l-X))
    #print(lis_)
    lis_min=min(lis_)
 
    def my_index(l, x, default=False):
        if x in l:
            return l.index(x)
        else:
            return default
 
    print(lis[my_index(lis_, lis_min)])
else:
    print(X)

Submission status: Accepted

Solution code:
def solve():
    X, N = map(int,input().split())
    p = set(map(int,input().split()))

    ans = float('inf')
    for i in range(102):
        if not i in p:
            if abs(ans-X) > abs(i-X):
                ans = i
    
    print(ans)

if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
def main():
    k = [int(i) for i in input().split()]
    x = k[0]
    n = k[1]
    if(n==0):
        print(x)
        return 0
        
    nums = [int(i) for i in input().split()]
    
    a=x
    b=x
    
    while(True):
        if(a not in nums):
            print(a)
            break
        if(b not in nums):
            print(b)
            break
        a-=1
        b+=1
    return 0
    
main()

Submission status: Accepted

Solution code:
def solve():
    X,N = map(int, raw_input().split())
    if N == 0:
        return  X

    P = map(int, raw_input().split())
    P = sorted(P)
    x = P[-1]
    for p in P:
        if X <= p:
            x = p
            break

    m = 1000000
    ans = 0
    for i in range(x-110, x+110):
        if i not in P:
            d = abs(X - i)
            if d < m:
                m = d
                ans = i
    return ans

print solve()

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
if n!=0:
  li=list(map(int,input().split()))
else:
  li=[]
z=0

while True:
  if x-z not in li:
    print(x-z)
    break
  if x+z not in li:
    print(x+z)
    break
  z+=1

Submission status: Accepted

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

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

ans = -2
dif = 1000
for i in range(-1,102):
    if(i in p):
        continue
    dif_i = abs(i-x)
    if(dif > dif_i):
        dif = dif_i
        ans = i

print(ans)

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
if n==0:
  print(x)
else:
  a=list(map(int,input().split()))
  ans=-1
  for i in range(0,102):
    if i not in a and abs(i-x)<abs(ans-x):
      ans=i
  print(ans)

Submission status: Accepted

Solution code:
X,N = [int(i) for i in input().split()]
p = sorted([int(i) for i in input().split()], key=lambda x: x) if N > 0 else [0]

diffMin = 10**9 
minNum = -10**9
for i in range(0, 100+1+1):
  if i not in p and diffMin > abs( X-i ) :
     diffMin = min(diffMin,abs( X-i ))
     minNum = i
print(minNum)

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
l=list(map(int,input().split()))
if x not in l:
    print(x)
elif n==0:
    print(x)
else:
    a=101
    p1=0
    for i in range(102):
        if i not in l:
            if abs(x-i)<a:
                a=abs(x-i)
                p1=i

    print(p1)

Submission status: Accepted

Solution code:
import sys

x,n = map(int, input().split())
p = sorted(list(map(int, input().split())))
res = [x,-1]
for i in range(101):
    a = x - i
    b = x + i
    if a not in p:
        print(a)
        sys.exit()
    if b not in p:
        print(b)
        sys.exit()

Submission status: Accepted

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

for i in range(101):
    a = x - i
    b = x + i

    if a not in p:
        print(a)
        exit()
    elif b not in p:
        print(b)
        exit()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

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

d = [0 for _ in range(201)]
for i in range(-100, 101):
    d[i+100] = i+1 

for i in p:
    d.remove(i)

d2 = [0 for _ in range(len(d))]
for i in range(len(d)):
    d2[i] = abs(d[i]-x)

m = 10000
for i in reversed(range(len(d2))):
    if d2[i] <= m:
        m = d2[i]
        tmpi = i 

print(d[tmpi])

Submission status: Accepted

Solution code:
from typing import List


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

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

    p_lst: List[int] = list(map(int, input().split()))

    for i in range(100):
        if X - i not in p_lst:
            print(X - i)
            exit()
        if X + i not in p_lst:
            print(X + i)
            exit()


if __name__ == "__main__":
    main()

Submission status: Accepted

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

C = list({i for i in range(0, 101+1)} - set(P))
C.sort()
dist = float('inf')
result = None
for i in C:
    if abs(X - i) < dist:
        result = i
        dist = abs(X - i)

print(result)

Submission status: Accepted

Solution code:
try:
  x,n = list(map(int, input().split()))
  ps  = list(map(int, input().split()))
  #print(x)
  #print(n)
  #print(ps)
  
  if not (x in ps):
    print(x)
    exit(0)
  
  for item in range(1,101):
    if not x-item in ps:
      print(x-item)
      exit(0)
    elif not x+item in ps:
      print(x+item)
      exit(0)
except EOFError:
  print(x)

Submission status: Accepted

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

all = set(range(0, 102))
kouho = all - set(P)

min_dis = 200
for i in kouho:
    dis = abs(i-X)
    if min_dis > dis:
        min_i = i
        min_dis = dis

print(min_i)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    X, N = map(int, input().split())
    P = list(map(int, input().split()))
    if N == 0:
        print(X)
        return
    diff = 100
    ans = -1
    for i in range(102):
        if i in P:
            continue
        d = abs(i - X)
        if d < diff:
            diff = d
            ans = i
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
a,b=map(int,input().split())
s = list(map(int, input().split()))
t = 0
h = 0
if b ==0:
    print(a)
else:
    for i in range(a,a+2+b):
        if not i in s:
            t = i
            break
    for i in range(a-1,a-2-b,-1):
        if not i in s:
            h = i
            break
    if abs(t-a)>=abs(h-a):
        print (h)
    else:
        print(t)

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
if n == 0:print(x);exit(0)
*p, = sorted(map(int,input().split()))
pp = set(p)
ans = 9e9
for i in range(0,102):
    if i in pp: continue
    if abs(i-x) < ans:
        xx = i
        ans = abs(i-x)
    else:
        break
print(xx)

Submission status: Accepted

Solution code:
from math import *
x,n=map(int,input().split())
a=[int(x) for x in input().split()]
s=[i for i in range(-100,105)]
s=set(s)-set(a)
s=list(s)
s.sort()
dif=10**18
#a.sort()
ans=s[0]
for i in range(len(s)):
	if abs(s[i]-x)<dif:
		dif=abs(s[i]-x)
		ans=s[i]
print(ans)

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
p=list(map(int,input().split()))
p.sort()
ans=float('inf')
cnt=0
for i in range(0,110):
    if not i in p:
        if ans>abs(x-i):
            cnt=i
            ans=abs(x-i)

print(cnt)

Submission status: Accepted

Solution code:
X,N = map(int,input().split())
n = list(map(int,input().split()))
xn = list(range(0,102))
answer = 0
for i in range(N):
  xn.remove(n[i])
mindis = 100
for i in range(len(xn)):
  dis = abs(X-xn[i])
  if dis < mindis:
    mindis = dis
    answer = xn[i]
print(answer)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import itertools
from decimal import *

input = sys.stdin.readline

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
def inputStr(): return input()[:-1]

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

def main():
	X,N = inputMap()
	p = inputList()

	sa = inf
	pointer = 0
	for i in range(200,-100,-1):
		if i in p:
			continue
		tmp = abs(X-i)
		if tmp <= sa:
			sa = tmp
			pointer = i

	if sa == inf:
		if X > 50:
			print(101)
		else:
			print(0)
	else:
		print(pointer)


#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
from collections import defaultdict

x, n = map(int, input().split())
p = list(map(int, input().split()))
h = defaultdict(lambda: False)
for i in p:
    h[i] = True
i = 0
while True:
    if not h[x - i]:
        print(x - i)
        break
    if not h[x + i]:
        print(x + i)
        break
    i += 1

Submission status: Accepted

Solution code:
def main():
    import sys
    read = sys.stdin.buffer.read
    readline = sys.stdin.buffer.readline
    readlines = sys.stdin.buffer.readlines
    sys.setrecursionlimit(10 ** 7)

    x, n = map(int, readline().split())
    p = list(map(int, readline().split()))
    check = float('inf')
    ans = 0
    for i in range(102):
        if i not in p:
            if check > abs(x - i):
                ans = i
                check = abs(x - i)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
arr = sorted(list(map(int, input().split())))
mins = 10000
idx = 0
for i in range(0, 102):
    if abs(x-i) < mins and i not in arr:
        mins = abs(x-i)
        idx = i
print(idx)

Submission status: Accepted

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

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

if x <= 50:
    minp = x
    minv = 0
    p.sort()
else:
    minp = abs(101 - x)
    minv = 101
    p.sort(reverse=True)

if n == 0:
    print(x)
elif n == 100:
    if x <= abs(101 - x):
        print(0)
    else:
        print(101)
else:
    for i in range(1, 101):
        if i in p:
            continue
        else:
            if abs(i - x) < minp:
                minp = abs(i - x)
                minv = i
            elif abs(i - x) == minp:
                if (minv > i):
                    minv = i
    print(minv)

Submission status: Accepted

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

    ans = min(
        (i for i in range(0, 102) if i not in P),
        key=lambda x: abs(X - x)
    )
    print(ans)


if __name__ == '__main__':
    main()