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:
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float("INF")

#solve
def solve():
    x, n = LI()
    p = LI()
    ans = 0
    for i in range(102):
        if not i in p:
            if abs(ans - x) > abs(x - i):
                ans = i
    print(ans)
    return


#main
if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
X,N= map(int,input().split())
p = list(map(int, input().split()))
ans_tmp = 10**9
ans = X
for i in range(0,102):
    if i not in p and ans_tmp>abs(X-i):
        ans_tmp=abs(X-i)
        ans = i
print(ans)

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

X, N, *P = map(int, read().split())
se = frozenset(P)

def gen_nums(X):
  low, high = X-1, X
  while True:
    yield high
    yield low
    low, high = low-1, high+1

for x in gen_nums(X):
  if x not in se:
    break

print(x)

Submission status: Accepted

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

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

p.sort()

ans = 1000000

memo = x

for i in range(0,102):
    if i not in p and abs(i-x) < ans:
        ans = abs(i-x)
        memo = i
print(memo)

Submission status: Accepted

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


for i in range(100):
    ans = X - i
    if ans not in LP:
        print(ans)
        exit()
    else:
        dans = X + i
        if dans not in LP:
            print(dans)
            exit()

Submission status: Accepted

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

result = x
if n != 0:
    for i in range(0, 1000):
        if not (x - i) in p:
            print(x - i)
            break
        if not (x + i) in p:
            print(x + i)
            break
else:
    print(x)

Submission status: Accepted

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

for i in range(0,102):
  if i not in p:
    nai.append(i)
nai.append(X)
nai.sort()
ind=nai.index(X)
if abs(nai[ind-1]-X)<=abs(nai[ind+1]-X):
  print(nai[ind-1])
else:
  print(nai[ind+1])

Submission status: Accepted

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

for i in range(N):
  if(P[i] > X):
    L = P[:i][::-1]
    U = P[i:]
    break
  elif(i == N-1):
    L = P[::-1]
    U = []

if (len(L) == 0 or L[0] != X):
  print(X)
  exit()

lans = -1
for i in range(1, len(L)):
  if (L[i-1] - L[i] > 1):
    lans = L[i-1]-1
    break
if(lans == -1):
  lans = L[len(L)-1]-1

if (len(U) == 0 or U[0] != X+1):
  uans = X+1
else:
  uans = -1
  for i in range(1, len(U)):
   if (U[i] - U[i-1] > 1):
      uans = U[i-1]+1
      break
  if(uans == -1):
    uans = U[len(U)-1]+1

if(abs(lans-X) <= abs(uans-X)):
  print(lans)
else:
  print(uans)

Submission status: Accepted

Solution code:
import sys
 
x, n = map(int, input().split())
ps = list(map(int, input().split()))
 
# n=0の時の例外処理
if n==0:
  print(x)
  sys.exit()
 
for i in range(0, 101):
  if not((x-i) in ps):
    print(x-i)
    sys.exit()
  if not((x+i) in ps):
    print(x+i)
    sys.exit()

Submission status: Accepted

Solution code:
x, n = [int(_) for _ in input().rstrip("\n").split(" ") if _]
if n > 0:
  p = set([int(_) for _ in input().rstrip("\n").split(" ")])
else:
  p = set([])
for diff in range(51):
    if not (x - diff) in p:
        print((x - diff))
        break
    if not (x + diff) in p:
        print((x + diff))
        break

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
if n == 0:
    print(x)
else:
    P = set(map(int, input().split()))
    NP = [i for i in range(0, 102) if i not in P]
    mx = 102
    for p in NP:
        mx = min(mx, p, key=lambda p: abs(x-p))
    print(mx)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
if n == 0:
    print(x)
else:
    P = set(map(int, input().split()))
    NP = [i for i in range(0, 102) if i not in P]
    mx = 102
    for p in NP:
        if abs(x-p) < abs(x-mx):
            mx = p
    print(mx)

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
if n==0:
    print(x)
    exit()
List=list(map(int,input().split()))
ans=list(range(0,102))
min_num=1000
for i in List:
    ans.remove(i)
for i in ans:
    if(abs(i-x)<abs(min_num-x)) or (abs(i-x)==abs(min_num-x) and i<min_num):
        min_num=i
