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


a = 0
for m in range(100 + 2):
    if m in p:
        continue
    else:
        if abs(x - a) > abs(x - m):
            a = m

print(a)

Submission status: Accepted

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

if N == 0:
    print(X)
else:
    p = sorted(p)
    for i in range(0, 100):
        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:
  print(x)
  exit()
p = set(map(int, input().split()))

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

Submission status: Accepted

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

going = True
c = X # 初期値
co = X
count = 0

if N == 0:
    print(X)
else:
    while going:
        if p.count(c) == 0:
            print(c)
            break
        elif p.count(co) == 0:
            print(co)
            break
        c -= 1
        co += 1
        #count += 1
#print(count)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = list(map(int,input().split()))
ux = x
dx = x
while True:
    if dx in p:
        dx -= 1
    else:
        ans1 = dx
        break
while True:
    if ux in p:
        ux += 1
    else:
        ans2 = ux
        break
if x-dx <= ux-x:
    print(dx)
else:
    print(ux)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
if(n == 0):
    print(x)
elif(n == 1):
    if(n == x):
        print(x - 1)
    else:
        print(x)
else:
    p = list(map(int, input().split()))
    p.sort()
    p2 = map(lambda a: a - x, p)
    ps = sorted(p2, key=abs)
    q = list(range((-1) * n, n))
    qs = sorted(q, key=abs)
    for i in range(n):
        if(ps[i] != qs[i]):
            print(qs[i] + x)
            break
    else:
        print(x + qs[n])

Submission status: Accepted

Solution code:
x,n=map(int,input('').split(' '))
p=input('')
if n==0:
    print(x)
else:
    p=p.split(' ')
    for a in range(n):
        p[a]=int(p[a])

    l=400
    sok=0
    for a in range(102):
        ok=1
        for b in range(n):
            if p[b]==a:
                ok=ok*0
            else:
                ok=ok*1
                sok=1

        if ok==1:
            if abs(a-x)<abs(l-x):
                l=a
            elif abs(a-x)==abs(l-x):
                if a<l:
                    l=a
                elif a>l:
                    l=l


    print(l)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
ps = list(map(int, input().split()))
anss = [101] * 102
for i in range(102):
  if (i not in ps):
    anss[i] = abs(x - i)
m = min(anss)
for i, ans in enumerate(anss):
  if ans == m:
    print(i)
    exit()

Submission status: Accepted

Solution code:
X, N =map(int, input().split())
if N ==0:
  print(X)
  exit()
S_1 = set(map(int, input().split()))
S_2 = {i for i in range(102)}
S = S_2 - S_1
L = 1000
for s in S:
  if abs(X-s) < abs(X-L):
    L = s
print(L)

Submission status: Accepted

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

check = float("inf")
ans = float("inf")
for p in range(1000,-1001,-1):
    if p in p_lst:
        continue
    else:
        #print(p)
        if check >= abs(p-x):
            check = abs(p-x)
            ans = p
            
print(ans)

Submission status: Accepted

Solution code:
import sys
x, n = map(int, input().split())
p = []
if n != 0:
    p = sorted(map(int, input().split()))
q = []
t = 0
for t in range(102):
    if t not in p:
        q.append(t)
m = 100000000
ans = 0
for i in q:
    if abs(x - i) < m:
        m = abs(x - i)
        ans = i
print(ans)

Submission status: Accepted

Solution code:
import sys

x,n = map(int,input().split())
p = list(map(int,input().split()))
pp = [i for i in range(-103,103)]
ans = 1000
m = 1000

for j in range(n):
    pp.remove(p[j])

for k in pp:
    if m > abs(x-k):
        m = abs(x-k)
        ans = k

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 not p.count(x-i):
        print(x-i)
        exit()
    elif not p.count(x+i):
        print(x+i)
        exit()

Submission status: Accepted

Solution code:
"""
6 5
4 7 10 6 
"""
x,n = map(int, raw_input().split(' '))

ais = map(int, raw_input().split(' ')) if n else []
ais.sort()


def f(x, u, v):
	#returns the number thats closest to x within range u,v not including u and v
	if u + 1 == v: return (+float('inf'), +float('inf'))
	if u < x < v: return (0,x) 	
	if x >= v: return (abs(x - (v -1)), v-1)
	if x <= u: return (abs(x - (u +1)), u + 1)
