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

p = set(p)
for i in range(200):
    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:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))
X, N = mi()
A = li()

flag = [0] * (205)

for num in A:
    flag[num] = 1

if not flag[X]:
    print(X)
    exit()

i = 1
while True:
    if not flag[X - i]:
        print(X-i)
        exit()
    elif not flag[X + i]:
        print(X+i)
        exit()
    i += 1

Submission status: Accepted

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

for i in range(100):
    if x-i not in p:
        print(x-i)
        sys.exit()
    if 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()))

diff = 100
for x in range(-100, 201):
    tmp = abs(X - x)
    if x in P:
        continue
    else:
        if tmp < diff:
            ans = x
            diff = tmp

print (ans)

Submission status: Accepted

Solution code:
import sys
X, N = map(int,input().split())
P = list(map(int,input().split()))
ans = X
d = 1
if not ans in P:
    print(ans)
    sys.exit()
while True:
    if not ans - d in P:
        print(ans - d)
        break
    if not ans + d in P:
        print(ans + d)
        break
    d += 1

Submission status: Accepted

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

for i in range(200):
  MIN = X-i
  MAX = X+i
  if MIN not in pset:
    print(MIN)
    exit()
  elif MAX not in pset:
    print(MAX)
    exit()

Submission status: Accepted

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

    d, v = X, 0
    for i in range(102):
        if i in P:
            continue
        if abs(i - X) < d:
            d = abs(i - X)
            v = i
    return v


print(main())

Submission status: Accepted

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

for i in range(100):
  if X-i in p:
    pass
  else:
    print(X-i)
    exit()
    
  if X+i in p:
    pass
  else:
    print(X+i)
    exit()

Submission status: Accepted

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

  check=x
  if (p.count(x)==0):
      print(check)
  else:
      check1=check
      check2=check
      for i in range(100):
          check1=check1-1
          if (p.count(check1)==0):
              print(check1)
              break
          check2=check2+1
          if (p.count(check2)==0):
              print(check2)
              break

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    X, N = LI()
    P = LI()
    s = set(P)
    diff = inf
    ans_x = -1
    for x in range(-101, 300):
        if x in s:
            continue
        if abs(x-X) < diff:
            diff = abs(x-X)
            ans_x = x
    print(ans_x)





main()

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(1000000)

import bisect
import math
import collections
import heapq


def solve(X, N, Ps):
    Ps = set(Ps)
    d = 0
    while True:
        if X - d not in Ps:
            return X - d
        if X + d not in Ps:
            return X + d
        d += 1


if __name__ == "__main__":
    X, N = tuple(map(int, input().split(" ")))
    Ps = []
    if N > 0:
        Ps = list(map(int, input().split(" ")))
    print(solve(X, N, Ps))

Submission status: Accepted

Solution code:
X,N=map(int,input().split())
if(N==0):
  print(X)
  exit()
p=list(map(int,input().split()))
#0~100
flag=False
for i in range(200):
  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:
def main():
    X, N = map(int, input().split())
    *P, = map(int, input().split())

    B = [0] * (400 + 1)
    for i in P:
        B[i] += 1

    d = 0
    while True:
        if not B[X - d]:
            print(X - d)
            return

        if not B[X + d]:
            print(X + d)
            return

        d += 1


if __name__ == '__main__':
    main()

# import sys
# input = sys.stdin.readline
# 
# sys.setrecursionlimit(10 ** 7)
# 
# (int(x)-1 for x in input().split())
# rstrip()
#
# def binary_search(*, ok, ng, func):
#     while abs(ok - ng) > 1:
#         mid = (ok + ng) // 2
#         if func(mid):
#             ok = mid
#         else:
#             ng = mid
#     return ok

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = set(list(map(int, input().split())))
a = set(list(range(102)))
a = list(a - p)
a.sort()

tmp = 10 ** 10
for i in a:
    if tmp > abs(x - i):
        tmp = abs(x - i)
        ans = i
print(ans)

Submission status: Accepted

Solution code:
x, n = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]
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:
X, N = map(int, input().split())
p = list(map(int, input().split()))
ans = 0
for i in range(102):
  if i not in p:
    if abs(i-X)<abs(ans-X):
      ans = i
print(ans)

Submission status: Accepted

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

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

ans = 10000
for r in range(-1, 105):
    if r in p:
        continue
    ans = min(ans, r, key=lambda y: abs(x-y))

print(ans)

Submission status: Accepted

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

pset=set(map(int,input().split()))
for i in range(1000):
  if not X-i in pset:
    print(X-i)
    sys.exit(0)
  if not X+i in pset:
    print(X+i)
    sys.exit(0)

Submission status: Accepted

Solution code:
import sys

