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

i = 0

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

candidates = []

x = X
while(True):
    if not x in p:
        candidates.append(x)
        break
    else:
        x += 1
x = X
while(True):
    if not x in p:
        candidates.append(x)
        break
    else:
        x -= 1

if abs(X-candidates[0]) == abs(X-candidates[1]):
    print(min(candidates))
elif abs(X-candidates[0]) > abs(X-candidates[1]):
    print(candidates[1])
else:
    print(candidates[0])

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
if n == 0:
  print(x)
  exit(0)
p = list(map(int, input().split()))
a = [i for i in range(201)]
b = sorted(list(set(a) - set(p)))
min_v = 1000
min_id = 0
for i in range(len(b)):
  if abs(x - b[i]) < min_v:
    min_v = abs(x - b[i])
    min_id = i
print(b[min_id])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

dist = 0

if N == 0:
    print(X)
    dist_max = -2
else:
    dist_max = max(abs(max(p) - X), abs(min(p) - X))

while dist <= dist_max+1:
    if (X - dist in p) and (X + dist in p):
        dist += 1
        continue

    if not (X - dist in p):
        print(X - dist)
        break
    elif not (X + dist in p):
        print(X + dist)
        break

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+1):
    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())
p = list(map(int, input().split()))
xp =x; xm =x
for i in range(n+1):
    if not (xm in p):
        print(xm)
        break
    if not (xp in p):
        print(xp)
        break
    xp += 1
    xm -= 1

Submission status: Accepted

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

differ = 0

while x+differ in p and x-differ in p:
    differ+=1

print(int(x-differ if x-differ not in p else x+differ))

Submission status: Accepted

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

sub = 10000
ans = 0
for i in range(-1000, 1001):
    y = X + i
    if y in P:
        continue
    if abs(i) < sub:
        sub = abs(i)
        ans = y
print(ans)

Submission status: Accepted

Solution code:
X, N = map(int, input().split(' '))
if N == 0:
    print(X)
else:
    P_ls = list(map(int, input().split(' ')))
    diff = -1
    for i in range(101, -1, -1):
        if i not in P_ls:
            if diff == -1:
                diff =  abs(X - i)
                rst = i
            else:
                diff = min(diff, abs(X - i))
                if diff == abs(X - i):
                    rst = i
    print(rst)

Submission status: Accepted

Solution code:
X,N=map(int,input().split())
p=list(map(int,input().split()))
for i in range(102):
    if (X-i)not in p:
        print(X-i)
        exit()
    elif (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()))
a = range(X-101,X,1)
a1 = sorted(a,reverse=True)
b = range(X,X+101,1)
A = []
B = []
for i in range(len(a1)):
    C = a1[i] not in P
    if C==True:
        A.append(a1[i])
    else:
        continue
for i in range(len(b)):
    D = b[i] not in P
    if D==True:
        B.append(b[i])
    else:
        continue
if X-A[0] <= B[0]-X:
    print(A[0])
else:
    print(B[0])

Submission status: Accepted

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

q=[0]*(102)

for pp in p:
    q[pp]=1
diff=1000
ans=-1

for i in range(0,102):
    if q[i]:
        continue

    cdiff=abs(i-x)

    if cdiff<diff:
        diff=cdiff
        ans=i
    
print(ans)

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

Submission status: Accepted

Solution code:

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


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

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
P = list(map(int, input().split()))
Q = [q for q in range(-1, 102) if q not in P]
ans = min(Q, key=lambda q: (abs(q - X), q))
print(ans)

Submission status: Accepted

Solution code:
x,n = map(int, input().split())
if n > 0:
	l = list(map(int,input().split()))
else:
	l = []
tl = []
for i in range(0,102):
	if i not in l:
		tl.append(i)
tlabs = []
for i in tl:
	tlabs.append(abs(x - i))
ans = tl[tlabs.index(min(tlabs))]
print(ans)

Submission status: Accepted

Solution code:
import math
X, N = list(map(lambda n : int(n), input().split(" ")))
if N == 0:
  print(X)