print(min_num)

Submission status: Accepted

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

X, N = LI()
p = LI()

ans = mod
for i in range(100):
    if X - i not in p:
        ans = X - i
        break
    if X + i not in p:
        ans = X + i
        break

print(ans)

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

for i in range(N):
  X_ = X+i
  _X = X-i
  
  if not _X in p:
    print(_X)
    sys.exit()
  elif not X_ in p:
    print(X_)
    sys.exit()
print(X-1)

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
if n==0:
    print(x)
    exit()
List=list(map(int,input().split()))
ans=list(range(0,102))
min_num=1000
for i in List:
    ans.remove(i)
for i in ans:
    if (abs(i-x)<abs(min_num-x)) or (abs(i-x)==abs(min_num-x) and i<min_num):
        min_num=i
print(min_num)

Submission status: Accepted

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

max = X
min = X

while True:
    if min not in p:
        print(min)
        exit()
    if max not in p:
        print(max)
        exit()
    max+=1
    min-=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)
    exit()
  if X + count not in p:
    print(X+count)
    exit()
  count += 1

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
x,n=map(int,input().split())
if n == 0:
  print(x)
  sys.exit()
  
a={int(i) for i in input().split()}
i=0
while True:
  if not (x-i) in a:
    print(x-i)
    sys.exit()
  
  if not (x+i) in a:
    print(x+i)
    sys.exit()
  i+= 1

Submission status: Accepted

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

d = 0
while True:
    if X - d not in p:
        print(X - d)
        exit()
    elif X + d not in p:
        print(X + d)
        exit()
    else:
        d += 1

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
if n == 0:
  print(x)
else:
  p = list(map(int, input().split()))
  q = [True] * 102
  for i in range(n):
    q[p[i]] = False
  d_min = 10**3
  for j in range(102):
    if q[j]:
      d = abs(x - j)
      if d_min > d:
        d_min = d
        ans = j
  print(ans)

Submission status: Accepted

Solution code:
X,N = map(int,input().split())
P = {}
if N > 0:
  for p in input().split():
    i = int(p)
    P[i] = 0
x = X
n = -1
while True:
  if not x in P:
    break
  x = X + n
  n *= -1
  if n < 0:
    n -= 1
print(x)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
if n == 0: print(x); exit()
C = [0]*(101+1) # candidate:[0,101]
for p in map(int, input().split()): C[p] = 1
for d in range(100):
    c = x - d
    if not C[c]: print(c); exit()
    c = x + d
    if not C[c]: print(c); exit()

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
if n == 0: print(x); exit()
C = [0]*(101+1) # candidate:[0,101]
for p in map(int, input().split()):
    C[p] = 1
ans = x
d = 1000000000
for c in range(101+1):
    if not C[c] and d > abs(x - c):
        d = abs(x - c)
        ans = c
print(ans)

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
if X <= 50:
  l = X
  d = 0
else:
  l = 101 - X
  d = 101

if N == 0:
  print(X)
  exit()
elif N == 100:
  print(d)
  exit()
else:
  p = set(map(int, input().split()))

for i in range(100):
  if i+1 not in p:
    li = abs(X-i-1)
    if li < l:
      l = li
      d = i+1
    elif li == l:
      if i+1 < d:
        d = i+1
    elif li > l:
      break
print(d)

Submission status: Accepted

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

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

Submission status: Accepted

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

result = X

try:
    p = set(map(int, input().split()))
    if X not in p:
        result = X
    else:
        for i in range(1, 101):
            if X - i not in p:
                result = X - i
                break
            elif X + i not in p:
                result = X + i
                break
    print(result)
except:
    print(result)

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
if N > 0:
    P = list(map(int, input().split()))
    A = [0]*102
    cnt = 0
    res = float('Inf')
    for n in range(N):
        A[P[n]] += 1
    for a in A:
        if a == 0:
            total = abs(X - cnt)
            if res > total:
                res = total
                man = cnt
        cnt += 1
    print(man)
else:
    print(X)

Submission status: Accepted

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

# 0,101は含まなければいけない
P_n = [i for i in range(102) if i not in P]
abs_value = [abs(X-P_n[j]) for j in range(len(P_n))]


