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:
def main():
    # x in [1, 100]
    # n in [0, 100]
    # p_i in [1, 100] 
    x, n = (int(i) for i in input().split())
    if n > 0:
        p = set(int(i) for i in input().split())
    else:
        p = set() 

    b, e = x, x
    while b in p and e in p:
        b -= 1
        e += 1

    if b not in p:
        print(b)
    else:
        print(e)


main()

Submission status: Accepted

Solution code:
X,N = map(int,input().split())
P = set(map(int,input().split()))
for i in range(X+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:
k,n=map(int,input().split())
if(n==0):
    print(k)
else:
  l=list(map(int,input().split()))
  c=0
  d=0
  while(d==0):
        if(k-c not in l):
            print(k-c)
            break
        if(k+c not in l):
            print(k+c)
            break
        c=c+1

Submission status: Accepted

Solution code:
k,n=map(int,input().split())
if(n==0):
    print(k)
else:
  l=list(map(int,input().split()))
  c=1
  d=0
  if(k not in l):
      print(k)
  else:  
      while(d==0):
        if(k-c not in l):
           print(k-c)
           break
        if(k+c not in l):
           print(k+c)
           break
        c=c+1

Submission status: Accepted

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

counter = 0

for i in range(1, 101):
    if x in p:
        if counter == 0:
            x -= i
            counter = 1
        else:
            x += i
            counter = 0
    else:
        exit
print(x)

Submission status: Accepted

Solution code:
def pick(sol, a):
    count,s = 0, sol
    while (True):
        count += 1
        if s not in a:
            return s
        else:
            if count%2:
                s -= count
            else:
                s += count
def near(a, n):
    ans = set()
    for i in a:
        ans.add(max(i,n))
        if i == n:
            break
        if len(ans)!=1:
            break
    else:
        if len(ans) == 1:
            if (ans[0]==n):
                i = a[0]
            elif ans[0]==a[-1]:
                i = a[-1]
    print(pick(i, a))

n ,k = map(int,input().split())
a = sorted(list(map(int,input().split())))
if k == 0:
    print(n)
else:
    near(a,n)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
x,n=map(int,input().split())
if n==0:
  print(x)
else:
  plist=list(map(int,input().split()))
  newplist=sorted(plist)
#リストからｘの値を引いて絶対値をとったものをリスト化する
  p_list=[]
  for i in newplist:
    k=abs(i-x)
    p_list.append(k)
#最小値となるときのインデックスを探す
  ind=np.argmin(p_list)
  moto=newplist[ind]
  gap=0
  while True:
    gap+=1
    if (moto-gap) in newplist:
      pass
    else:
      print(moto-gap)
      break
    if (moto+gap) in newplist:
      pass
    else:
      print(moto+gap)
      break

Submission status: Accepted

Solution code:
# C Forbidden List

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

  for i in range(100):
    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:
inp = list(map(int,input().split()))
x=inp[0]
n=inp[1]
inp = list(map(int,input().split()))
from collections import Counter
c=Counter(inp)
if c[x]==0:
  print (x)
else:
  i=1
  while (1):
    if c[x-i]==0:
      print (x-i)
      break
    elif c[x+i]==0:
      print (x+i)
      break
    i+=1

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = [int(x) for x in input().split()]
seen = set(p)
offset = 0
while True:
    val1, val2 = x + offset, x - offset
    if val2 not in seen:
        print(val2)
        break
    if val1 not in seen:
        print(val1)
        break
    offset += 1

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
p=set(list(map(int,input().split())))
ans=0
flag=0
while flag==0:
    if not x-ans in p:
        print(x-ans)
        flag=1
    elif not x+ans in p:
        print(x+ans)
        flag=1
    ans+=1

Submission status: Accepted

Solution code:
import math

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

ans = -1
dif = 10000
for i in range(102):
  if i in p: #含まれている時
    continue
  else:
    if abs(x - i) < dif:
      ans = i
      dif = abs(x - i)

print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

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

dist=1000
for i in range(101,-1,-1):
  if i in p:
    continue

  t_dist=abs(x-i)
  if t_dist<=dist:
    dist=t_dist
    ans=i

print(ans)

Submission status: Accepted

Solution code:
#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))
  
x,n=input2()
p=sorted(input_array())
q=[0]*102
result=[10000,-1]
for i in range(n):
	q[p[i]]=1
for i in range(102):
	if q[i]==0:
		num=abs(i-x)
		if num<result[0]:
			result=[num,i]
print(result[1])

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
ps_x = {int(s)-x for s in input().split()}

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

Submission status: Accepted

Solution code:
# coding: utf-8

x, N = map(int,input().split())
if N != 0:
    P = list(map(int,input().split()))
    L = [i for i in range(-1000, 1010)]

    l = list(set(P)^set(L))
    dis = 10**9
    
    for i in range(len(l)):
        dis_ = abs(x-l[i])
        if dis_ < dis:
            ans = l[i]
            dis = dis_
else:
    ans = x


print(ans)

Submission status: Accepted

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

  if x not in num:
    print(x)
  else:
    y = num.index(x)
    if y == (n-1):
      if num[y-1] == x-1:
        print(x+1)
      else:
        print(x-1)
    elif y == 0:
      print(x-1)
    else:
      for i in range(100):
        y = x-i
        if y not in num:
          under = y
          count_under = i
          break
      for j in range(100):
        y = x + j
        if y not in num:
          upper = y
          count_upper = j
          break
      
      if count_under <= count_upper:
        print(under)
      else:
        print(upper)

Submission status: Accepted

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

q = [i for i in Z if i not in p]
t = []

for i in range(0, len(q)):
    t.append(abs(int(X)-q[i]))

print(q[(t.index(min(t)))])

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
if n > 0:
    p = [int(i) for i in input().split()]
else:
    p = [0]

y = []
for i in range(102):
    if i not in p:
        y.append(i)

m = 102
ans = -1
for i in y:
    if abs(x-i) < m:
        m = abs(x-i)
        ans = i

print(ans)

Submission status: Accepted

Solution code:
import math

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

ans = -1
dif = 10000
for i in range(102):
    if i in p:
        continue
    else:
        if abs(x - i) < dif:
            ans = i
            dif = abs(x - 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()))
    p.sort()
    p2 = [i - x for i in p]
    for i in range(100):
        if not -i in p2:
            print(x - i)
            break
        if not i in p2:
            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 i in range(101):
        if x-i==0:
            print(0)
            break
        if p.count(x-i)==0:
            print(x-i)
            break
        if x+i==101:
            print("101")
            break
        if p.count(x+i)==0:
            print(x+i)
            break

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
p = list(map(int,input().split()))
if not x in p:
    print(x)
