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()))
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 = list(map(int, input().split()))
if N != 0:
    p = list(map(int, input().split()))
if N == 0:
    p = []
if X in p:
    Xp = X + 1
    Xm = X - 1
    while True:
        if Xm in p:
            Xm -= 1
        else:
            print(Xm)
            break
        if Xp in p:
            Xp += 1
        else:
            print(Xp)
            break
else:
    print(X)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
x, n = map(int,input().split())
p = list(map(int,input().split()))
p_list = [0 for i in range(103)]
n_abs = 1000
ans = 100000

for i in p:
    p_list[i] = 1

for i in range(0, 102):
    temp_abs = abs(x-i)
    if n_abs > temp_abs and p_list[i] != 1:
        n_abs = temp_abs
        ans = i

print(ans)

Submission status: Accepted

Solution code:
x, n = map(int,input().split())
p = list(map(int,input().split()))
p_list = [0 for i in range(100)]
n_abs = 1000
ans = 100000

for i in p:
    p_list[i-1] = 1

for i in range(0, 102):
    if i == 0 or i == 101:
        temp_abs = abs(x-i)
        if n_abs > temp_abs:
            n_abs = temp_abs
            ans = i
    else:
        temp_abs = abs(x-i)
        if n_abs > temp_abs and p_list[i-1] != 1:
            n_abs = temp_abs
            ans = i
        elif n_abs == temp_abs and i < ans and p_lsit[i-1] != 1:
            n_abs = temp_abs
            ans = i

print(ans)

Submission status: Accepted

Solution code:
def MI():
    return map(int, input().split())

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

X, N = MI()
P = LI()
ans = X

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

for i in range(101):
    if not X - i in P:
        ans = X - i
        break
        
    if not X + i 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()))

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

    elif (x + d) not in p:
        print(x+d)
        exit()

Submission status: Accepted

Solution code:
X,N = map(int,input().split())
p = sorted(list(map(int,input().split())))
for i in range(X,-1,-1):
    if i not in p:
        ans = i
        break
for i in range(X+1,102):
    if i not in p:
        ans2 = i
        break
if X-ans > ans2-X:
    print(ans2)
else:
    print(ans)

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
g=set(map(int,input().split()))
l=r=x
while 1:
    if l in g:l-=1
    else:print(l);break
    if r in g:r+=1
    else:print(r);break

Submission status: Accepted

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

for i in range(X+1):
    for j in [-1, 1]:
        a = X + i * j
        if a not in p:
            print(a)
            exit(0)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = set(map(int, input().split()))
min_d = 103
ans = 103
for i in range(102):
    if i in p:
        continue
    d = abs(x - i)
    if d < min_d:
        min_d = d
        ans = i
print(ans)

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
p = input().split()
q = p[::-1]
a = x
b = x
c = 1
if p.count(str(x)) == 1:
  while c == 1:
    a -= 1
    c = p.count(str(a))
c = 1
if p.count(str(x)) == 1:
  while c == 1:
    b += 1
    c = p.count(str(b))
if x - a <= b - x:
  print(a)
else:
  print(b)

Submission status: Accepted

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

for d in range(X + 1):
    if (X - d) not in p:
        print(X-d)
        exit()
    elif (X + d) not in p:
        print(X+d)
        exit()

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
if n == 0:
  print(x)
  exit()
P = [int(i) for i in input().split()]
P = sorted(P)
diff = abs(x-(P[0]-1))
ans = P[0]-1
for i in range(1, 102):
  if i not in P and abs(x-i) < diff:
    diff = abs(x-i)
    ans = i
print(ans)

Submission status: Accepted

Solution code:
from sys import exit, stdin
X, N = [int(_) for _ in stdin.readline().rstrip().split()]
P = [int(_) for _ in stdin.readline().rstrip().split()]
ans = 0
for i in range(X+1):
    diff = [X-i, X+i]
    if diff[0] not in P:
        ans = diff[0]
        break
    if diff[1] not in P:
        ans = diff[1]
        break
print(ans)

Submission status: Accepted

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

for i in range(0,100):
  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:
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np
# from numpy import cumsum  # accumulate

def solve():
    X, N = MI()
    P = LI()

    ans = 0
    d = INF
    for i in range(0, 102):
        if i in P: continue
        if d > abs(i - X):
            ans = i
            d = abs(i - X)
    print(ans)

if __name__ == '__main__':
    solve()

Submission status: Accepted

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

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

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

diff = 0

