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:
import bisect

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

A = {i for i in range(102)}

S = list(A - P)

T = bisect.bisect_left(S, X)

if T == 0:
    print(S[0])
elif X - S[T-1] > S[T] - X:
    print(S[T])
else:
    print(S[T-1])

Submission status: Accepted

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

for i in range(x+1):
    for j in [-1, 1]:
        ans = x + i*j
        if not p.count(ans):
            print(ans)
            exit(0)

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
try:
  p=sorted([*map(int,input().split())])
except:
  print(x);exit()
for i in range(x+1):
  for s in [-1,1]:
    a=x+i*s
    if p.count(a)==0:
      print(a);exit()

Submission status: Accepted

Solution code:
# from sys import stdin
# input = stdin.readline
from collections import Counter

def solve():
    x,n = map(int,input().split())
    if n != 0:
        p = set(map(int,input().split()))
    if n == 0 or x not in p:
        print(x)
        return
    else:
        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__':
    solve()

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
p=list(map(int,input().split()))
num1=0
num2=0
if(n==0):
    print(x)
    exit()
for i in range(100):
    num1=x-i
    num2=x+i
    if(not num1 in p and not num2 in p):
        print(num1)
        exit()
    elif(not num2 in p):
        print(num2)
        exit()
    elif(not num1 in p):
        print(num1)
        exit()

Submission status: Accepted

Solution code:
a,b = map(int,input().split())
s = list(map(int,input().split()))
num1 =0
num2 =0
if b ==0:
  print(a)
  exit()