else:
    y = x-1
    z = x+1
    while 1:
        if not y in p:
            print(y)
            break
        if not z in p:
            print(z)
            break
        y-=1
        z+=1

Submission status: Accepted

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

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

Submission status: Accepted

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

    best_num = 0
    best_diff = 999
    for i in range(102):
        if i not in p and abs(x - i) < best_diff:
            best_num = i
            best_diff = abs(x - i)

    print(best_num)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

m=float('inf')
l=[]
       
for i in range(-100,N+101):
    if i not in p:
        l.append(i)
    else:
        continue

for j in l:
    m=min(m,abs(X-j))
    
if (X-m) not in p:
    print(X-m)
else:
    print(X+m)

Submission status: Accepted

Solution code:
import sys

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

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

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

for i in range(51):
    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())
S=map(int, input().split())
K=(list(range(0,102)))
for i in S:
    K.remove(i)
L=[]
for i in K:
    L.append(abs(x-i))
m=min(L)
ind_m=L.index(m)
print(K[ind_m])

Submission status: Accepted

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

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

upper_ans = 0

for i in range(x, 102):
    if not (i in ps):
        upper_ans = i
        break

lower_ans = 0

for j in reversed(range(0, x + 1)):
    if not (j in ps):
        lower_ans = j
        break

if (upper_ans == 0) and (lower_ans == 0):
    ans = 0
elif abs(x - upper_ans) < abs(x - lower_ans):
    ans = upper_ans
elif abs(x - upper_ans) > abs(x - lower_ans):
    ans = lower_ans
else:
    ans = min(upper_ans, lower_ans)

print(ans)

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

Submission status: Accepted

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

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

i = X
j = X

if len(P) == 0:
    print(X)    
elif X  not in P:
    print(X)
else:
    while i < 101:
        i += 1
        if i not in P:
            break
    while j > 0:
        j -= 1
        if j not in P:
            break
    
    if i - X >= X - j:
        print(j)
    else:
        print(i)

Submission status: Accepted

Solution code:
import random

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

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

if len(P) == 0:
    print(X)    