else:
  P = list(map(lambda p : int(p), input().split(" ")))
  Q = list(map(lambda p : [p, abs(X-p)], P))
  Q.sort(key=lambda q: (q[1], q[0]))

  cand = []
  for i in range(N):
    if i == 0 and Q[0][1] != 0:
      cand.append(X)
      break
    else:
      if Q[i][1] != math.ceil(i/2):
        cand.append(X + math.ceil(i/2))
        cand.append(X - math.ceil(i/2))
        break
  if len(cand) == 0:
    if N % 2 == 0:
      cand.append(X + int(N/2))
      cand.append(X - int(N/2))
    else:
      cand.append(X + int((N+1)/2))
      cand.append(X - int((N+1)/2))

  print(min(list(filter(lambda c: c not in P, cand))))

Submission status: Accepted

Solution code:
l=input()
ls=l.split(" ")
X=int(ls[0])
N=int(ls[1])
lstr=input()
lst=lstr.split(" ")
fl=[]
if(N!=0):
    for a in lst:
         fl.append(int(a))
for a in range(101):
    if(X-a not in fl):
         print(X-a)
         break
    if(X+a not in fl):
         print(X+a)
         break

Submission status: Accepted

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

for n in range(100):
  if X-n not in P:
    print(X-n)
    break
  if X+n not in P:
    print(X+n)
    break

Submission status: Accepted

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

for n in range(51):
  if X-n not in P:
    print(X-n)
    break
  if X+n not in P:
    print(X+n)
    break

Submission status: Accepted

Solution code:
import numpy as np
X,N = map(int,input().split())
P = list(map(int,input().split()))
A = []

for n in range(102):
  if n not in P:
    A+=[abs(n-X)]
  else:
    A+=[100]

print(np.argmin(A))

Submission status: Accepted

Solution code:
def main():
    x, n = list(map(int, input().split()))
    if n > 0:
        p_list = list(map(int, input().split()))
    else:
        return x
    ans = 0
    diff = abs(p_list[0]-x)
    for i in range(n):
        diff_new = abs(p_list[i] - x)
        if diff_new < diff:
            ans =i
            diff=diff_new
    #print(p_list[ans])

    for i in range(200):
        if p_list[ans] - i not in p_list:
            return p_list[ans] - i
            break
        elif p_list[ans] + i not in p_list:
            return p_list[ans] + i
            break
            
if __name__=='__main__':
    print(main())

Submission status: Accepted

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

print(ans)

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

X,N = (int(x) for x in input().split())
P = list(map(int, input().split()))
ALL = list(int(i) for i in range(-100,201))
P.sort()
Q = list(set(P)^set(ALL))
number = bisect.bisect(Q,X)

if number==0:
  print(Q[0])
elif number==len(Q):
  print(Q[len(Q)-1])
elif X-Q[number-1]<=Q[number]-X:
  print(Q[number-1])
elif X-Q[number-1]>Q[number]-X:
  print(Q[number])

Submission status: Accepted

Solution code:
(X,N) = map(int,input().split())
if N == 0:
    print(X)
else:
    p = list(map(int,input().split()))
    for i in range(N+1):
        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()))
else:
  print(x)
  exit()

for j in range(100):
  if all(x-j != i for i in p):
    print(x-j)
    exit()
  elif all(x+j != i for i in p):
    print(x+j)
    exit()

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
def main():
    X, N = map(int, input().split())
    if N == 0:
        print(X)
        return 0
    p_list = list(map(int, input().split()))
    
    
    ans = X
    i = 0
    while True:
        tmp_n = X - i
        if tmp_n not in p_list:
            ans = tmp_n
            break
        tmp_p = X + i
        if tmp_p not in p_list:
            ans = tmp_p
            break
        i += 1        
    
    print(ans)

main()

Submission status: Accepted

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

for i in range(101):
    for x in [X-i, X+i]:
        if x not in P:
            print(x)
            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(102):
    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(' '))
if N == 0:
    print(X)
else:
    P_ls = list(map(int, input().split(' ')))
    P_ls.sort(reverse=True)
    diff = -1
    for i in range(101, -1, -1):
        if i not in P_ls:
            if diff == -1:
                diff = abs(X - i)
                rst = i
            else:
                diff = min(diff, abs(X - i))
                if diff == abs(X-i):
                    rst = i
    print(rst)