for i in range(100):
    num1 = a-i
    num2 = a+i
    if not num1 in s and not num2 in s:
        print(num1)
        exit()
    if not num1 in s:
        print(num1)
        exit()
    if not num2 in s:
        print(num2)
        exit()

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x,n= map(int,input().split())
p = list(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
    else:
        i+=1
        continue
print(ans)

Submission status: Accepted

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

min_val = 101
for i in range(102):
    if i not in p:
        if abs(i - x) < min_val:
            min_val = abs(i - x)
            ans = i
print(ans)

Submission status: Accepted

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

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

count = 0

flg = False

lis=[]

result=0

while True:
    
    up = X+count
    
    down = X-count
    
    if p.count(down) ==0:
        lis.append(down)
        flg = True
    
    if p.count(up)==0:
        lis.append(up)
        flg = True
        
    
    if flg ==True:
        break
    else:
        count+=1
        

lis.sort()

print(lis[0])

Submission status: Accepted

Solution code:
from bisect import bisect

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

for i in range(100):
    if not(x-i in p):
        print(x-i)
        break
    if not(x+i in p):
        print(x+i)
        break

Submission status: Accepted

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

if(n):
    l = [0 for _ in range(102)]
    for i in p:
        l[i] = 1

    for i in range(101):
        if(l[x-i] == 0):
            ans = x-i
            break
        if(l[x+i] == 0):
            ans = x+i
            break
    print(ans)
else:
    print(x)

Submission status: Accepted

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

mind = 10**10
ans = -102
for i in range(-101, 102):
    dist = abs(X - i)
    if mind > dist:
        if i not in pi:
            ans = i
            mind = dist


print(ans)

Submission status: Accepted

Solution code:
def ri():
    return int(input())


def rii():
    return [int(v) for v in input().split()]


def solve():
    X, N = rii()
    P = set(rii())
    n = m = float("inf")
    if not P:
        print(X)
        return

    for i in range(min(P)-1, max(P)+2):
        if i not in P:
            d = abs(i - X)
            if d == m:
                n = min(n, i)
            elif d < m:
                m = d
                n = i
    
    print(n)



if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
X, N = map(int,input().split())
if N == 0:
  P = []
else:
  P = list(map(int, input().split()))
  P = sorted(P)
assert len(P) == N
cands = []
# 下側検索
x = X
while True:
  if x not in P:
    cands.append(x)
    break
  x -= 1
# 上側検索
x = X
while True:
  if x not in P:
    cands.append(x)
    break
  x += 1
a,b = cands
if abs(a - X) > abs(b - X):
  print(b)
else:
  print(a)

Submission status: Accepted

Solution code:
x,_ = list(map(int,input().split()))
p = list(map(int,input().split()))
x_l = x
x_u = x
while(True):
    if(not x_l in p):
        print(x_l)
        break
    if(not x_u in p):
        print(x_u)
        break
    x_l -= 1
    x_u += 1

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
p=list(map(int,input().split()))
a=101
m=101-x
for i in range(102):
  i=100-i
  if i in p:
    continue
  M=abs(i-x)
  if M<=m:
    m=M
    a=i
print(a)

Submission status: Accepted

Solution code:
X,N = map(int, input().split())
flg=False
i=1

if N==0:
  Ans=X
else:
  S=list(map(int, input().split()))
#  S.sort()
  if X not in S:
    Ans=X
    flg=True
    
  while not flg:
    if X-i not in S:
      Ans=X-i
      flg=True
      break
    elif X+i not in S:
      Ans=X+i
      flg=True
      break
    else:
      i+=1
      
print(Ans)

Submission status: Accepted

Solution code:
""" 170/C
"""
import sys
import math
from functools import reduce
from bisect import bisect_left

def readString():
    return sys.stdin.readline()

def readInteger():
    return int(readString())

def readStringSet(n):
    return sys.stdin.readline().split(" ")[:n]

def readIntegerSet(n):
    return list(map(int, readStringSet(n)))

def readIntegerMatrix(n, m):
    return [lambda _: readIntegerSet(m) for _ in range(0, n)]

def main(X, N, P):
    mP = {}
    for p in P:
        mP[p] = p

    if X not in mP:
        return X

    i = 0
    while True:
        if X-i not in mP:
            return X-i

        if X+i not in mP:
            return X+i

        i += 1


if __name__ == "__main__":
    _X, _N = readIntegerSet(2)
    _P = readIntegerSet(_N)

    print(main(_X, _N, _P))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
X,N = (int(x) for x in input().split())
p = sorted(list((int(x) for x in input().split())))
if N == 0:
  print(X)
elif N == 1:
  if p[0] == X:
    print(X-1)
  else:
    print(X)
else:
  ans = float('inf')
  for z in range(0,p[0]):
    if (ans-X)**2 > (z-X)**2 :
      ans = z
  for i in range(N-1):
    for z in range(p[i]+1,p[i+1]):
      if (ans-X)**2 > (z-X)**2 :
      	ans = z
  for z in range(p[-1]+1,102):
    if (ans-X)**2 > (z-X)**2 :
      ans = z
  print(ans)

Submission status: Accepted

Solution code:
x, n = map(int,input().split())
l = list(map(int,input().split()))
a = 0
ab = 0
for i in range(100):
    if x - i not in l:
        ans = x - i
        a = i + 1
        break
for i in range(100):
    if x + i not in l:
        ansb = x + i
        ab = i + 1
        break
if a > ab:
    print(ansb)
else:
    print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
readline = stdin.readline
def i_input(): return int(readline().rstrip())
def i_map(): return map(int, readline().rstrip().split())
def i_list(): return list(i_map())

def main():
    X, N = i_map()
    if N == 0:
        print(X)
        exit()
    P = i_list()
    p = list(map(lambda x: abs(x - X), P))
    p.sort()
    for i, j in enumerate(p, 1):
        if i // 2 != j:
            ans = X - (i // 2)
            if ans in P:
                ans = X + (i // 2)
            break
    else:
        if N % 2 == 1:
            ans = X - ((N + 1) // 2)
        else:
            ans = X - (N // 2)
            if ans in P:
                ans = X + (N // 2)
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = list(map(int,input().split()))
p.sort()
s = x
d = 1
while s in p:
    s = s - d
    d = int((abs(d)+1)*d/abs(d)*(-1))
print(s)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = list(map(int,input().split()))
s = x
d = 1
while s in p:
    s = s - d
    d = int((abs(d)+1)*d/abs(d)*(-1))
print(s)

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
l=list(map(int,input().split()))
a=0
for i in range(100):
    if x-i not in l:
        ans=x-i
        a=i+1
        break
for i in range(100):
    if x+i not in l:
        ansb=x+i
        ab=i+1
        break
if a>ab:
    print(ansb)
else:
    print(ans)

Submission status: Accepted

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

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

count = 0

flg = False

lis=[]

result=0

while True:
    
    up = X+count
    
    down = X-count
    
    if p.count(down) ==0:
        lis.append(down)
        flg = True
    
    if p.count(up)==0:
        lis.append(up)
        flg = True
        
    
    if flg ==True:
        break
    else:
        count+=1
        

lis.sort()

print(lis[0])

Submission status: Accepted

Solution code:
#                               #
    # author : samars_diary #
    # 18-09-2020 │ 19:20:45 #
#                               #

import sys, os.path

#if(os.path.exists('input.txt')):
    #sys.stdin = open('input.txt',"r")
    #sys.stdout = open('output.txt',"w")

sys.setrecursionlimit(10 ** 5)

def mod(): return 10**9+7
def i(): return sys.stdin.readline().strip()
def ii(): return int(sys.stdin.readline())
def li(): return list(sys.stdin.readline().strip())
def mii(): return map(int, sys.stdin.readline().split())
def lii(): return list(map(int, sys.stdin.readline().strip().split()))

#print=sys.stdout.write

def solve():
    a,b=mii()
    if b==0: print(a) ; return
    c=lii();d=111;e=0
    for i in range(max(c)+2):
        if i not in c:
            if abs(i-a)<d:
                d=abs(i-a)
                e=i
    print(e)
                
for _ in range(1):
    solve()

Submission status: Accepted

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

l, r = X, X
ans = float("inf")
while True:
    if l not in forbid:
        ans = l
        break
    if r not in forbid:
        ans = r
        break
    l -= 1
    r += 1

print(ans)

Submission status: Accepted

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

sa_min=100

"""
sa=[]
for i in range(N):
    sa.append(p[i]-X)
"""

for i in range(102):
    if sa_min>abs(i-X) and (not i in p):
        sa_min=abs(i-X)
        ans=i

if N==0:ans=X

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
li_p = list(map(int, input().split()))
li_p.sort()
i = 0
while True:
    a = x - i
    b = x + i
    if not a in li_p:
        print(a)
        break
    elif a in li_p and not b in li_p:
        print(b)
        break
    elif a in li_p and b in li_p:
        i += 1

Submission status: Accepted

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

if n == 0 or x not in L:
  print(x)
  exit()

for i in range(102):
  if (x-i) not in L:
    print(x-i)
    break
  elif (x+i) not in L:
    print(x+i)
    break

Submission status: Accepted

Solution code:
x, n = map(int,input().split())
L = list(map(int,input().split()))
l, r = x-1, x+1

if n == 0 or x not in L:
  print(x)
  exit()

while True:
  if l not in L:
    print(l)
    break
  elif r not in L:
    print(r)
    break
  l -= 1
  r += 1

Submission status: Accepted

Solution code:
x, n = map(int,input().split())
L = list(map(int,input().split()))
l, r = x-1, x+1

if n == 0 or x not in L:
  print(x)
  exit()

while True:
  flg = True
  if l not in L:
    print(l)
    break
  elif r not in L:
    print(r)
    break
  l -= 1
  r += 1

Submission status: Accepted

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

if N ==0 or X < min(p) or X > max(p):
    print(X)
else:
    for n in range(N+1):
        if not X - n in p:
            print(X - n)
            break
        elif not X + n in p:
            print(X + n)
            break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#C問題

#ループ処理をスキップするコード→break,continue,return(関数方式)
x, n = map(int, input().split())
P = list(map(int, input().split()))
xm = x 
xM = x

for i in range(0,100):
    if n == 0:
        print(x)
        break
    xm = x - i
    xM = x + i
    mcounter = 0
    Mcounter = 0
    for j in range(len(P)):
        if xm == P[j]:
            mcounter += 1000
        if xM == P[j]:
            Mcounter += 1000
    if mcounter < 1000:
        print(xm)
        break
    if Mcounter < 1000:
        print(xM)
        break

Submission status: Accepted

Solution code:
import bisect

X, N = map(int,input().split())
if N == 0:
    Ps = []
else:
    Ps = list(map(int,input().split()))
Ps.sort()
for i in range(300):
    if i % 2 == 0:
        x = i//2
    else:
        x = -((i+1)//2)
    if (X + x) in Ps:
        continue
    else:
        print(X + x)
        break

Submission status: Accepted

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

min =10000
temp = 0
num = 10000

for i in range(-1000, 1000):
  temp = abs(x- i)
  
  if temp < min and i not in p:
    min = temp
    num = i
    
print(num)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = [int(v) for v in input().split()]
ans = None
if x not in p:
    ans = x
else:
    diff = 101
    for i in range(0, max(p) + 2):

        if abs(x - i) < diff and i not in p:
            ans = i
            diff = abs(x - i)
print(ans)

Submission status: Accepted

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

ans = None
diff = 1000

if X not in p:
    ans = X
else:
    for i in range(-1, max(max(p), X)+2):
        if i in p:continue
        if abs(X - i) < diff:
            diff = abs(X - i)
            ans = i

print(ans)

Submission status: Accepted

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

def INT(): return int(input())
def MAPINT(): return map(int, input().split())
def LMAPINT(): return list(map(int, input().split()))
def STR(): return input()
def MAPSTR(): return map(str, input().split())
def LMAPSTR(): return list(map(str, input().split()))

f_inf = float('inf')

x, n = LMAPINT()
if n == 0:
  _ = input()
  print(x)
  exit()

p = LMAPINT()
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()))

p.sort()

def main():

    if len(p) == 0:
        print(X)
        return

    if X < p[0] and p[-1] < X:
        print(X)

    keep = True
    i = 0
    while keep:
        left_found = (X - i) not in p
        right_found = (X + i) not in p

        if left_found and right_found:
            print(X-i)
            keep = False
        elif left_found:
            print(X-i)
            keep = False
        elif right_found:
            print(X+i)
            keep = False


        i += 1


if __name__ == '__main__':
    main()

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 i not in list(p):
        if abs(x-i)<abs(x-ans):
            ans = i

print(ans)

Submission status: Accepted

Solution code:
m, n = map(int, input().split())
p = list(map(int, input().split()))
a=0

while True:
    if m-a not in p:
        print(m-a)
        break
    elif m+a not in p:
        print(m+a)
        break
    a+=1

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 i not in p:
        if abs(X-i)<abs(X-ans):
            ans=i
print(ans)

Submission status: Accepted

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


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

a = 0


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

Submission status: Accepted

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

for i in range(100):
    num = x - i
    if num not in p:
        print(num)
        exit()
    num = x + i
    if num not in p:
        print(num)
        exit()

Submission status: Accepted

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

gap = x
ans = 0

for y in range(102):
  if y not in p:
    if abs(x - y) < gap:
      gap = abs(x-y)
      ans = y
print(ans)

Submission status: Accepted

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

gap = x
ans = 0

for y in range(0,102):
  if y not in p:
    if abs(x - y) < gap:
      gap = abs(x-y)
      ans = y
      
print(ans)

Submission status: Accepted

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

m=X;i=0
for i in range(m,min(p)-2,-1):
  if i not in p:break
M=X;j=0
for j in range(M,max(p)+2):
  if j not in p:break
if abs(i-X)==abs(j-X):print(min(i,j))
elif abs(i-X)<abs(j-X):
  print(i)
else:print(j)

Submission status: Accepted

Solution code:
import bisect
X, N=map(int, input().split())
if N==0:print(X);exit()
p=sorted(list(map(int, input().split())))
#print(p)
m=min(p)-1
M=max(p)+1
#for i in range(m,M+1):
#  p.append(i)
#p=sorted(p)
m=X;i=0
for i in range(m,min(p)-2,-1):
  if i not in p:break
M=X;j=0
for j in range(M,max(p)+2):
  if j not in p:break
if abs(i-X)==abs(j-X):print(min(i,j))
elif abs(i-X)<abs(j-X):
  print(i)
else:print(j)

Submission status: Accepted

Solution code:
import math
X, N = map(int, input().split())
P = list(map(int, input().split()))
ans_1 = X
ans_2 = X
while True:
    if ans_1 not in P:
        print(ans_1)
        exit()
    ans_1 -= 1

    if ans_2 not in P:
        print(ans_2)
        exit()
    ans_2 += 1

Submission status: Accepted

Solution code:
def main():
    X, N = map(int, input().split())
    if N == 0:
        print(X)
        return

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

    if not X in P:
        print(X)
        return
    
    for i in range(1, 10000):
        if not X-i in P:
            print(X-i)
            return
        if not X+i in P:
            print(X+i)
            return

main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def main():
    x, n = map(int, input().split())
    ps = list(map(int, input().split()))

    for i in range(n//2 + 2):
        if x - i not in ps:
            print(x-i)
            return
        if x + i not in ps:
            print(x+i)
            return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    X,N=MI()
    P=set(LI())

    for i in range(N+1):
        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())
p = list(map(int,input().split()))

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

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
p=list(map(int,input().split()))
y=x
z=x
if x not in p:
    print(x)
    exit()
for i in range(2*len(p)):
    y-=1
    z+=1
    if y not in p:
        print(y)
        exit()
    if z not in p:
        print(z)
        exit()

Submission status: Accepted

Solution code:
import bisect
X, N = map(int, input().split())
if N == 0:
    print(X)
else:
    p = set(map(int, input().split()))
    num_list = set([i for i in range(-1, 102)])
    num_list = sorted(list(num_list ^ p))
    nummin = num_list[bisect.bisect_left(num_list, X)]
    nummax = num_list[bisect.bisect_right(num_list, X)]
    if nummin == nummax:
        nummin = num_list[bisect.bisect_left(num_list, X)-1]
    if X-nummin <= nummax-X:
        print(nummin)
    else:
        print(nummax)

Submission status: Accepted

Solution code:
X,N = map(int,input().split())
p = list(map(int,input().split()))
count = -1
while True:
    count +=1
    if X-count not in p:
        print(X-count)
        break
    elif X+count not in p:
        print(X+count)
        break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
for i in range(n):
    if p[i] - x >= 0:
        p[i] = 2 * (p[i] - x)
    else:
        p[i] = (x - p[i]) * 2 - 1
p = sorted(p)
i = 0
while i in p:
    i += 1
if i % 2 == 0:
    j = round(i / 2) + x
else:
    j = x - round((i + 1) / 2)
print(j)

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
if n==0:
  print(x)
  exit()
p=[int(y) for y in input().split()]
a=0
for i in range(101):
  if x-a not in p:
    print(x-a)
    break
  elif x+a not in p:
    print(x+a)
    break
  a+=1

Submission status: Accepted

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

if P.count(X) == 0:
    print(X)
else:
    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

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
if n == 0:
  print(x)
  exit()
nums = list(map(int,input().split()))
cnt =0
while True:
  if x-cnt not in nums:
    print(x-cnt)
    break
  if x+cnt not in nums:
    print(x+cnt)
    break
  cnt +=1

Submission status: Accepted

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

l = [i for i in range(102)]

for j in p:
    l.remove(j)

m = []

for k in l:
    m.append(abs(k-x))

print(l[m.index(min(m))])

Submission status: Accepted

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

try:
    p = list(map(int, input().split()))
except:
    p = []
i = 0

while True:
    if X + i not in p:
        ans = X + i
        if X - i not in p:
            ans = X - i
        break
    if X - i not in p:
        ans = X - i
        break
    
    i += 1

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

max_num = max(p)
lst = []
for i in range(max_num+2):
  if i not in p:
    lst.append(i)
tmp = float("inf")
for j in lst:
  if tmp > abs(X-j):
    tmp = abs(X-j)
    ans = j
print(ans)

Submission status: Accepted

Solution code:
import math , sys

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

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

F = math.inf
ans = math.inf
B  =[]
for i in range( -2 , 102):
    if i not in A:
        B.append(i)
#print(A,B)
for i in range(len(B)):
    d = abs( X - B[i] )
    #print(B[i] , d)
    if d < F:
        F = d
        ans = B[i]
    elif d==F:
        if B[i] < ans:
            ans = B[i]
print(ans)

Submission status: Accepted

Solution code:
def main():
    x, n = map(int, input().split())
    if n == 0:
        print(x)
        return
    p_tuple = tuple(map(int, input().split()))

    radius = 0
    for i in range(100):
        if x-radius not in p_tuple:
            print(x-radius)
            return
        elif x+radius not in p_tuple:
            print(x+radius)
            return
        else:
            radius += 1


if __name__ == '__main__':
    main()

Submission status: Accepted

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

table = [0] * 102
ans = X
dist = 102

for p in P:
  table[p] = 1

for i in range(102):
  if table[i] != 0:
    continue
  if abs(i - X) < dist:
    ans = i
    dist = abs(i - X)
  elif abs(i - X) == dist:
    ans = min(i, ans)

print(str(ans))

Submission status: Accepted

Solution code:
X, N = map(int,input().split())
P = list(map(int,input().split()))
list = [0] * 102
res = X
dist = 102
for p in P:
    list[p] = 1
for i in range(102):
    if list[i] == 0:
        if abs(i - X) < dist:
            dist = abs(i - X)
            res = i
        elif abs(i - X) == dist:
            res = min(res,i)
print(res)

Submission status: Accepted

Solution code:
import numpy

x,n = map(int,input().split())
try:
    p = list(map(int,input().split()))
except EOFError:
    p =[]

a = numpy.abs(list(map(lambda z: z-x,p))).tolist()
if 0 not in a:
    print(x)
else:
    i = 1
    while i <= n:
        if a.count(i) == 2:
            i += 1
            continue
        elif a.count(i) == 1:
            if x+i not in p:
                print(x+i)
                break
        if x > 0:
            print(x-i)
        else:
            print(x+i)
        break

Submission status: Accepted

Solution code:
x,n = list(map(int, input().split()))
if n == 0:
    print(x)
else:
    p = list(map(int, input().split()))
    hoge = [i for i in range(x - n, x + n + 1)]
    sabun = list(set(hoge) - set(p))
    min_ = 300
    index_ = 0
    for i, v in enumerate(sabun):
        if abs(x - v) < min_:
            min_ = abs(x - v)
            index_ = i
    print(sabun[index_])

Submission status: Accepted

Solution code:
import bisect as bi

if __name__ == '__main__':

    x,n = map(int,input().split())
    A = list(map(int,input().split()))
    B = [i for i in range(102)]
    
    #差分を求める
    C = list(set(B) - set(A))

    #二分探索自身の位置を調べる
    ind = bi.bisect_left(C,x)

    if ind == 0:
        print(C[0])
    elif ind == x - n:
        print(C[ind])
    else:
        tmp_l = abs(C[ind-1] - x)
        tmp_r = abs(C[ind] - x)
        if tmp_l > tmp_r:
            print(C[ind])
        else:
            print(C[ind-1])

Submission status: Accepted

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

low=x
high=x
while True:
  if low not in p:
    print(low)
    break
  elif high not in p:
    print(high)
    break
  low-=1
  high+=1

Submission status: Accepted

Solution code:
X,N=map(int,input().split())
alist = list(map(int, input().split()))
for a in range(X+1):
    for b in [-1,+1]:
        c = X + a * b
        if alist.count(c) == 0:
            print(c)
            exit(0)