else:
    L = list(range(max(0,X-N),min(102,X+N)))

    if X+N <= 101:
        L.append(X+N)

    for i in range(N):
        if P[i] in L:
            L.remove(P[i])

    while len(L) > 2:
        rand = random.randint(1,len(L)-2)
        if L[rand] == X:
            break
        elif L[rand] > X:
            L = L[0:rand+1]
        else:
            L = L[rand:len(L)]

    if X in L:
        print(X)
    elif len(L) == 1:
        print(L[0])
    else:
        if abs(L[0]-X) > abs(L[1]-X):
            print(L[1])
        else:
            print(L[0])

Submission status: Accepted

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

while True:
    try:
        numbers = input().split(" ")
        i = 0
        n = X
        while n > -1000 :
            if str(n) in numbers:
                i += 1
                n = n - (i * (-1)**(i-1))
            else:
                print(n)
                break
        break
    except:
        print(X)
        break

Submission status: Accepted

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

cnt = 0
while True:
    y = x - cnt
    if y not in s:
        print(y)
        break
    y = x + cnt
    if y not in s:
        print(y)
        break
    cnt += 1

Submission status: Accepted

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

ans1=100
ans=0
if N==0:
    print(X)
else:
    for i in range(102):
        if i in p:
            continue
        elif abs(X-i)<ans1:
            ans =i
            ans1 = abs(X-i)
    print(ans)

Submission status: Accepted

Solution code:
XN = list(map(int, input().split(' ')))
if XN[1] == 0:
    print(XN[0])
else:
    p = list(map(int, input().split(' ')))
    count = [0] * 110
    for i in range(XN[1]):
        count[p[i] + 5] += 1
    for i in range(60):
        if count[XN[0] + 5 - i] == 0:
            print(XN[0] - i)
            break
        elif count[XN[0] + 5 + i] == 0:
            print(XN[0] + i)
            break

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7

import itertools

X,N = map(int,readline().split())
p = list(map(int,readline().split()))
ans = -INF
now = INF
for i in range(-10,105):
    if i not in p:
        if now > abs(X-i):
            ans = i
            now = abs(X-i)
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin


def readline_from_stdin() -> str:
    return stdin.readline().rstrip


if __name__ == '__main__':
    pass
    # N = input()
    # X, Y, Z = input().split()
    # A = [int(i) for i in input().split()]
    X, N = input().split()
    X, N = int(X), int(N)
    if N == 0:
        print(X)
        exit(0)
    P = [int(i) for i in input().split()]
    P = list(set(P))

    i = 0
    while True:
        v = X-i
        if not (v in P):
            print(v)
            exit(0)
        v = X+i
        if not (v in P):
            print(v)
            exit(0)
        i += 1

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
p = list(map(int, input().split()))
tmp = 101
ans = 101
for i in range(-200, 201):
    if i not in p:
        if tmp == abs(X-i):
            if ans > i:
                ans = i
        elif tmp >= abs(X-i):
            ans = i
            tmp = abs(X-i)
print(ans)

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
p = list(map(int, input().split()))
tmp = 101
ans = 101
for i in range(-100, 201):
    if i not in p:
        if tmp == abs(X-i):
            if ans > i:
                ans = i
        elif tmp >= abs(X-i):
            ans = i
            tmp = abs(X-i)
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:
'''
例
6 5
4 7 10 6 5

１．X = 6 との差を求める
(X-P_iの配列を作る)
2 -1 -4 0 1

2. X-P_iの配列に0, ±1, ±2, ... が含まれていないか調べる


3. 数列Pに含まれていない数で
6との差が-2になる8
'''

import numpy as np

def pm_list(i):
    if(i%2 == 0):
        return i//2
    else:
        return -i//2

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

def_list = np.array(P) - X

i = 0
while True:
    iter_num = pm_list(i) 
    if not (iter_num in def_list):
        print(X + iter_num)
        break
    i += 1

Submission status: Accepted

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

  NP = sorted(list(set(range(-1,102)) - P))
  right = bisect.bisect(NP, X)
  left = right - 1
  if abs(X - NP[left]) > abs(X - NP[right]):
    print(NP[right])
  else:
    print(NP[left])

main()

Submission status: Accepted

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

  NP = sorted(list(set(range(102)) - P))
  right = bisect.bisect(NP, X)
  left = right - 1
  if left == -1 or abs(X - NP[left]) > abs(X - NP[right]):
    print(NP[right])
  else:
    print(NP[left])

main()

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
p=list(map(int,input().split()))
q=p
s=0
for i in range(n):
    p[i]-=x
for i in range(100):
    t=0
    for j in range(n):
        if p[j]==i:
            t+=1
        if p[j]==-i:
            t+=2
    s=i
    if t!=3:
        break
if t==0 or t==1:
    print(x-s)