def solve():
    input = sys.stdin.readline
    X, N = map(int, input().split())
    P = [int(p) for p in input().split()]
    Num = [True] * 102
    for p in P: Num[p] = False
    minDiff = 10000000000
    ans = 0
    for i, t in enumerate(Num):
        if t == True and abs(X - i) < minDiff:
            ans = i
            minDiff = abs(X - i)
    print(ans)

    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
import sys, math
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

X, N = rl()
P = rl()

h = {}
for p in P:
	h[p] = 1

for i in range(105):
	if X-i not in h:
		print(X-i)
		exit()
	if X+i not in h:
		print(X+i)
		exit()

Submission status: Accepted

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

for i in range(100):
    x_m = x-i
    if not x_m in p:
        print(x_m)
        exit()
    x_p = x+i
    if not x_p in p:
        print(x_p)
        exit()

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
P=list(map(int,input().split()))
if x not in P:
    print(x)
else:
    i=0
    while True:
        i+=1
        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 = set(map(int, input().split()))

ans=-200000

for i in range(-200,200):
    if not i in p:
        if abs(x-ans)>abs(x-i):
            ans=i

print(ans)

Submission status: Accepted

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

dist = []
for i in range(102):
    if i in p:
        dist.append((i, INF))
    else:
        dist.append((i, abs(x - i)))

dist.sort(key=lambda x: x[1])
print(dist[0][0])

Submission status: Accepted

Solution code:
def examA():
    X = LI()
    for i in range(len(X)):
        if X[i]==0:
            ans = i+1
    print(ans)
    return

def examB():
    X, Y = LI()
    ans = "No"
    for i in range(X+1):
        if i*2+(X-i)*4==Y:
            ans = "Yes"
    print(ans)
    return

def examC():
    X, N = LI()
    P = LI()
    P = set(P)
    cur = inf
    ans = -1
    for i in range(-1,102):
        if i in P:
            continue
        now = abs(i-X)
        if now<cur:
            ans = i
            cur = now
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