min_abs = min(abs_value)
for k in range(len(abs_value)):
    if abs_value[k] == min_abs:
        print(P_n[k])
        break

Submission status: Accepted

Solution code:
x,n,*p=map(int,open(i:=0).read().split())
while x in p:x+=(-1)**i*i;i+=1
print(x)

Submission status: Accepted

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


P_n = [i for i in range(102) if i not in P]
abs_value = [abs(X-P_n[j]) for j in range(len(P_n))]


min_abs = min(abs_value)
for k in range(len(abs_value)):
    if abs_value[k] == min_abs:
        print(P_n[k])
        break

Submission status: Accepted

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


P_n = [i for i in range(105) if i not in P]
abs_value = [abs(X-P_n[j]) for j in range(len(P_n))]


min_abs = min(abs_value)
for k in range(len(abs_value)):
    if abs_value[k] == min_abs:
        print(P_n[k])
        break

Submission status: Accepted

Solution code:
def actual(X, N, P):
    # 解の候補: [0, 101] かつ Pに含まれていない
    nums = set(range(0, 101 + 1)) - set(P)

    # [min — Python 3.8.3(https://docs.python.org/ja/3/library/functions.html#min)
    return min(nums, key=lambda n: abs(n - X))

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

print(actual(X, N, P))

Submission status: Accepted

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


P_n = [i for i in range(110) if i not in P]
abs_value = [abs(X-P_n[j]) for j in range(len(P_n))]


min_abs = min(abs_value)
for k in range(len(abs_value)):
    if abs_value[k] == min_abs:
        print(P_n[k])
        break

Submission status: Accepted

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

P_n = [i for i in range(110) if i not in P]
abs_value = [abs(X-P_n[j]) for j in range(len(P_n))]

import sys

min_abs = min(abs_value)
for k in range(len(abs_value)):
    if abs_value[k] == min_abs:
        print(P_n[k])
        sys.exit()

Submission status: Accepted

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

d_min = 1000
ans = 1000
for num in range(-1, 102):
    if num in P:
        continue
    
    d = abs(x-num)
    if d < d_min:
        d_min = d
        ans = num

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
 
p = list(map(int, input().split()))
 
p_none = [i for i in range(110) if i not in p]
p_none_sa = [abs(p_none[i]-X) for i in range(len(p_none))]
 
import sys
 
min_p_none = min(p_none_sa)
for i in range(len(p_none_sa)):
    if p_none_sa[i] == min_p_none:
        print(p_none[i])
        sys.exit()

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
*P, = map(int, input().split())
l = set(range(-200, 200)) - set(P)
m = 10 ** 7
ans = 0
for i in l:
    if abs(i - X) < m:
        ans = i
        m = abs(i - X)
print(ans)

Submission status: Accepted

Solution code:
a,b=map(int,input().split())
c=list(map(int,input().split()))
ans=0
for i in range(100):
    if a-i not in c:
        ans=a-i
        break
    elif a+i not in c:
        ans=a+i
        break
print(ans)

Submission status: Accepted

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

table = [0] * 102
for a in data:
    table[a] = 1

left = None
idx = x
while idx >= 0:
    if table[idx] == 0:
       left = idx
       break
    idx -= 1
idx = x
right = None
while idx < 102:
    if table[idx] == 0:
        right = idx
        break
    idx += 1

lscore = abs(x-left)
rscore = abs(x-right)

if lscore <= rscore:
    print(left)
else:
    print(right)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10000000)

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

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


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

l=[0] * 102

for i in p:
    l[i] =1

diff=1000
ans=0
for i in range(0,102):
    if l[i] == 0 and diff > abs(x-i):
        diff= abs(x-i)
        ans=i

print(ans)

Submission status: Accepted

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

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

p_none = [i for i in range(110) if i not in p]
p_none_sa = [abs(p_none[i]-X) for i in range(len(p_none))]

import sys

min_p_none = min(p_none_sa)
for i in range(len(p_none_sa)):
    if p_none_sa[i] == min_p_none:
        print(p_none[i])
        sys.exit()

Submission status: Accepted

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