else:
    print(x+s)

Submission status: Accepted

Solution code:
import collections
import heapq
import math
import random
import sys
input = sys.stdin.readline

sys.setrecursionlimit(500005)
read_int = lambda: int(ns())
read_list = lambda: list(map(int, input().split()))
read_string = lambda: input().rstrip()

x, n = read_list()
p = set(read_list())
res = 1000000
for i in range(-100, 300):
    if i in p:
        continue
    if abs(i - x) < abs(res - x) or (abs(i - x) == abs(res - x) and i < res):
        res = i
print(res)

Submission status: Accepted

Solution code:
# inpute integer (x) along with integer sequence (n)
# finding the integer nearest to x within the given range 100
# no time i have to submit
x, n = map(int, input().split())  # take input from the user
P = list(map(int, input().split()))

for i in range(101):  # loop through the range
    length = x - i
    result = x + i
    if length not in P:
        print(length)
        break
    elif result not in P:
        print(result)
        break

Submission status: Accepted

Solution code:
X, N = map(int, input().split())        #asking for input
p = list(map(int, input().split()))     #asking for input
for d in range(X + 1):                  #doing loop
    for s in [-1, +1]:
        a = X + s * d
        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()))
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:
#array to get nearest values
A, B = map(int, input().split())
p = list(map(int, input().split()))
for d in range(A + 1):
    for s in [-1, +1]:
        x = A + s * d
        if p.count(x) == 0:

             print(x)

             exit(0)

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:
x,n = map(int,input().split()) # take input from the user
P = list(map(int,input().split()))
 
for i in range(101): # loop through the range
  xl = x - i
  xr = x + i
  if xl not in P:
    print(xl)
    break
  elif xr not in P:
    print(xr)
    break

# time complixity O(N)

Submission status: Accepted

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

Submission status: Accepted

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

x, n = map(int, input().split())
s = list(map(int, input().split()))
for i in range(x + 1):
    for op in [-1, 1]:
        if (v := op * i + x) not in s: print(v); exit()
print('GayLand')

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
judge = 102*[1]
if N==0:
	print(X)
	exit()

P = list(map(int, input().split()))
for i in range(N):
	judge[P[i]] = 0

upcnt = 0
while judge[X+upcnt]==0:
	upcnt+=1

downcnt = 0
while judge[X-downcnt]==0:
	downcnt+=1

if upcnt < downcnt:
	print(X+upcnt)
else:
	print(X-downcnt)

Submission status: Accepted

Solution code:
x, n = list(map(int, input().split()))
if n > 0:
  p = list(map(int, input().split()))
else:
  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())
p=list(map(int, input().split()))
if not x in p:print(x)
else:
    for i in range(500):
        if not x-i in p:
            print(x-i)
            break
        elif not x+i in p:
            print(x+i)
            break

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
p=list(map(int, input().split()))
youso=[]
for i in range(-300,1000):
    if not i in p:
        youso+=[i]
hikaku=[]
for i in youso:
    hikaku+=[(i,abs(x-i))]
hikaku1=sorted(hikaku,key=lambda x:x[1])
res=hikaku1[0][0]
print(res)

Submission status: Accepted

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

Submission status: Accepted

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

p = list(map(int,input().split()))
p = [-1] + p + [102]
import bisect
p.sort()
i = bisect.bisect_left(p,x)
if p[i] != x:
    print(x)
    exit()

for h in range(102):
  if p[i-h] != x-h:
    print(x-h)
    exit()
  elif p[i+h] != x+h:
    print(x+h)
    exit()

Submission status: Accepted

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