Submission status: Accepted

Solution code:
data_XN = input()
data_p = input()

XN = data_XN.strip().split()
X = int(XN[0])
N = int(XN[1])
p = data_p.strip().split()

for i in range(101):
    a = X - i
    b = X + i
    forbidden_a = False
    forbidden_b = False
    for j in range(N):
        if a == int(p[j]):
            forbidden_a = True
        if b == int(p[j]):
            forbidden_b = True
    if forbidden_a == True and forbidden_b == True:
        pass
    elif forbidden_a == True and forbidden_b == False:
        print(b)
        break
    elif forbidden_a == False and forbidden_b == True:
        print(a)
        break
    else:
        print(a)
        break

Submission status: Accepted

Solution code:
# import itertools
# import math
# import sys
# import numpy as np

# K = int(input())
# S = input()
# n, *a = map(int, open(0))
X, N = map(int, input().split())
P = list(map(int, input().split()))
# Q = list(map(int, input().split()))
# S = input()

# d = sorted(d.items(), key=lambda x:x[0]) # keyでsort
# all_cases = list(itertools.permutations(P))
# a = list(itertools.combinations_with_replacement([i for i in range(1, M + 1)], N))
# print(a[0][0])
# print(conditions[0])

min_ = 999
num = 0
for i in range(102):
    if i in P:
        # print(i)
        continue
    _ = abs(i - X)
    if min_ > _:
        min_ = _
        num = i
print(num)

Submission status: Accepted

Solution code:
X,N,*P = map(int,open(0).read().split())
if P != []:
  P = sorted(list(P),reverse=True)
else:
  print(X)
  exit()

min_diff = 101
min_val = 101

for i in range(101,-1,-1):
  #print(i,min_val,min_val)
  if not i in P:
    if abs(X-i) <= min_diff and min_val >=i:
      min_diff = abs(X-i)
      min_val = i
  ans = min_val
print(ans)

Submission status: Accepted

Solution code:
X,N=map(int,input().split())
P=[int(x) for x in input().split()]
index=0
while(1):
    if X-index not in P:
        print(X-index)
        break
    if X+index not in P:
        print(X+index)
        break
    index+=1

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    x, n, *p = map(int, read().split())
    sa = 10000
    r = 10000
    for i1 in range(-101, 202):
        if i1 not in p:
            if abs(x - i1) < sa:
                sa = abs(x - i1)
                r = i1
    print(r)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
def main():
    for i in range(x+2):
        for j in [-1, 1]:
            ans = x + j*i
            if ans in p:
                continue
            else:
                return ans
        
print(main())

Submission status: Accepted

Solution code:
X, N = map(int,input().split())
li = set(list(map(int,input().split())))
li = list(set(range(102)) - li)

li.sort(reverse=True)
n = 102

for i in li:
    m = abs(X - i)
    if m <= n:
        n = m
        k = i
print(k)

Submission status: Accepted

Solution code:
# Forbidden List

X, N = [int(i) for i in input().split()]
pi = [int(i) for i in input().split()]

pl = []
pu = []
for i in pi:
    if i <= X:
        pl.append(i)
    if X <= X:
        pu.append(i)

pl.sort(reverse=True)
pu.sort()

nl = X
for i in pl:
    if i == nl:
        nl -= 1
nu = X
for i in pu:
    if i == nu:
        nu += 1

if X - nl <= nu - X:
    print(nl)
else:
    print(nu)

Submission status: Accepted

Solution code:
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]

#bisect.bisect_left(list,key)はlistのなかでkey未満の数字がいくつあるかを返す
#つまりlist[i] < x となる i の個数
#bisect.bisect_right(list, key)はlistのなかでkey以下の数字がいくつあるかを返す
#つまりlist[i] <= x となる i の個数
#これを応用することで
#len(list) - bisect.bisect_left(list,key)はlistのなかでkey以上の数字がいくつあるかを返す
#len(list) - bisect.bisect_right(list,key)はlistのなかでkeyより大きい数字がいくつあるかを返す
#これらを使うときはあらかじめlistをソートしておくこと！
x,n = MI()
if n == 0:
  print(x)