from decimal import Decimal as dec
import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def DI(): return dec(input())
def LDI(): return list(map(dec,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examC()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Submission status: Accepted

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

ans = 0
res = 10**9
for i in range(x-100, x+101):
    if i in p:
        continue
    diff = abs(x-i)
    if diff < res:
        ans = i
        res = diff
print(ans)

Submission status: Accepted

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

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

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

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

print(ans)

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
p=set(map(int,input().split()))
ans=0
a=1000000
for i in range(-1000,1000):
    if abs(x-i)<a and (not i in p):
        ans=i
        a=abs(x-i)
print(ans)

Submission status: Accepted

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

res = -100
for r in range(-100,200):
    if r not in pl:
        if abs(x-r)<abs(x-res):
            res = r
print(res)

Submission status: Accepted

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

diff = 1e9
ans = -1
for i in range(0,102):
    if i not in arr:
        d = abs(x-i)
        if d < diff:
            diff = d
            ans = i

print(ans)

Submission status: Accepted

Solution code:
x, n = [int(_) for _ in input().split()]
p = set([int(_) for _ in input().split()])
cand = []
for i in range(102):
    if i in p:
        continue
    cand += [(abs(i - x), i)]
cand.sort()
print(cand[0][1])

Submission status: Accepted

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

for i in range(100):
    if x - i not in p:
        print(x - i)
        exit()

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

Submission status: Accepted

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


def solve(X: int, N: int, p: "List[int]"):
    for i in range(101):
        if (X - i) not in p:
            print(X-i)
            return
        elif (X + i) not in p:
            print(X+i)
            return

    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    N = int(next(tokens))  # type: int
    p = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(X, N, p)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
p=list(map(int,input().split()))
for i in range(100):
    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:
def main():

    X, N = map(int, input().split())
    if N == 0: return X
    p = list(map(int, input().split()))

    p = set(p)
    ans = 1
    l = float('inf')
    for i in range(-1, 102):
        if i not in p and abs(i-X) < l:
            l = abs(i-X)
            ans = i
    return ans



if __name__ == '__main__':
    print(main())

Submission status: Accepted

Solution code:
import sys
input=lambda: sys.stdin.readline().rstrip()
x,n=map(int,input().split())
P=set([int(i) for i in input().split()])
ans=0
for i in range(1,102):
  if i in P:
    continue
  else:
    if abs(i-x)<abs(ans-x):
      ans=i
print(ans)

Submission status: Accepted

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

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

ans = 0
d = 10 ** 9

for i in range(-200, 201):
    if i not in p:
        if abs(x - i) < d:
            d = abs(x - i)
            ans = i

print(ans)

Submission status: Accepted

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

for i in range(0,100):
    if x-i not in pl:
        print(x-i)
        break
    elif x+i not in pl:
        print(x+i)
        break

Submission status: Accepted

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

def main():
    x, N = map(int, input().split())
    P = set(map(int, input().split()))
    d = 0
    while True:
        if x + d in P and x - d in P:
            d += 1
            continue
        else: break
    if x - d in P: print(x + d)
    else: print(x - d)
    

if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys

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

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

best_diff = 10000000
best_a = -2
for a in range(-5, 1000):
	if not a in p:
		diff = abs(x - a)
		if diff < best_diff:
			best_diff = diff
			best_a = a

print(best_a)

Submission status: Accepted

Solution code:
nii=lambda:map(int,input().split())
lnii=lambda:list(map(int,input().split()))

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

dist=1000
ans=[]
aa=[]
for i in range(-10,110):
  if i not in p:
    ans.append(abs(x-i))
    aa.append(i)
min_inx=ans.index(min(ans))
print(aa[min_inx])

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
if n == 0:
  print(x)
  exit()
a = list(map(int,input().split()))
b = [0 for _ in range(-300,301)]
for y in a:
  b[y+300] = 1
c = []
for i in range(601):
  j = i - 300
  if b[i] == 0:
    c.append([abs(x-j),j])
print(min(c)[1])

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
set_ = set([])
if n == 0:
    pass
else:
    set_ = set(list(map(int, input().split())))

diff = 10 ** 18
ans = -1
for num in range(-1000, 1000)[::-1]:
    if num in set_:
        continue
    if abs(num - x) <= diff:
        diff = abs(num - x)
        ans = num
print(ans)

Submission status: Accepted

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

X,N,*P = map(int, sys.stdin.buffer.read().split())

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

Submission status: Accepted

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

p = set(p)

for i in range(0, 200) :
  if not X - i in p :
    print(X - i)
    break
    
  if not X + i in p :
    print(X + i)
    break

Submission status: Accepted

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

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

Submission status: Accepted

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

X,N=map(int,input().split())
P=list(map(int,input().split()))
A=[]
for a in range(0,102):
    if not a in P:
        A.append(a)

ans=0
for a in A:
    if abs(X-a) < abs(X-ans):
        ans=a

print(ans)

Submission status: Accepted

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

if not x in p:
    print(x)
    exit()
for i in range(1,200):
    if not x-i in p:
        print(x-i)
        exit()
    elif not x+i in p:
        print(x+i)
        exit()

Submission status: Accepted

Solution code:
X,N=map(int,input().split())
p=set(map(int,input().split()))
t=200
a=1000
for i in range(101,-1,-1):
    if i not in p:
        if abs(i-X)<=t:
            a=i
            t=abs(i-X)
print(a)

Submission status: Accepted

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

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

sa = 1
while True:
    if x-sa not in p:
        print(x-sa)
        exit()
    if x+sa not in p:
        print(x+sa)
        exit()
    sa += 1

Submission status: Accepted

Solution code:
X, N = map(int, input().split(' '))
if N > 0:
    P = set(map(int, input().split(' ')))
else:
    P = set()

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from collections import *

X, N = map(int, input().split())
p = list(map(int, input().split()))
s = set(p)
low = X-1000
high = X+1000
d = 10**18

for i in range(low, high+1):
    if i not in s:
        d = min(d, abs(X-i))
    
for i in range(low, high+1):
    if i not in s and abs(X-i)==d:
        print(i)
        exit()

Submission status: Accepted

Solution code:
from sys import stdin
from sys import setrecursionlimit
import bisect
setrecursionlimit(10 ** 7)

x,n = map(int,stdin.readline().rstrip().split())
p = list(map(int,stdin.readline().rstrip().split()))
p.sort()
mi = 10**10
now = 10**10

for i in range(-1000,1000):
    if i not in p:
        if abs(i-x) < mi:
            mi = abs(i-x)
            now = i

print(now)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = set([int(i) for i in input().split()])
ans = 1000
for i in range(-100, 200):
    if i in p:
        continue
    if abs(i - x) < abs(ans - x):
        ans = i

print(ans)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
a = set(list(map(int, input().split())))
ans_d = 10000
ans = -1
for i in range(-100,1000):
    if abs(x - i) < ans_d and i not in a:
        ans = i
        ans_d = abs(x - i)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

import sys
import numpy as np
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

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

for i in range(0, 10000):
    acc = (X - i, X + i)
    for x_ in acc:
        if x_ not in P:
            print(x_)
            sys.exit()

Submission status: Accepted

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

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

B = set(A)
t = 10**15
ans = -1
for i in range(103):
    if not i in B and abs(i-X) < t:
        t = abs(i-X)
        ans = i

print(ans)

Submission status: Accepted

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

ans=100
mindif=100000
for i in reversed(range(-200,200)):
    if i in p:
        continue
    if mindif>abs(i-X):
        ans=i
        mindif=abs(i-X)
    elif mindif==abs(i-X):
        ans=min(ans,i)
print(ans)

Submission status: Accepted

Solution code:

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

for i in range(200):
    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:
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 = list(map(int, input().split()))
if N != 0:
  p = list(map(int, input().split()))
else:
  p = []

ans = 1000000
ansabs = 1000000
for i in range(0, 102):
  if i in p: continue
  if abs(X - i) < ansabs:
    ansabs = abs(X - i)
    ans = i

print(ans)

Submission status: Accepted

Solution code:
# C - Forbidden List
X,N = map(int,input().split())
p = list(map(int,input().split()))
ans = X
for i in range(0,1000):
    ans = X-i
    if ans not in p:
        break
    ans = X+i
    if ans not in p:
        break
print(ans)

Submission status: Accepted

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

x, n = LI()
p = LI()
tmp = 0
while 1:
    if x - tmp not in p:
        print(x-tmp)
        quit()
    elif x + tmp not in p:
        print(x+tmp)
        quit()
    tmp += 1

Submission status: Accepted

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

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

if not (X in P):
    print(X)
else:
    ANS=-1
    for i in range(100):
        for to in [X-i,X+i]:
            if not(to in P):
                ANS=to
                break
        if ANS!=-1:
            break
    print(ANS)

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
P = set(map(int, input().split()))
ans = 101
for i in range(101, -1, -1):
    if i not in P:
        if abs(ans - X) >= abs(i - X):
            ans = i
print(ans)

Submission status: Accepted

Solution code:
X, N = [int(x) for x in input().split()]
if N:
    P  = [int(x) for x in input().split()]
    P = set(P)
else:
    P = set()
best = (float('inf'), )
for i in range(0, 102):
    if i not in P:
        best = min(best, (abs(i - X), i))
print(best[1])

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

x,n = map(int,readline().split())
lst1 = list(map(int,readline().split()))

ans = []

for i in range(-200,200):
    if i in lst1:continue
    ans.append([abs(x-i),i])

res = 1000000
a2 = 9999999
for i in ans:
    if i[0] < res:
        a2 = i[1]
        res = i[0]
print(a2)

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
p=[]
if n:
	p=list(map(int,input().split()))
ans=None
mi=float("inf")
for i in range(-300,300):
	if i not in p:
		if mi>abs(x-i):
			mi=abs(x-i)
			ans=i
print(ans)

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
A = set([int(a) for a in input().split()]) if N else []
mi = 105
mii = -1
for i in range(-1, 110):
    if i in A: continue
    if abs(i - X) < mi:
        mi = abs(i - X)
        mii = i
print(mii)

Submission status: Accepted

Solution code:
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

x,n=mp()
p=lmp()
for i in range(200):
    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()))