res = (+float('inf'), +float('inf'))
ais = [-1] + ais + [102]
for u,v in zip(ais,ais[1:]):
	res = min(res , f(x,u,v))

print res[1]

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# C

import sys
from collections import defaultdict, deque
from heapq import heappush, heappop
import math
import bisect
input = sys.stdin.readline

# 再起回数上限変更
# sys.setrecursionlimit(1000000)

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

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

all = list(range(102))
val = 10000000000
# print(list(set(all) - set(p)))

for a in list(set(all) - set(p)):
    if abs(a - x) < val:
        ans = a
        val = abs(a - x)
        # print(val)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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


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

left = x
while True:
    if left not in p:
        break
    left -= 1

right = x
while True:
    if right not in p:
        break
    right += 1

if abs(x-left) <= abs(x-right):
    print(left)
else:
    print(right)

Submission status: Accepted

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

MAX = 102
tbl = [False] * MAX
for t in p:
    tbl[t] = True
MIN = MAX
ans = 0
for i in range(MAX):
    if tbl[i]:
        continue
    if MIN > abs(x-i):
        ans = i
        MIN = abs(x-i)

print(ans)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
ps = list(map(int, input().split()))
nums = list(range(-1, 102))
for p in ps:
    nums.remove(p)
min_diff = float("inf")
min_original = float("inf")
for num in nums:
    diff = abs(num - x)
    if diff < min_diff:
        min_diff = diff
        min_original = num
    elif diff == min_diff:
        if num < min_original:
            min_original = num
print(min_original)

Submission status: Accepted

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

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

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

diff = 0
high = low = None
while True:
    if X + diff not in P:
        high = X + diff
    if X - diff not in P:
        low = X - diff
    if high is None and low is None:
        diff += 1
        continue

    if high == low:
        print(low)
    elif low is None:
        print(high)
    else:
        print(low)
    break

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
 
if n != 0:
    s = set(map(int, input().split()))
    origin_set = set(range(-1, 102))
    result_set = origin_set - s
    result_list = list(result_set)
    result_num = 1000
 
    for i in result_list:
      if abs(x-i) < result_num:
        min_num = i
        result_num = abs(x-i)
      elif abs(x-i) == result_num:
        if i < min_num:
          min_num = i
    print(min_num)
else:
  print(x)

Submission status: Accepted

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

l = list(range(-1,102))
s = []
  
for i in p:
  l.remove(i)

for j in l:
  s.append(abs(X-j))
  
ans = min(s)

if l.count(X+ans) == 1 and l.count(X-ans) == 1:
  print(X-ans)

elif l.count(X+ans) == 1 and l.count(X-ans) != 1:
  print(X+ans)
  
elif l.count(X+ans) != 1 and l.count(X-ans) == 1:
  print(X-ans)

Submission status: Accepted

Solution code:
def dev(y,x):
    if y<x:
        return 2*(x-y)-1
    else:
        return 2*(y-x)


x,n=map(int,input().split())
p=[int(y) for y in input().split()]
q=[dev(y,x) for y in p]
q.sort()
r=0
while r<len(q):
    if q[r]!=r:
        break
    r+=1