else:
  p = set(LI())
  li = set(range(-1,102))
  new_li = li - p
  x_dis = []
  for k in new_li:
    x_dis.append(abs(k-x))
  ind = x_dis.index(min(x_dis))
  print(list(new_li)[ind])

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
if not N ==0:
  A = [int(x) for x in input().split()]
  index = 0
  value = abs(A[0] - X)
  up_list = [0]*(N+1)
  down_list = [0]*(N+1)

  for i in range(N):
    if abs(A[i] - X ) < N+1:
      if A[i] - X >= 0:
        up_list[A[i]-X] = 1
      if A[i] - X <= 0:
        down_list[abs(A[i]- X)] = 1

  j = 0
  while True:
    if down_list[j] == 0:
      print(X-j)
      break
    if up_list[j] ==0:
      print(X+j)
      break
    if j>N+1:
      print('fail')
      break
    j+=1

else:
  print(X)

Submission status: Accepted

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

abs_list = []

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

for i in range(0,150):
    j,k = abs(X - i), X +i
    if j not in P:
        print(j)
        break
    if k not in P:
        print(k)
        break

Submission status: Accepted

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

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

P = list(map(int, input().split()))
up_min = 0
low_min = 0

arr = [0] * 102
for i in P:
  arr[i] = 1
lower = arr[:X]
lower.reverse()
upper = arr[X:]
for i, num in enumerate(lower):
  if num == 0:
    low_min = len(lower) - 1 - i
    break
for i, num in enumerate(upper):
  if num == 0:
    up_min = len(lower) + i
    break

if abs(up_min - X) >= abs(X - low_min):
  print(low_min)
else:
  print(up_min)

Submission status: Accepted

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

i = 0
ans = -1

while True:
    temp1 = x - i
    temp2 = x + i
    if temp1 not in p:
        ans = temp1
        break
    if temp2 not in p:
        ans = temp2
        break
    i += 1
print(ans)

Submission status: Accepted

Solution code:
import sys
x,n = map(int,input().split())
p = list(map(int,input().split()))
s = 100
min_i = -1

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

for i in range(-1,102):
    if i not in p and abs(i-x) < s:
        s = abs(i-x)
        min_i = i

        
print(min_i)

Submission status: Accepted

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

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

#print(N)
#print(M)
#print(x)

def hantei(number_1, list_1):
    for a in range(101):
        a_plus = number_1 + a
        a_minus = number_1 - a

        if a_minus not in list_1:
            return a_minus
            break
        elif a_plus not in list_1:
            return a_plus
            break
    
print(hantei(N,x))

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
n = list(i for i in range(-1, 110) if i not in p)

diff = 110
ans = 0

for i in n:
    if diff > abs(x-i):
        diff = abs(x-i)
        ans = i
        
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
if n == 0:
    print(x)
else:
    L = list(map(int,input().split()))
    ans = []
    cur = 0
    while len(ans) == 0:
        temp_1 = x-cur
        temp_2 = x+cur
        if temp_1 not in L:
            ans.append(temp_1)
        if temp_2 not in L:
            ans.append(temp_2)
        cur += 1
    print(ans[0])

Submission status: Accepted

Solution code:
import numpy as np
X,N=map(int,input().split())


    
if N==0:
	print(X)
else:
  p=list(map(int,input().split()))
  p=sorted(p)
  if X in p:
      s=X-1
      t=X+1
      while True:
          if s not in p:
              print(s)
              break
          elif t not in p:
              print(t)
              break
          else:
              s=s-1
              t=t+1
  else:
      print(X)

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
p=list(map(int,input().split()))
a=[]
b=[]
for i in range(0,102):
  if i not in p:
    a.append(i)
#a=set(a)

for i in a:
  b.append(abs(x-i))
#print(a)
idx = b.index(min(b))

print(a[idx])

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
if n == 0:
    print(x)