while True:
    if x - diff not in pn:
        print(x-diff)
        exit()
    elif x + diff not in pn:
        print(x+diff)
        exit()
    diff += 1

Submission status: Accepted

Solution code:
# ABC170C

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

if n == 0:
    p = set([])
else:
    p = list(map(int, input().split()))
a = list(set(range(201)) - set(p))
abs_diff = [abs(i - x) for i in a]
min_abs_diff = min(abs_diff)
for i, j in zip(a, abs_diff):
    if j == min_abs_diff:
        print(i)
        break

Submission status: Accepted

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

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

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


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


def main():
    a, b = map(int, input().split())
    array = list(map(int, input().split()))

    cnt = 1
    ans = 0
    array2 = []
    zero_flg = 0

    if len(array) != 0:
        for i in range(len(array)):
            if a == array[i]:
                zero_flg = 1

    if zero_flg == 0:
        ans = a
    else:
        if ans == 0:
            while True:
                for i in range(len(array)):
                    if (a + cnt == array[i]) or (a - cnt == array[i]):
                        array2.append(array[i])
                if len(array2) != 2:
                    break
                cnt += 1
                array2.clear()

        if len(array2) == 0:
            if a + cnt < a - cnt:
                ans = a + cnt
            else:
                ans = a - cnt
        elif len(array2) == 1:
            if array2[0] == a + cnt:
                ans = a - cnt
            else:
                ans = a + cnt

    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import os
import sys
from collections import defaultdict, Counter
from itertools import product, permutations,combinations, accumulate
from operator import itemgetter
from bisect import bisect_left,bisect
from heapq import heappop,heappush,heapify
from math import ceil, floor, sqrt
from copy import deepcopy

def main():
    x,n = map(int, input().split())
    p_list = list(map(int, input().split()))
    x_list = [i for i in range(0,200)]
    ans = 0
    min_abs = 10**3

    for i in p_list:
        x_list.remove(i)

    for j in x_list:
        if min_abs > abs(j-x):
            min_abs = abs(j-x)
            ans = j

    print(ans)
    
    

   
if __name__ == "__main__":
    main()

Submission status: Accepted

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

def main():
    X, N = map(int, input().split())
    p = list(map(int, input().split()))
    if X not in p:
        print(X)
        return
    for i in range(1, 101):
        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()))
c=0
if n==0:
    print(x)
else:
    while True:
        if x-c not in p:
            print(x-c)
            break
        elif x+c not in p:
            print(x+c)
            break
        c+=1

Submission status: Accepted

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

try:
    p = [None if k is None else int(k) for k in input().split()]
except:
    p = []
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:
  print(X)
  exit()
P=list(map(int,input().split()))
count=0
while True:
  if X-count not in P:
    print(X-count)
    break
  if X+count not in P:
    print(X+count)
    break
  count+=1

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
p = list(map(int,input().split()))
for i in range(100):
    pFlag = True
    mFlag = True
    for j in range(len(p)):
        if p[j] == x+i:
            pFlag = False
        if p[j] == x-i:
            mFlag = False
    if mFlag:
        a = (-1)* i
        break
    if pFlag:
        a = i
        break
print(x+a)

Submission status: Accepted

Solution code:
def myargmin(array):
    array = list( array )
    return array.index(min(array))

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

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

    P = sorted(map(int, input().split(" ")))
    array = list(range(0, 102))
    for p in P:
        if p in array:
            array.remove(p)
        else:
            continue

    resid = [abs(a - X) for a in array]
    min_idx = myargmin(resid)

    print(array[min_idx])

Submission status: Accepted

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



for j in range(0,X+1):

    flag_a=0
    flag_b=0

    a=X-j
    b=X+j

    for k in p:

        if a==k:
            flag_a=1
        if b==k:
            flag_b=1

    if flag_a==0:

        print(a)
        break
    
    elif flag_b==0:

        print(b)
        break

Submission status: Accepted

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

if N == 0:
    print(X)
    exit()
else:
    for i in range(200):

        if X-i not in nums:
            print(X-i)
            exit()

        if X+i not in nums:
            print(X+i)
            exit()

Submission status: Accepted

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


ans_list = []
for i in range(102):
    ans_list.append([abs(X-i),i])
ans_list = sorted(ans_list)
flag = True
for j in range(102):
    for k in range(N):
         if(p[k]==ans_list[j][1]):
             flag = False
    if(flag):
        print(ans_list[j][1])
        break
    flag = True

Submission status: Accepted

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

Submission status: Accepted

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