p.sort()
if len(p) == 0 or x < p[0] or p[-1] < x or x not in p:
    ans = x
else:
    d = x
    ans = 0
    for i in range(p[0] - 1, p[-1] + 2):
        if i not in p and abs(x - i) < d:
            ans = i
            d = abs(x - i)
print(ans)

Submission status: Accepted

Solution code:
X,N=map(int,input().split())
if N==0:
  print(X)
  exit()
p=list(map(int,input().split()))
ans=0
check=100
for i in range(101+1):
  if i in p:
    continue
  if abs(X-i)<check:
    check=abs(X-i)
    ans=i
print(ans)

Submission status: Accepted

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

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

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

nip_temp = []
for i in not_in_p:
    nip_temp.append(abs(x-i))

address = nip_temp.index(min(nip_temp))
print(not_in_p[address])

Submission status: Accepted

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


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

Submission status: Accepted

Solution code:
#ABC170C ×

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

if n == 0:
    print(x)
    
else:
    _x = x 
    x_ = x
    while True:
        if _x not in p:
            print(_x)
            break
        if x_ not in p:
            print(x_)
            break
        _x -= 1
        x_ += 1

Submission status: Accepted

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


for i in range(101):
    if x - i not in p:
        print(x - i)
        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()))
p = sorted(p)
q = 10000
r = 10000
for i in range(0, 102):
    if i not in p:
        if q > abs(i-x):
            q = abs(i-x)
            r = i
print(r)

Submission status: Accepted

Solution code:
from sys import stdin
import sys
import math
import random
from decimal import Decimal
 
 
X, N = [int(x) for x in stdin.readline().rstrip().split()]
 
if N == 0:
    print(X)
    sys.exit()
p = list(map(int, input().split()))
 
ans = 10**9
ans1 = [X, 10**9]
for i in range(-100, 105):
    if i not in p:
        if ans > abs(X-i):
            ans = abs(X-i)
            # print(i, abs(X-i))
            if ans1[1] == abs(X-i):
                pass
            else:
                ans1[1] = abs(X-i)
                ans1[0] = i
            # ans1[1] = abs(X-i)
            # if ans1 > i:
            #     ans1 = i
                # print(i)
print(ans1[0])

Submission status: Accepted

Solution code:
X, n = map(int, input().split())
print(min(set(range(0, 102))-set(map(int, input().split())), key=lambda x: abs(x-X)))

Submission status: Accepted

Solution code:
X, n = map(int, input().split())
Ps = set(map(int, input().split()))
cood = set(range(0, 102))
cood -= Ps
print(min(cood, key=lambda x: abs(x-X)))

Submission status: Accepted

Solution code:
X , N = map(int, input().split())
p = list(map(int,input().split()))
ans = []
if N == 0:
    print(X)
elif X not in  p:
    print(X)
else:
    p = sorted(p)
    p2 = [abs(i-X) for i in p]

    for i in range(p[p2.index(min(p2))],102):
        if i not in p:
            ans.append(i)
            break
    for i in range(p[p2.index(min(p2))], -100, -1):
        if i not in p:
            ans.append(i)
            break
    
    ans = sorted(ans)
    ans2 = [abs(i-X) for i in ans]
    print(ans[ans2.index(min(ans2))])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
def get_input() -> tuple:
    """
    標準入力を取得する.

    Returns:\n
        tuple: 標準入力
    """
    X, N = list(map(int, input().split()))
    p = list(map(int, input().split()))

    return X, N, p


def main(X: int, N: int, p: list) -> None:
    """
    求解処理を行う.

    Args:\n
        X (int): 整数
        N (int): 長さ
        p (list): 整数列
    """
    # 求解処理
    ans = 0
    diff = 0
    while True:
        # Xとの差がdiffのうち小さいほう
        x_minus = X - diff
        if x_minus not in p:
            ans = x_minus
            break
        # Xとの差がdiffのうち大きいほう
        x_plus = X + diff
        if x_plus not in p:
            ans = x_plus
            break

        diff += 1

    # 結果出力
    print(ans)


if __name__ == "__main__":
    X, N, p = get_input()
    main(X, N, p)

Submission status: Accepted

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

line = [0]*(102)
for p in Ps:
    line[p] = 1