if r%2==0:
    print(x+r//2)
else:
    print(x-(r+1)//2)

Submission status: Accepted

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

tmp = [(abs(i-x), i) for i in range(0, 102) if i not in ps]
min_d = min(tmp, key=lambda x: x[0])[0]

ans = min(filter(lambda x: x[0] == min_d, tmp), key=lambda x:x[1])

print(ans[1])

Submission status: Accepted

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


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


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

p.sort()
gen = list(range(-5,120))

for i in p:
    gen.remove(i)

index = bisect.bisect(gen,X)

ans = 100000
ans2 = 100000

a = [gen[index-1],gen[index],gen[index+1]]

for i in range(3):
    check = abs(a[i]-X)
    if ans > check:
        ans = check
        ans2 = a[i]
    
print(ans2)

Submission status: Accepted

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

result = 100
AAA = result

if N == 0:
    result = X
else:
    for pi in range(-2,102):
        if pi in P:
            continue

        if pi > X:

            if abs(X - AAA) <= abs(X - pi):
                result = AAA
            else:
                result = pi

            break

        AAA = pi

print(result)

Submission status: Accepted

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

from pprint import pprint
import sys

sys.setrecursionlimit(10 ** 6)
INF = float('inf')


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

diff = INF
res = None

for i in range(-200, 200):
    if i in P:
        continue
    if abs(x - i) < diff:
        res = i
        diff = abs(x - i)

print(res)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
pre = input().split()
X = int(pre[0])
N = int(pre[1])

if N == 0:
  print(X)
else:
  pre = input().split()
  p = [int(s) for s in pre]

  list = [0] * 102

  for i in range(len(p)):
    list[p[i]] = 1
  

  for i in range(55):
    if list[X-i] == 0:
      print(X-i)
      break
    if list[X+i] == 0:
      print(X+i)
      break

Submission status: Accepted

Solution code:
X,N = map(int,input().split(" "))
if N == 0:
    print(X)
else:
    p = [int(i) for i in input().split(" ")]
    if not(X in p):
        print(X)
    else:
        un = sorted([i for i in p if i < X],reverse = True)
        hi = sorted([i for i in p if i > X])
        X1 = X-1
        X2 = X+1
        while(1):
            if not(X1 in un):
                print(X1)
                break
            if not(X2 in hi):
                print(X2)
                break
            X1 -= 1
            X2 += 1

Submission status: Accepted

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

ans = x

if x not in p:
    ans = x
else:
    for i in range(1, 52):
        if x - i not in p:
            ans = x - i
            break
        elif x + i not in p:
            ans = x + i
            break
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

num_list = list(map(int,input().split()))
i = 0

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

Submission status: Accepted

Solution code:

if __name__ == "__main__":
    x, n = [int(a) for a in input().split()]
    p = list(map(int, input().split()))
    p.sort()
    i = 0
    ans =-1
    if x not in p:
        print(x)
        exit()
    while True:
        i += 1
        if (x-i) not in p:
            ans = x-i
            break
        elif (x+i) not in p:
            ans = x+i
            break
    print(ans)

Submission status: Accepted

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

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

for i in range(len(p)):
    ans1 -= 1
    ans2 += 1
    if ans1 not in p:
        print(ans1)
        exit()
    if ans2 not in p:
        print(ans2)
        exit()
print(X)

Submission status: Accepted

Solution code:
x,n = (int(x) for x in input().split())
try:
  p = [int(x) for x in input().split()]
  i = 0
  while 1:
    ans1 = x - i
    ans2 = x + i
    if ans1 not in p:
      print(ans1)
      break
    if ans2 not in p:
      print(ans2)
      break
    i = i + 1
except EOFError:
  print(x)

Submission status: Accepted

Solution code:
import sys

X,N=(int(x) for x in input().split())
if N==0:
  print(X)
  sys.exit()

P=input().split()
P_int = [int(s) for s in P]
#print(P_int)
#print(X,Y)
#print(4 in P_int)
if not X in P_int:
  print(X)
  sys.exit()

for i in range(1,100):
  if not (X-i) in P_int:
    print(X-i)
    sys.exit()
  
  if not (X+i) in P_int:
    print(X+i)
    sys.exit()

Submission status: Accepted

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

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

if N == 0:print(X)
else:
    for i in range(0,100):
        if not X-i in L:
            print(X-i)
            break
        if not X+i in L:
            print(X+i)
            break

Submission status: Accepted

Solution code:
X,N = (int(x) for x in input().split())
p = [int(x) for x in input().split()]

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

Submission status: Accepted

Solution code:
x, n=map(int, input().split())
try:
  l=list(map(int, input().split()))
except EOFError:
  print(x)
  exit()
for i in range(101):
  if x+i in l and x-i in l:
    continue
  elif x+i in l:
    print(x-i)
    exit()
  elif x-i in l:
    print(x+i)
    exit()
  else:
    print(x-i)
    exit()

Submission status: Accepted

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

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

s = set(P)

m = 1000
ans = None
for i in range(-1,102):
    if i not in s:
        if m > abs(X-i):
            ans = i
            m = abs(X-i)

print(ans)

Submission status: Accepted

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

res = 10**15
for i in range(-120,120):
  if i in P: continue
  if abs(i-X) < abs(res-X):
    res = i
print(res)

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
try:
 P = list(map(int,input().split()))
except EOFError:
  print(x)
else:
  ans1 = x
  ans2 = x
  if x not in P:
    print(x)
  else:
    while True:
        ans1 += 1
        ans2 -= 1
        if ans1 not in P and ans2 not in P:
          print(ans2)
          break
        elif ans1 in P and ans2 not in P:
          print(ans2)
          break
        elif ans2 in P and ans1 not in P:
          print(ans1)
          break

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
pli = [int(i) for i in input().split()]
ans = 0
for s in range(1, 51):
    if not x in pli:
        ans = x
    elif x in pli and not x - s in pli and not x + s in pli:
        ans = x - s
        break
    elif x in pli and x - s in pli and not x + s in pli:
        ans = x + s
        break
    elif x in pli and not x - s in pli and x + s in pli:
        ans = x - s
        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



queue = [x]
while(len(queue)>0):
    now = queue.pop(0)
    if(now <= 0 or now >=101):
        print(now)
        break
    if(mp[now]==False):
        print(now)
        break
    
    if(now==x):
        queue.append(now-1)
        queue.append(now+1)
    if(now < x):
        queue.append(now-1)
    if(now > x):
        queue.append(now+1)

Submission status: Accepted

Solution code:
import sys
x, n = map(int, input().split())
if n == 0:
  print(x)
  sys.exit()
else:
  l = list(map(int, input().split()))
  
  ze = [0 for i in range(101)]
  
  for i in range(n):
    ze[abs(x-l[i])] += 1
    
  if ze[0] == 0:
    print(x)
  else:
    for i in range(1, 101):
      if ze[i] < 2:
        if x-i not in l:
          print(x-i)
          sys.exit()
        else:
          print(x+i)
          sys.exit()

Submission status: Accepted

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

c = 1
while True:
    if X in p:
        if not((X-c) in p):
            print(X-c)
            break
        if not((X+c) in p):
            print(X+c)
            break
        c += 1  
    else:
        print(X)
        break

Submission status: Accepted

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

else:
    print(x)

Submission status: Accepted

Solution code:
X, N = map( int, input().split() )
ret = X
if N > 0:
  P = sorted( list( map( int, input().split() ) ))
  dis = 10 ** 18
  for i in range( 110, -1, -1 ):
    if not i in P:
      if dis - abs( i - X ) >= 0:
        ret = i
        dis = abs( i - X )
  
print( ret )

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:
    for i in range(100):
        Ans1 = x - i
        Ans2 = x + i
        if Ans1 not in p:
            print(Ans1)
            break
        if Ans2 not in p:
            print(Ans2)
            break

Submission status: Accepted

Solution code:
import math
x,n  = map(int,input().split())
if n==0:
    print(x)
    exit()
p = [int(i) for i in input().split()]


max_ = max(p)
a= [i for i in range(2*max_+1)]

m=0
for i in p:
    a[i]=100000
min_=100000
for i in a:
    b = abs(i-x)
    if min_ > b:
        min_=b
        m = i
print(m)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
l = [i for i in range(0, 102)]
z = list(set(p)^set(l))
y = []
for i in z:
    y.append(abs(x-i))
z2 = sorted(y)
ans1 = x-z2[0]
ans2 = x+z2[0]
m = min(ans1, ans2)
M = max(ans1, ans2)
if m in z:
    print(m)
else:
    print(M)

Submission status: Accepted

Solution code:
X, N = map(int,input().split())
p = sorted(list(map(int, input().split())))
P = list(range(-1, 103))
[P.remove(pp) for pp in p]
p_min_abs = 10000000

for pp in P:
    if abs(pp - X) < p_min_abs:
        p_min_abs = abs(pp - X)
        p_min = pp
print(p_min)

Submission status: Accepted

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

for i in range(n+1):
    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())
if N==0:
    print(X)
    exit()
P = set(map(int, input().split()))

Min = float("inf")
ans = int()
for i in range(-1, 102):
    if not i in P:
        if Min > abs(X-i):
            Min = abs(X-i)
            ans = i
print(ans)

Submission status: Accepted

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

  min = 1000
  ans = 0
  for i in range(102):
    if abs(x-i)<min and (i in p)==False:
      min = abs(x-i)
      ans = i

  print(ans)

Submission status: Accepted

Solution code:
import numpy as np
x,n=(int(x) for x in input().split())
p = np.array([int(x) for x in 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:
import sys

a = list(map(int, input().split()))
X = a[0]
N = a[1]

try:
  p = list(map(int, input().split()))
except EOFError:
  print(X)
  sys.exit()

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

Submission status: Accepted

Solution code:

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

p=sorted([int(x) for x in input().split()])
a=[]
ans=10**9
for i in range(-1,102):
    if i in p:
        pass
    else:
        a.append([i,abs(x-i)])
        ans=min(ans,abs(x-i))
for i in range(len(a)):
    if a[i][1]==ans:
        print(a[i][0])
        sys.exit()

Submission status: Accepted

Solution code:
para_line = list(map(int,input().split(' ')))
if(para_line[1]):
    input_line = list(map(int,input().split(' ')))

ans = para_line[0]
if(para_line[1]):
    for i in range(100):
        if(para_line[0]-i not in input_line):
            ans = para_line[0]-i
            break
        if(para_line[0]+i not in input_line):
            ans = para_line[0]+i
            break
print(ans)

Submission status: Accepted

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

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

p_set = set(p_list)
min_p = min(p_list)
max_p = max(p_list)

compare_X = X
min_d = 100000
min_d_i = compare_X

while True:
    if compare_X not in p_set:
        d = abs(X - compare_X)
        min_d = min(min_d, d)
        if min_d == d:
            min_d_i = compare_X

    if compare_X > max_p:
        break

    compare_X += 1

compare_X = X


while True:
    if compare_X not in p_set:
        d = abs(X - compare_X)
        min_d = min(min_d, d)
        if min_d == d:
            min_d_i = compare_X

    if compare_X < min_p:
        break

    compare_X -= 1


print(min_d_i)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
all = list(range(0, 102))
diff = []

for i in p:
    all.remove(i)

for j in all:
    diff.append(abs(x-j))

diff_min = min(diff)
num_min = diff.index(diff_min)
ans = all[num_min]

print(ans)

Submission status: Accepted

Solution code:
def around_nums(x):
    i = 1

    while(True):
        yield x
        yield x - i
        yield x + i
        i += 1

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

nums = list(map(int, temp.split()))
for n in around_nums(x):
    if not n in nums:
        print(n)
        break

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
p=list(map(int,input().split()))
p.sort()
ans=0
dist=1000000
for i in range(110):
    i-=2
    if i in p:
        continue
    if abs(i-x) < dist:
        dist = abs(i-x)
        ans = i

print(ans)

Submission status: Accepted

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

ans = 10 ** 9
num = 10 ** 9
a = [0] * 200
for i in range(len(p)):
    a[p[i]] = 1

for i in range(110):
    if a[i] == 1:
        continue

    if ans > abs(i - x):
        num = i
        ans = abs(i - x)

# print(num)
if abs(x - (-1)) <= abs(num-x):
    num = -1
print(num)

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
p = list(map(int,input().split()))
p.sort()
ans1 = 999999
for i in range(101,-1,-1):
    if i not in p:
        if abs(x - i) <= abs(x - ans1):
            ans1 = i
print(ans1)

Submission status: Accepted

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

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

    p.sort()
    trgt = x
    roop_flg = True
    a = 1
    while roop_flg:
        if trgt not in p:
            break
        else:
            if a > 0:
                trgt = trgt -a
                a = -(a+1)

            else:
                trgt = trgt -a
                a = -(a-1)


    print(trgt)

Submission status: Accepted

Solution code:
import sys
X, N = map(int, input().split())
if(N == 0):
    print(X)
    sys.exit()
p_list = list(map(int, input().split()))
p_list.sort()

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

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
p_lst = list(map(int, input().split()))
o_lst = list(range(0,102))
lst = list(set(p_lst) ^ set(o_lst))

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

Submission status: Accepted

Solution code:
import sys


def main():
    X, N = list(map(int, input().split()))
    ans = 999
    dis = 999
    if N == 0:
        print(X)
        sys.exit()
    P = list(map(int, input().split()))
    for i in range(0, 102):
        if i not in P:
            if dis > abs(i - X):
                dis = abs(i - X)
                ans = i
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans = 10**18

for i in range(-100, 200):
    if i in P:
        continue
    if abs(X - i) < abs(X - ans):
        ans = i
    if abs(X - i) == abs(X - ans):
        if i < ans:
            ans = i

print(ans)

Submission status: Accepted

Solution code:
import sys
X, N = map(int, input().split())
P = list(map(int, input().split()))
P.sort()
if X not in P:
    print(X)
    sys.exit()

for i in range(55):
    low = X - i
    if low not in P:
        print(low)
        break
    high = X + i
    if high not in P:
        print(high)
        break

Submission status: Accepted

Solution code:
X,N=map(int, input().split())
if N==0:
  print(X)
  exit()
else:
  P=list(map(int,input().split()))
  for i in range(101):
    if (X+i not in P) and (X-i not in P):
      print(min(X+i, X-i))
      exit()
    elif (X+i not in P):
      print(X+i)
      exit()
    elif (X-i not in P):
      print(X-i)
      exit()
    else:
      X+=0

Submission status: Accepted

Solution code:
x,n = map(int, input().split())
p = [int(i) for i in input().split()]
ans = 0
if x in p:
    p.sort()
    for i,v in enumerate(p):
        if v == x:
            break
    j = 1
    while True:
        if i-j < 0 or v-j != p[i-j]:
            ans = v-j
            break
        if i+j > n-1 or v+j != p[i+j]:
            ans = v+j
            break
        j += 1
else:
    ans = x
print(ans)

Submission status: Accepted

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

if n==0:
    print(x)
else:
    if x in ls:
        ls.sort()
        x_idx = ls.index(x)
        pos_search = x + 1
        ans_1 = ls[-1]+1
        ans_2 = ls[0]-1
        for i in ls[x_idx+1:]:
            if i == pos_search:
                pass
            else:
                ans_1 = pos_search
                break
            pos_search+=1
        nega_ls = ls[:x_idx]
        nega_ls.reverse()
        nega_search = x - 1
        for i in nega_ls:
            if i == nega_search:
                pass
            else:
                ans_2 = nega_search
                break
            nega_search-=1
        if abs(ans_2-x) <= abs(ans_1-x):
            print(ans_2)
        else:
            print(ans_1)
    else:
        print(x)

Submission status: Accepted

Solution code:
X,N = map(int,input().split())
P = [int(i) for i in input().split()]
ans = 100000
flag = False
for i in range(-1,102):
    if i in P:
        pass
    else:
        if abs(X - ans) > abs(X-i):
            flag = True
            ans = i
print(ans)

Submission status: Accepted

Solution code:
x, n = map(int,input().split())
p = list(map(int,input().split()))
l=[]
judge=[]
for i in range(120):
    l.append(i)
    l.append(-1*i)
for i in range(n):
    l.remove(p[i])
for i in range(len(l)):
    judge.append((l[i]-x)**2)
judge.sort()
if x - judge[0]**0.5 in l :
    print(int(x - judge[0]**0.5))
else:
    print(int(x + judge[0]**0.5))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*

def find(l, r, lst):

    if (l - 1) not in lst:
        return (l - 1)
    
    if (r + 1) not in lst:
        return (r + 1)
    
    return find(l - 1, r + 1, lst)



def main():
    # 整数の入力
    x, n = map(int, input().split())
    lst = list(map(int, input().split()))

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

    if x not in lst:
        print(x)
        exit(0)
    
    print(find(x, x, lst))




if __name__ == '__main__':
    main()

Submission status: Accepted

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

for i in range(100):
    u_flg = False
    l_flg = False

    x_u=x+i
    x_l=x-i
    for p in P:
        if x_u == p:
            u_flg = True
        if x_l == p:
            l_flg = True

    if u_flg == False and l_flg == False:
        print(min(x_u,x_l))
        break
    elif u_flg == False:
        print(x_u)
        break
    elif l_flg == False:
        print(x_l)
        break

Submission status: Accepted

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

n_ans = 0
sa = 200
for k in range(0,102,1):
    if (k in p):
        continue
    if(abs(k-X) < sa):
        n_ans = k
        sa = abs(k-X)
    else:
        break
print(n_ans)