else:
    a = [int(x) for x in input().split()]
    ans1 = x
    while ans1 in a :
        ans1 -= 1
    ans2 = x
    while ans2 in a :
        ans2 += 1
    if abs(x - ans1) <= abs(x - ans2):
        print(ans1)
    else:
        print(ans2)

Submission status: Accepted

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

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

Submission status: Accepted

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

    for i in range(100):
        if X-i not in lst:
            print(X-i)
            break

        if X+i not in lst:
            print(X+i)
            break

else:
    print(X)

Submission status: Accepted

Solution code:
X,N = map(int,input().split())
p = [int(i) for i in input().split()]
if N==0:
    print(X)
else:
    pN=[]
    for j in range(N):
        pj = p[j]-X
        pN.append(pj)
    pN.sort()
    p0 = pN[0]-1
    p1 = pN[N-1]+1
    list_p = list(range(p0,p1+1,1))
    result = list(set(list_p)-set(pN))
    k0 = abs(result[0])
    for k in result:
        k1 = abs(k)
        if k1<k0:
            k0 = k1
    cnt = 0
    for l in result:
        if l == (-1)*k0:
            cnt+=1
    if cnt==0:
        print(X+k0)
    else:
        print(X-k0)

Submission status: Accepted

Solution code:
X, N = map(int, input().split()) #6,5
p = list(map(int, input().split())) #[4,7,10,6,5]
 
q = [(abs(X-i),i) for i in range(0,102) if not i in p]
q.sort()
 
print(q[0][1])

Submission status: Accepted

Solution code:
X,N = map(int, input().split())
l = [int(x) for x in input().split()]
i = 1
if X not in l:
        print(X)
else:    
    while i <= N//2 + 1 :
        if X - i  not in l:
            print(X-i)
            break
        elif X + i not in l:
            print(X+i)
            break
        i += 1

Submission status: Accepted

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

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
if N == 0:
  print(X)
else:
  a = list(map(int, input().split()))

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

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
y = list(map(int, input().split()))
a = x
for i in range(100):
  if (x-i) not in y:
    a = x-i
    break
  if (x+i) not in y:
    a = x+i
    break
print(a)

Submission status: Accepted

Solution code:

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

occupied = set(P)
for i in range(200):
    if X - i not in occupied:
        print(X - i)
        break

    if X + i not in occupied:
        print(X + i)
        break

Submission status: Accepted

Solution code:
def Qc():
    x, n = map(int, input().split())
    if 0 < n:
        p = list(map(int, input().split()))
        for i in range(101):
            if x - i not in p:
                print(x - i)
                exit()
            if x + i not in p:
                res = x + 1
                print(x + i)
                exit()
    else:
        # 整数列がなにもない場合は自分自身が含まれていない最近値になる
        print(x)
        exit()


if __name__ == "__main__":
    Qc()

Submission status: Accepted

Solution code:
a = input()

t, c = int(a.split(" ")[0]), int(a.split(" ")[1])

if not c:
    print(t)
else:
    b = input()
    lst = [int(x) for x in b.split(" ")]

    for i in range(c+2):
        if t - i not in lst:
            print(t - i)
            break
        if t + i not in lst:
            print(t + i)
            break

Submission status: Accepted

Solution code:
def main(X, N, p):
    for d in range(X + 2):
        if not((X - d) in p):
            print(X - d)
            return
        elif not((X + d) in p):
            print(X + d)
            return


if __name__ == "__main__":
    X, N = [int(s) for s in input().split(' ')]
    input_s = input()
    p = []
    if input_s != "":
        p = [int(s) for s in input_s.split(' ')]
    main(X, N, p)

Submission status: Accepted

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

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

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

for d in range(x + 2):
    if x-d not in p:
        print(x-d)
        exit()
        
    if x+d not in p:
        print(x+d)
        exit()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
l=list(map(int,input().split()))
ans=200
for i in range(-200,200):
  if (i not in l and abs(x-i)<abs(x-ans)):
    ans=i
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

l = []

for i in range(-1, 102, 1):
    if i not in p:
        l.append(i)

ans = []

for i in l:
    ans.append(abs(X-i))

ind = ans.index(min(ans))