for i in range(200):
    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:
#!/usr/bin/env python3
import sys
input = sys.stdin.readline

x, n = map(int, input().split())
p = [int(item) for item in input().split()]
seen = set(p)

ans = None 
diff = 200
for val in range(200, -200, -1):
    if val not in seen:
        if abs(val - x) <= diff:
            ans = val
            diff = abs(val - x)

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()))
d = 1000
for i in range(102):
  if i in p:
    continue
  if abs(x-i) < d:
    ans = i
    d = abs(x-i)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import gcd

from math import factorial as f

from math import ceil,floor,sqrt
import math

import bisect
import re
import heapq


from copy import deepcopy
import itertools
from itertools import permutations

from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))


yes = "Yes"
no = "No"


def main():
    x,n = mi()
    p = li()
    for i in range(100):
        if not x-i in p:
            print(x-i)
            exit()
        elif not x+i in p:
            print(x+i)
            exit()



main()

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    x, n = map(int, input().split())
    P = set(list(map(int, input().split())))
    res = 0
    mi = f_inf
    for i in range(-200, 200):
        if i not in P:
            if abs(x - i) < mi:
                mi = abs(x - i)
                res = i
    print(res)


if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
if n == 0:
    print(x)
    exit()
P = set(map(int, input().split()))
t = float("inf")
for i in range(-200, 201):
    if i not in P and abs(i-x) < t:
        t = abs(i-x)
        ans = i
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

    for i in range(x, x+200):
        if i not in p:
            m = i
            break
    for i in range(x, x-200, -1):
        if i not in p:
            M = i
            break
    if abs(m-x) < abs(M-x):
        print(m)
    else:
        print(M)


main()

Submission status: Accepted

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

ans = 1e10
pos = 0
for i in range(-100,120):
    if i not in p:
        if abs(i-X) < ans:
            pos = i
            ans = abs(i-X)
    
print(pos)

Submission status: Accepted

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

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

Submission status: Accepted

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