flag = 0
abs = 0

while flag == 0:
  test1 = xn[0] + abs
  test2 = xn[0] - abs
  if not test2 in p:
    flag = 2
  elif not test1 in p:
    flag = 1
  abs += 1

if flag == 1:
  print(test1)
else:
  print(test2)

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


diff = 10000
best = -1
for i in range(-100, 201):
    if i not in P:
        d = abs(X-i)
        if diff > d:
            best = i
            diff = d
            # print(i)
print(best)

Submission status: Accepted

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

set_p = set(p)

num = 2000
ans = 0
for i in range(200, -1 , -1):
    if i not in set_p:
        if num >= abs(x - i):
            num = abs(x - i)
            ans = i

print(ans)

Submission status: Accepted

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

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

x = X
while x in P:
  x -= 1
minX = x

x = X
while x in P:
  x += 1
maxX=x

if abs(minX - X) <= abs(maxX - X):
  print(minX)
else:
  print(maxX)

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(101):
                if X - i not in p:
                        print(X - i)
                        break
                if X + i not in p:
                        print(X + i)
                        break

Submission status: Accepted

Solution code:
import sys
def getmax():
    max = 0
    for i in p:
        if i > max:
            max = i
    return max
def getmin():
    min = p[0]
    for i in p:
        if i < min:
            min = i
    return min
X,N = map(int,input().split())
if N ==0:
    print(X)
    sys.exit()
if N == 1:
    p = int(input())
    print(p-1)
    sys.exit()
p = list(map(int,input().split()))  #
MIN = 101   #
minnum = 0
for i in range(-101,102):
    if not i in p:
        if abs(i-X) < MIN:
            MIN = abs(i-X)
            minnum = i
print(minnum)

Submission status: Accepted