for i in range(101):
    L, R = x-i, x+i
    if line[L] == 0:
        print(L)
        break
    if line[R] == 0:
        print(R)
        break

Submission status: Accepted

Solution code:
X,N=map(int,input().split())
P=list(map(int,input().split()))
ans=0
for i in range(100):
    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 = list(map(int, input().split()))
P = list(map(int, input().split()))

min_ = 100
for i in range(0, 102):
    cur = i 
    if cur in P:
        continue
    diff = abs(X - cur)
    if diff < min_:
        min_ = diff

front = X - min_
back = X + min_
if front not in P:
    print(front)
else:
    print(back)

Submission status: Accepted

Solution code:
import sys
import numpy as np
import math
from collections import deque 
from functools import reduce

# input = sys.stdin.readline
x, y = map(int, input().split())
if y == 0:
    print(x)
    exit()
p = [list(map(int, input().split()))]
p_n = np.array(p)
p_n = p_n.reshape(-1)
pp = np.arange(0, 102)
for i in p_n:
    pp[i] += 10000
sa = min(abs(pp-x))
if sa <= 101:
    if pp[x-sa] >= 10000:
        print(x+sa)
    else:
        print(x-sa)
else:
    print("0")

Submission status: Accepted

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

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

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

for diff in range(200):
  if x-diff not in p:
    print(x-diff)
    exit()

  if x+diff not in p:
    print(x+diff)
    exit()

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
try:
  p=set(map(int, input().split()))
except Exception:
  p=set()
i = 0
while 1: 
  ans = X - i
  if ans not in p:
    print(ans)
    break
  ans = X + i
  if ans not in p:
    print(ans)
    break
  i = i + 1

Submission status: Accepted

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

for i in range(110):
    if X-i not in p:
        print(X-i)
        exit()
    if X+i not in p:
        print(X+i)
        exit()

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
p_s = list(map(int, input().split()))
 
p_s.sort()
ans = 0
tmp_diff = float('inf')
 
for num in range(-300,301):
    if(num not in p_s):
        diff = abs(X - num)
        if (diff < tmp_diff):
            ans = num
            tmp_diff = diff
            
print(ans)

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, *P = map(int, open(0).read().split())
P = set(P)
for i in range(51):
    Q = {x-i, x+i} - P
    if Q:
        print(min(Q))
        break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x, n, *P = map(int, open(0).read().split())
for i in range(51):
	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 = input().split()
x = int(x)
n = int(n)

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

	ans = -1
	mn = 10000

	for i in range(0, 102):
		if(p.count(i) == 0):
			d = x - i
			if d<0:
				d = -d
			if d<mn:
				ans = i
				mn = d
	print(ans)

Submission status: Accepted

Solution code:
import sys

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

sa = 300

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

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
l = list(map(int, input().split()))
flg = False
t = x
while flg == False:
  if t in l:
    t -= 1
  else:
    ans = t
    flg = True
flg = False
t = x
while flg == False:
  if t in l:
    t += 1
  else:
    if abs(x-ans) > abs(x-t):
      ans = t
    flg = True
print(ans)

Submission status: Accepted

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

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

	ans = -1
	mn = 10000

	for i in range(-1, 102):
		if(p.count(i) == 0):
			d = x - i
			if d<0:
				d = -d
			if d<mn:
				ans = i
				mn = d
	print(ans)

Submission status: Accepted

Solution code:
x,n=map(int, input().split())
p = list(map(int, input().split()))
p=sorted(p)
last=1000
zettai=1000
for i in range(0, 102):
    if i not in p:
        if zettai>abs(i-x):
            zettai=abs(i-x)
            last=i
print(last)

Submission status: Accepted

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

cand = []
P = set(P)
for i in range(0, 102):
    if i in P:
        continue
    cand.append((abs(X - i), i))

cand.sort()

print(cand[0][1])

Submission status: Accepted

Solution code:
import sys
# from collections import deque
# from collections import Counter
# from math import sqrt
# from math import log
# from math import ceil

# def gcd(a, b):
# 	if(a==0):
# 		return b 
# 	return gcd(b%a,a)