print(l[ind])

Submission status: Accepted

Solution code:
X,N,*P = map(int, open(0).read().split())

i = 0
while True:
    r = X - i 
    if r not in P:
        print(r)
        break
    l = X + i
    if l not in P:
        print(l)
        break
    i += 1

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

X, N = mapint()
A = set(range(1000))
Ps = list(mapint())
Ps = sorted(list(A-set(Ps)))
mi = 10**18
ans = 0
for p in Ps:
    if abs(X-p)<mi:
        ans = p
        mi = abs(X-p)

print(ans)

Submission status: Accepted

Solution code:
x,n = map(int, input().split())
p = list(map(int, input().split()))
y1 = x
y2 = x
while y1 > 0 and y2 <= 100:
    if y1 in p:
        y1 += 1
    else: break
    if y2 in p:
        y2 -= 1
    else: break
ans = [100,100]
if y1 not in p:
    ans[0] = abs(x-y1)
if y2 not in p:
    ans[1] = abs(x-y2)
print(y2 if min(ans) == ans[1] else y1)

Submission status: Accepted

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

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

ans = 10000

for i in range(102):
    if i not in p:
        if abs(x-i) < abs(x-ans):
            ans = i
            #print(ans)
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()))
ans = -1

for i in range(0,102):
    if i not in p:
        if 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()))
if X not in P:
    print(X)
else:
    d = 1
    while True:
        if X-d not in P:
            print(X-d)
            break
        if X+d not in P:
            print(X+d)
            break
        d += 1

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
p = list(map(int, input().split()))
s = set(p)
d = 10**18
ans = 0

for i in range(-1000, 1000):
    if i not in s and abs(X-i)<d:
        d = abs(X-i)
        ans = i

print(ans)

Submission status: Accepted

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

if X not in P:
    print(X)
    exit()

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

Submission status: Accepted

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

best = float('inf')
ans = -1
for a in range(102):
    if a in P:
        continue
    if best > abs(X - a):
        best = abs(X - a)
        ans = a
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

from bisect import bisect_left

if N==0:
    t=X
else:
    l = bisect_left(P, X)
    for i in range(100):
        t=X-i
        if l-i<0 or t!=P[l-i]: break
        t=X+i
        if N<=l+i or t!=P[l+i]: break
print(t)

Submission status: Accepted

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

s=set()
for i in range(-100,201):
    s.add(i)

s=list(s-p)

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

Submission status: Accepted

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

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

d =100
num = 0

if n == 0:
    num = x
else:
    for i in range(102):
        if i not in p:
            d_temp = abs(x-i)
            if d_temp < d:
                d = d_temp
                num = i
print(num)

Submission status: Accepted

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

dmin = 10 ** 9
ans = 0

for i in range(0, 102):
    if i not in p:
        d = (x - i) * (x - i)
        if d < dmin:
            dmin = d
            ans = i

print(ans)

Submission status: Accepted

Solution code:
X, N = [int(i) for i in input().split()]
P = [int(i) for i in input().split()]
# Xは0~101の値になる
result = 0
current = 102
for i in range(102):
    if i not in P:
        if abs(X - i) < current:
            result = i
            current = abs(X - i)
print(result)

Submission status: Accepted

Solution code:
X, N = [int(i) for i in input().split()]
P = [int(i) for i in input().split()]
# 近い順でソートできないか
# 負の数でも可なので、自分自身以外の場合は必ず二つある
# 一つあった場合はもう一方
# 一つもなかった場合は小さい方を選ぶ
P = sorted(P, key=lambda a: abs(a-X))
if N == 0 or P[0] != X:
    print(X)
else:
    # 1, 2が1ずれてるか、2, 3が2ずれてるか...と確認する
    i = 1
    for j in range(1, N):
        if abs(P[j] - X) != i:
            if X - i in P:
                print(X+i)
                exit()
            else:
                print(X-i)
                exit()

        if j % 2 == 0:
            i += 1
    if N % 2 == 1:
        print(X - (N+1) // 2)
    else:
        if X-N//2 in P:
            print(X+N//2)
        else:
            print(X-N//2)