Solution code:
X, N = map(int, input().split(' '))
P = []
if N > 0:
  P = sorted(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

if N > 0:
  print(ans)
else:
  print(X)

Submission status: Accepted

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

p = list(map(int, input().split()))
i = 1
if x in p:
  while 1:
    if (x - i) in p:
      if (x + i) in p:
        i += 1
      else:
        print(x + i)
        sys.exit()
    else:
      print(x - i)
      sys.exit()
else:
  print(x)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys


def log(s):
    # print("| " + str(s), file=sys.stderr)
    pass


def output(x):
    print(x, flush=True)


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


def main():
    x, n = tuple(input_ints())
    pp = input_ints()

    d = 0
    while True:
        if not x-d in pp:
            print(x - d)
            break
        if not x+d in pp:
            print(x + d)
            break
        d += 1

main()

Submission status: Accepted

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



x = y = X
true=[]
jud = True
while jud:
    if x not in p:
        true.append(x)
        break
    x += 1
while jud:
    if y not in p:
        true.append(y)
        break
    y -= 1

abs=[abs(t-X) for t in true]
#print(true[abs.index(min(abs))])
true_list=[i for i,a in enumerate(abs) if a==min(abs)] #絶対値が小さいものの添字リスト
true_list2=[true[i] for i in true_list]
print(min(true_list2))

Submission status: Accepted

Solution code:
X,N = map(int,input().split())
 
p = list(map(int,input().split()))
 
import sys
for i in range(102):
 
    if X-i not in p:
        print (X-i)
        sys.exit()
    elif X+i not in p:
        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 = tuple(map(int, input().split()))
for i in range(100):
    if (x-i in p) == False:
        print(x-i)
        break
    if (x+i in p) == False:
        print(x+i)
        break

Submission status: Accepted

Solution code:
X,N = map(int,input().split())
 
p = list(map(int,input().split()))
 
import sys
for i in range(200):
 
    if X-i not in p:
        print (X-i)
        sys.exit()
    elif X+i not in p:
        print (X+i)
        sys.exit()

Submission status: Accepted

Solution code:
# C - Forbidden List
X, N = map(int, input().split()) 
num_list = list(map(int, input().split())) 
for i in range(len(num_list)):
    num_list[i] = num_list[i]-X
for i in range(101):
    if (-i in num_list) is False:
        print(X-i)
        break
    if (i in num_list) is False:
        print(X+i)
        break

Submission status: Accepted

Solution code:
X,N = map(int,input().split())
if N == 0:
    print(X)
    exit()
else:
    M = list(map(int,input().split()))
    up = X
    down = X
    ans = []
    while ans == [] :
        if up in M and down in M:
            up += 1
            down -= 1
        elif down in M:
            ans.append(up)
        else:
            ans.append(down)
    print(min(ans))

Submission status: Accepted

Solution code:
# coding: utf-8
x, n = map(int, input().split())
if n == 0:
    print(x)
else:
    P = list(map(int, input().split()))
    ans = 10**9
    L = {P[i]:0 for i in range(n)}
    for i in range(-200, 201):
        if i not in L.keys():
            if abs(ans - x) > abs(i - x):
                ans = i
    print(ans)

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
a=sorted(list(map(int,input().split())))
if n==0:
  print(x)
  exit()
else:
  for i in range(100):
    aa=x-i
    if aa not in a:
      print(aa)
      exit()
    bb=x+i
    if bb not in a:
      print(bb)
      exit()

Submission status: Accepted

Solution code:
X,N=map(int,input().split())
if N==0:
  print(X)
  exit()
p=list(map(int,input().split()))
num=10**6
ans=0
np=[]
for i in range(0,201):
  if not i in p:
    np.append(i)
for i in np:
  if num>abs(X-i):
    num=abs(X-i)
    ans=i
print(ans)

Submission status: Accepted

Solution code:
class int(int):  
  def times(self, callback):
    for times in range(0,self):
      callback()

class list(list):
  def maps(self, callback):
    return list(map(callback, self))

  def each(self, callback):
    list(map(callback, self))
    return self

  # index will sent to the function as a second parameter.
  def each_with_index(self,callback):
    list(map(callback, self, range(0,len(self))))
    return self

# Make sure you initialize object with class name.
# Ex: int(10).times, array = list([1,2,3,4,5])

target, length = input().split()
target = int(target)
length = int(length)
nums = list(input().split())

def convert(arg):
    return int(arg)
nums = nums.maps(convert)

for i in range(0,101):
  # Xの両隣がpに存在しないかみていく（pに存在しない値をみつけたいので）
  a = target - i # まずは左隣をみていく(Xよりi小さい)
  if a not in nums:
    print(a)
    exit()

  b = target + i # 次に右隣をみていく(Xより大きい)
  if b not in nums:
    print(b)
    exit()
  
# 配列pが与えられなかったとき(長さが0のとき)でも、「Xより0小さい値がpに存在しない」ので、そのままXが返せる

Submission status: Accepted

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

cur_dist,num = int(1e10),int(1e10)

for i in range(-100,201):
  if i in arr:
    continue
  dist = abs(i-x)
  if dist < cur_dist:
    cur_dist = dist
    num = i

print(num)

Submission status: Accepted

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

    for i in range(100):
        if X - i not in ps:
            return X - i
        if X + i not in ps:
            return X + i
        

def main():
    print(solve())


if __name__ == "__main__":
    main()

Submission status: Accepted

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

    candidates = set(range(102))

    for p in ps:
        candidates.discard(p)

    nearest = 0
    distance = X
    for c in candidates:
        d = abs(X-c)
        if distance > d:
            nearest = c
            distance = d

    return nearest


def main():
    print(solve())


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
class int(int):  
  def times(self, callback):
    for times in range(0,self):
      callback()

class list(list):
  def maps(self, callback):
    return list(map(callback, self))

  def each(self, callback):
    list(map(callback, self))
    return self

  # index will sent to the function as a second parameter.
  def each_with_index(self,callback):
    list(map(callback, self, range(0,len(self))))
    return self

# Make sure you initialize object with class name.
# Ex: int(10).times, array = list([1,2,3,4,5])

target, length = input().split()
target = int(target)
length = int(length)
nums = list(input().split())

def convert(arg):
    return int(arg)
nums = nums.maps(convert)

for i in range(0,101):
  a = target - i
  if a not in nums:
    print(a)
    exit()

  b = target + i
  if b not in nums:
    print(b)
    exit()

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
ans={}
for P in list(map(int, input().split())):
    ans[X-P]=1

for i in range(0,101):
    if not i in ans:
        print(X-i)
        break
    elif not i*-1 in ans:
        print(X+i)
        break

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
diff = []
y = [i for i in range(-1, 102) if i not in p]
for i in y:
  z = abs(x - i)
  diff.append(z)

if x - min(diff) not in p:
  print(x - min(diff))
else:
  print(x + min(diff))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
import bisect
import numpy as np
import math
from collections import deque
from collections import defaultdict
from math import gcd

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

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

Submission status: Accepted

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


z=float("inf")
ans_temp=[0,0]
ans=[0,0]

y=[i for i in range(-1,102) if i not in p]

for i in y:
  if z>abs(x-i):
    ans[0]=abs(x-i)
    ans[1]=i
  elif z==abs(x-i):
    ans_temp[0]=abs(x-i)
    ans_temp[1]=i
    if ans_temp[1]<ans[1]:
      ans[1]=ans_temp[1]
  z=abs(x-i)
print(ans[1])

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
p = list(map(int,input().split()))
i = x
j = x
ansa = 0
ansb = 0
while True:
  if i not in p:
    ansa = i - x
    break
  else:
    i += 1

while True:
  if j not in p:
    ansb = x - j
    break
  else:
    j -= 1

print(i if ansa<ansb else j)

Submission status: Accepted

Solution code:
x, n = map(int, input(). split())
p = []
if n > 0:
  p = list(map(int, input(). split()))
if n == 0:
  print(x)
else:
  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:
import sys
sys.setrecursionlimit(10000000)
from collections import defaultdict
import math

x, n = map(int, input().split())
P = list(map(int, input().split()))
if len(P) == 0:
    print(x)
    exit()
for i in range(x, max(P)+2):
    if i not in P:
        a = i
        break
for i in range(x, -1, -1):
    if i not in P:
        b = i
        break
if abs(a-x) < abs(b-x):
    print(a)
else:
    print(b)

Submission status: Accepted

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

  diff = 0
  while True:
    if x-diff not in list_:
      print(x-diff)
      break
    if x+diff not in list_:
      print(x+diff)
      break
    diff+=1

Submission status: Accepted

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

diff = 0
while(True):
    if not x - diff in arr:
        print(x - diff)
        exit(0)
    if not x + diff in arr:
        print(x + diff)
        exit(0)
    diff += 1

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
p=list(map(int,input().split()))
if n==0:
    print(x)
else:
    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

Submission status: Accepted

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

if n == 0:
  print(x)
else:
  p = list(map(int, input().split()))
  for j in range(0, int(n/2)+ 2):
    #print(j)
    if x-j not in p:
      print(x-j)
      break
    else:
      if x+j not in p:
        print(x+j)
        break

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
diff, ans = 10000, x
if n > 0:
    vals = set(map(int, input().split()))
    for i in range(300):
        if i not in vals and diff > abs(x-i):
            ans = i
            diff = abs(x - 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()]

for i in range(0, 100):
    a = x - i
    b = x + i

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

Submission status: Accepted

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

for i in range(0, 100):
    a = x - i
    b = x + i

    if a >= 0 and a not in p:
        print(a)
        break
    elif b <= 101 and b not in p:
        print(b)
        break

Submission status: Accepted

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

i = 0
while x + i in s:
    if i >= 0: i += 1
    i *= -1

print(x + i)

Submission status: Accepted

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

i = 0
while True:
    k = x + i
    if k not in s:
        print(k)
        break

    if i >= 0: i += 1
    i *= -1

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

cand1 = x
while cand1 in p:
    cand1 -= 1

cand2 = x
while cand2 in p:
    cand2 += 1

ans = cand1 if abs(cand1 - x) <= abs(cand2 - x) else cand2
print(ans)

Submission status: Accepted

Solution code:
Input = input().split()
X = Input[0]
X = int(X)
N = Input[1]
N = int(N)
if N != 0:
    P = input().split()
    Z = 0
    A = 0
    while Z < 1:
        B = X + A
        C = X - A
        B = str(B)
        C = str(C)
        if not(C in P):
            D = C
            Z = 1
            break
        if not(B in P):
            D = B
            Z = 1
            break
        A += 1
else:
    D = X

print(D)

Submission status: Accepted

Solution code:
#coding:utf-8

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

P = [int(y) for y in input().split()]

flag = True
x = 0
count = 0

while flag:
    x = X - count
    if(x not in P):
        print("{}".format(x))
        break

    x = X + count
    if(x not in P):
        print("{}".format(x))
        break

    count += 1

Submission status: Accepted

Solution code:
import sys

x, n = map(int, input().split())
s = set(map(int, input().split()) if n != 0 else "")

i = 0
while True:
    for j in range(2):
        k = x - i * (-1)**j
        if k not in s:
            print(k)
            sys.exit()
    i += 1

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
a = []
if n != 0 : a = list(map(int,input().split()))
tmp = 114514
ret = -114514
for i in range(-10,110):
  if not i in a and abs(x-i) < tmp:
    ret = i
    tmp = abs(x-i)
print(ret)

Submission status: Accepted

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