# def sieve(n): 
# 	prime=[True for i in range(n+1)]
# 	p=2
# 	while(p*p<=n): 
# 		if (prime[p]==True): 
# 			for i in range(p*p,n+1,p): 
# 				prime[i]=False
# 		p+=1
# 	prime[0]=False
# 	prime[1]=False
# 	s=set()
# 	for i in range(len(prime)):
# 		if(prime[i]):
# 		s.add(i)
# 	return s 

# alpha=['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
# mod=10**9+7

fast_reader=sys.stdin.readline
fast_writer=sys.stdout.write

def input():
	return fast_reader().strip()

def print(*argv):
	fast_writer(' '.join((str(i)) for i in argv))
	fast_writer('\n')

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

def sep_input():
	return map(int, input().split())

#_______________________________________________________________________________________________________________________________________

x,n=sep_input()
l=list_input()
s=set(l)
i=0
while(True):
	if(x-i not in s):
		print(x-i)
		break
	elif(x+i not in s):
		print(x+i)
		break
	else:
		i+=1

Submission status: Accepted

Solution code:
# C - Forbidden List
def main():
    X, _, *P = map(int, open(0).read().split())
    ans = min(set(range(-1, 102)) - set(P), key=lambda x: abs(X - x))
    print(ans)


if __name__ == "__main__":
    main()

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()))
p.sort()
wk = 101
an = 0
#if n ==100:
 #   print(0)
  #  sys.exit()
for i in range(102):
    #if x!=i:
    if p.count(i)==0:
        if abs(x-i)<wk:
            an =i
            wk = abs(x-i)

print(an)

Submission status: Accepted

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


for i in range(200):
    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:
def main():

    x, n = map(int, input().split())
    ans = 0
    if n == 0:
        ans = x
        print(f'{ans}')
        exit()
    else:
        p = [int(i) for i in input().split()]

    for i in range(0, 102):
        if abs(x - i) not in p:
            ans = abs(x - i)
            break
        if x + i not in p:
            ans = x + i
            break
    
    print(f'{ans}')


if __name__ == '__main__':
    main()

Submission status: Accepted

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

for i in range(100):
    lr = [x - i, x + i]
    for y in lr:
        if y not in p:
            print(y)
            exit()

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
arr = list(map(int, input().split()))
 
ans = 0
for i in range(1, 102):
    if abs(X - i) < abs(X - ans) and i not in arr:
        ans = i
print(ans)

Submission status: Accepted

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

temp = x
d = 0

while 1:
    if temp - d not in p:
        print(temp - d)
        exit()
    if temp + d not in p:
        print(temp + d)
        exit()
    d += 1

Submission status: Accepted

Solution code:
x , n = map(int,input().split())
numberbuffer = 0
diff = 100000

if n == 0:
    print(x)
else:
    
    p = list(map(int,input().split()))
    
    pinverse = []
    
    for i in range(max(p)*2 +2):
        if (i-max(p)) not in p:
            pinverse.append(i-max(p))
        
    for y in pinverse:
        
        if abs(x-y) < diff:
            diff = abs(x-y)
            numberbuffer = y
        
        if diff == abs(x-y):
            if numberbuffer > y:
                numberbuffer = y
    
    print(numberbuffer)

Submission status: Accepted

Solution code:
def main():

    x, n = map(int, input().split())
    ans = 0
    if n == 0:
        ans = x
        print(f'{ans}')
        exit()
    else:
        p = [int(i) for i in input().split()]

    for i in range(n):
        if x - i not in p:
            ans = x - i
            break
        if x + i not in p:
            ans = x + i
            break
    
    print(f'{ans}')


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
x,n,*p=map(int,open(0).read().split())
i=0
while x in p:x+=(-1)**i*i;i+=1
print(x)

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
p = list(map(int, input().split()))
 
ans = 0
for i in range(1, 102):
    if abs(X - i) < abs(X - ans) and i not in p:
        ans = i
print(ans)

Submission status: Accepted

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

mn = 10**10
ans_li = []

for i in range(-200,201):
    if i not in p and abs(x - i) <= mn:
        ans_li.append(i)
        mn = abs(x - i)

for aa in ans_li:
    if abs(aa - x) == mn:
        print(aa)
        break