for i in range(101):
  xl = x - i
  xr = x + i
  if xl not in P:
    print(xl)
    break
  elif xr not in P:
    print(xr)
    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 i in range(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:
import sys
X, N = map(int, input().split())
if N == 0:
    print(X)
    sys.exit()
p = list(map(int, input().split()))

forbid = [True]*102

for i in range(len(p)):
    if forbid[p[i]]:
        forbid[p[i]] = False
        
pp = []

for i in range(len(forbid)):
    if forbid[i]:
        pp.append(i-X)

num = pp[len(pp)-1]        
for i in range(len(pp)-1,-1,-1):
    if abs(num) >= abs(pp[i]):
        num = pp[i]
        
print(num+X)

Submission status: Accepted

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

forbid = [True]*102

for i in range(len(p)):
    if forbid[p[i]]:
        forbid[p[i]] = False
        
pp = []

for i in range(len(forbid)):
    if forbid[i]:
        pp.append(i-X)

# num = pp[len(pp)-1]        
# for i in range(len(pp)-1,0,-1):
#     if abs(num) >= abs(pp[i]):
#         num = pp[i]
        
print(pp[np.argmin(np.abs(pp))]+X)

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    x,n=map(int, input().split())
    l=list(map(int,input().split()))
    for i in range(100):
        if x-i not in l:
            print(x-i)
            break
        elif x+i not in l:
            print(x+i)
            break
resolve()

Submission status: Accepted

Solution code:

import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    x,n=map(int, input().split())
    l=list(map(int,input().split()))
    samin=1000
    ans=1000
    for i in range(102):
        if i not in l and abs(i-x)<samin:
            samin=abs(i-x)
            ans=i
    print(ans)
resolve()

Submission status: Accepted

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

min = 1000
pre_i = 0
for i in range(102):
    if i in p:
        continue
    if min > abs(x - i):
        min = abs(x - i)
    else:
        break
    pre_i = i

print(pre_i)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
mem = []
mind = 100
for i in range(-100, 200):
    if i not in p:
        t = abs(x-i)
        if t < mind:
            mem.append([i, t])
            mind = t
mem = sorted(mem, key=lambda x: (x[1], x[0]))
print(mem[0][0])

Submission status: Accepted

Solution code:
a,b = map(int,input().split())
#if(b != 0):
c = list(map(int,input().split()))
#else:
  #print(a)
  #exit(0)

for dist in range(b+1):
  for signed in [-1,1]:
    x = a + signed*dist
    if c.count(x) == 0:
      print(x)
      exit(0)

Submission status: Accepted

Solution code:
a,b = map(int,input().split())
if(b != 0):
  c = list(map(int,input().split()))
else:
  print(a)
  exit()
ans = 0
for i in range(101):
  if(a+i not in c):
    if(a+i > 101):
      break
    else:
      ans = a+i
      break
for i in range(101):
  if(a-i not in c):
    if(a-i < 0):
      break
    else:
      if(i < abs(a-ans)):
        ans = a-i
      elif(i == abs(a-ans)):
        ans = min(a-i,ans)
      break
print(ans)

Submission status: Accepted

Solution code:
def resolve():
    x, n = [int(i) for i in input().split()]
    if n != 0:
        l = [int(i) for i in input().split()]
    c = 0
    while 1:
        if n == 0:
            print(x)
            break
        if not(x - c in l):
            print(x - c)
            break
        elif not(x + c in l):
            print(x + c)
            break
        c += 1
resolve()

Submission status: Accepted

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

a = x
while True:
    if not a in plist:
        big = a
        break
    a += 1

b = x-1
while True:
    if not b in plist:
        small = b
        break
    b -= 1

if abs(big-x) < abs(small-x):
    ans = big
else:
    ans = small

print(ans)

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
p=list(map(int,input().split()))
for i in range(1000):
    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:
    ps = list(map(int, input().split()))
    
    if x not in ps:
      print(x)
    else:
      i = 1
      while True:
          minus = x - i
          plus = x + i

          if not minus in ps:
              print(minus)
              break
          elif not plus in ps:
              print(plus)
              break

          i += 1

Submission status: Accepted

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

Submission status: Accepted

Solution code:
X,N = map(int,input().split())
A = list(map(int,input().split()))
import sys
for d in range(X+1):
  for i in [-1,1]:
    B = X + d*i
    if A.count(B) == 0:
      print(B)
      sys.exit()

Submission status: Accepted

Solution code:
  
import sys
sys.setrecursionlimit(10**7)

readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))



x,n = readints()
p = readints()

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

Submission status: Accepted

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

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

Ans = 400

for i in range(102):
    if max(0,X-i) in p:
        Ans = Ans
    else:
        Ans = max(0,X-i)
        break
    if min(101,X+i) in p:
        Ans=Ans
    else:
        Ans = min(101,X+i)
        break
print(Ans)

Submission status: Accepted

Solution code:
def fun():
    x, n = list(map(int, input().split()))
    if n == 0: return x
    num_list = list(map(int, input().split()))
    hashmap = {num: True for num in num_list}
    if x not in hashmap: return x
    a = []
    i = 1
    answer = float('inf')
    for _ in range(n):
        for dif in (-1*i, +1*i):
            if x+dif not in hashmap:
                a.append(x + dif)
            if len(a) == 2:
                break
        if len(a) == 2:
            break
        i += 1
    #print(a)
    answer = min([(abs(num-x), num) for num in a])
    return answer[1]
    
print(fun())