Problem:


Score : 300 points

Problem Statement

Given are an integer X and an integer sequence of length N: p_1, \ldots, p_N.

Among the integers not contained in the sequence p_1, \ldots, p_N (not necessarily positive), find the integer nearest to X, that is, find the integer whose absolute difference with X is the minimum. If there are multiple such integers, report the smallest such integer.

Constraints

1 \leq X \leq 100

0 \leq N \leq 100

1 \leq p_i \leq 100

p_1, \ldots, p_N are all distinct.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

X N
p_1 ... p_N

Output

Print the answer.

Sample Input 1

6 5
4 7 10 6 5

Sample Output 1

8

Among the integers not contained in the sequence 4, 7, 10, 6, 5, the one nearest to 6 is 8.

Sample Input 2

10 5
4 7 10 6 5

Sample Output 2

9

Among the integers not contained in the sequence 4, 7, 10, 6, 5, the ones nearest to 10 are 9 and 11. We should print the smaller one, 9.

Sample Input 3

100 0

Sample Output 3

100

When N = 0, the second line in the input will be empty. Also, as seen here, X itself can be the answer.



Sample input:
6 5
4 7 10 6 5


Sample output:
8

Submission status: Accepted

Solution code:
X, N = map(int, input().split(" "))
if N != 0:
  P = set(map(int, input().split(" ")))
  assert len(P) == N
else:
  P = set([])

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

Submission status: Accepted

Solution code:

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

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

    else:
        x1=x
        x2=x
        x1=x1-i
        x2=x2+i
        if x1 not in p:
            print(x1)
            break
        
        elif x2 not in p:
            print(x2)
            break

        else:
            continue

Submission status: Accepted

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

    p.sort()

    for i in range(100):
        a = X+i
        b = X-i
        if not b in p:
            print(b)
            break
        elif not a in p:
            print(a)
            break
else:
    print(X)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# Problem C - Forbidden List
# input
X, N = map(int, input().split())

# check
if N==0:
    print(X)
else:
    p_nums = list(map(int, input().split()))
    nums = [i for i in range(-1000, 1001)]
    # remove process
    for p in p_nums:
        nums.remove(p)
    point = 0
    # greedy
    kyori = float('INF')
    for n in nums:
        tmp = min(abs(X-n), abs(n-X))
        if tmp<kyori:
            point = n
            kyori = tmp

    # output
    print(point)

Submission status: Accepted

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


def solve(X: int, N: int, p: "List[int]"):
    p.sort()

    Q = []
    for q in range(-200, 200):
        if q not in p:
            Q.append(q)

    Q_diff = [abs(a - X) for a in Q]

    mn = min(Q_diff)

    ans_idx = Q_diff.index(mn)
    ans = Q[ans_idx]

    print(ans)
    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:
from collections import defaultdict
x, n = [int(i) for i in input().split()]
arr = [int(i) for i in input().split()]
Dict = defaultdict(int)
for i in arr:
    Dict[i] = 1
ans = int(1e9)
val = -1
for i in range(0,200):
    if Dict[i] == 0:
        diff = abs(x - i)
        if diff < ans:
            val = i
            ans = diff
print(val)

Submission status: Accepted

Solution code:
a = list(map(int, input().split()))
if a[1]!=0:
    b = list(map(int, input().split()))
    c=100
    d=0
    for i in range(201):
        if abs(a[0]-i)<c and i not in b:
            c=abs(a[0]-i)
            d=i
        if i>c+a[0]:
            break
    print(d)

else:
    print(a[0])

Submission status: Accepted

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


input = sys.stdin.readline
def IS(cb): return cb(input().strip())
def IL(cb): return [cb(s) for s in input().strip().split()]
def IR(cb, rows): return [IS(cb) for _ in range(rows)]
def ILL(cb, rows): return [IL(cb) for _ in range(rows)]


def solve():
    X, N = IL(int)
    if N > 0:
        P = IL(int)
        A = set(range(-2, 102)) - set(P)
    else:
        A = set(range(-2, 102))

    A = list(A)
    A.sort()
    i = bisect.bisect(A, X)
    print(min(A[i - 1: i + 1], key=lambda x: abs(X - x)))


solve()

Submission status: Accepted

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

for i in range(101):
  minans = X - i
  maxans = X + i
  if minans not in A:
    print(minans)
    exit(0)
  elif maxans not in A:
    print(maxans)
    exit(0)

Submission status: Accepted

Solution code:
X,N = map(int,input().split())
p = list(map(int,input().split()))
i = 0
while True:
    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())
if n==0:
  print(x)
else:
  lst=sorted(map(int,input().split()))
  dis=200
  ans=100
  for i in range(102):
    temp=abs(x-i)
    if temp<dis and i not in lst:
      dis=temp
      ans=i
  print(ans)

Submission status: Accepted

Solution code:
#import sys
#import numpy as np
import math
#import itertools
#from fractions import Fraction
#import itertools
from collections import deque
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
#import bisect
x,n=map(int,input().split())
if n==0:
  print(x)
  exit()
p=list(map(int,input().split()))
p=set(p)
res=[]
for i in range(x,-1,-1):
    if i not in p:
        res.append(i)
        break
for i in range(x+1,102):
    if i not in p:
        res.append(i)
if len(res)==1:
    print(res[0])
else:
    if x-res[0]>res[1]-x:
        print(res[1])
    else:
        print(res[0])

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
p = list(map(int,input().split()))
i = 0
ans = 0
while True:
  if(x-i in p):
    if(x+i in p):
      None
    else:
      ans = x+i
      break
  else:
    ans = x-i
    break
  i += 1
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
import math
import collections
import bisect


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

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


for i in range(200):
    ans = X - i
    if(ans not in p):
        print(ans)
        break

    ans = X + i
    if(ans not in p):
        print(ans)
        break

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
l=list(map(int,input().split()))
ans=1000
c=0
for i in range(-100,110):
    if i not in l:
        if(abs(i-x)<ans):
            ans=min(ans,abs((i-x)))
            c=i
print(c)

Submission status: Accepted

Solution code:
X,N = map(int,input().split())
p = list(map(int,input().split()))
p = set(p)
mini = 10**3
ans = 0
for i in range(10**3):
    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 = set(list(map(int, input().split())))
notP = set(list(range(-1, 102))) - P
#print(notP)

min_dif = 10000
ans = 10000
for num in list(notP):
    dif = abs(x - num)
    if dif < min_dif:
        min_dif = dif
        ans = num
    elif dif == min_dif and num < ans:
        min_dif = dif
        ans = num
print(ans)

Submission status: Accepted

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

diff = 103
ans = X
for i in range(101):
    a = X - i
    b = X + i
    if a not in P:
        ans = a
        break
    elif b not in P:
        ans = b
        break
print(ans)

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
p = list(map(int, input().split()))
small = X
big = X
while True:
    if p.count(X) == 0:
        print(X)
        break
    small -= 1
    big += 1
    if p.count(small) == 0:
        print(small)
        break
    elif p.count(big) == 0:
        print(big)
        break

Submission status: Accepted

Solution code:
import sys

X, N = map(int, sys.stdin.readline().split())
P = [int(x) for x in sys.stdin.readline().split()]

Y = [x for x in range(102)]
setY = set(Y)
setP = set(P)
R = list(setY-setP)
RX = [abs(r - X) for r in R]
i = RX.index(min(RX))
print(R[i])

Submission status: Accepted

Solution code:
from collections import Counter 
from collections import defaultdict
from collections import deque
from functools import reduce
import math
import itertools
import heapq
import numpy as np
import bisect
import sys
#import sympy
sys.setrecursionlimit(10**6)


def bfs(s,n,node):
    #頂点が探索済みかどうかのチェック配列
    check=[False for _ in range(n)]
    check[s]=True
    #次見る頂点を格納するキュー
    queue=deque([s])
    visited_num=1

    #問題固有の配列
    #color_check=[[True for _ in range(l)] for _ in range(n)]
    color=[-1 for _ in range(n)]
    color[s]=0
    
    while visited_num<n:
        #グラフが全連結ではない場合
        if len(queue)==0:
            #空配列を返す
            #現状までの計算済み配列を返してもいいと思う
            return color

        now_vertex=queue.popleft()
        #インデックスがない場合は
        for next_vertex in node[now_vertex]:


            if check[next_vertex]==True:
                continue

            queue.append(next_vertex)
            check[next_vertex]=True

            #問題固有の計算
            color[next_vertex]=color[now_vertex]+1
            visited_num+=1

    return color

#n=int(input())
#n,m=list(map(int,input().split()))
#a=list(map(int,input().split()))
ceil=lambda x,y: (x+y-1)//y
input_list = lambda : list(map(int,input().split()))



#n=int(input())
n,m=list(map(int,input().split()))
a=list(map(int,input().split()))
a=set(a)
tmp=set(i for i in range(-5,103))
cal=tmp-a
cal=list(cal)
cal.sort()
ind=bisect.bisect_left(cal,n)
ans=cal[ind]
if ans-n >= n-cal[ind-1]:
    ans=cal[ind-1]
print(ans)

Submission status: Accepted

Solution code:
import sys

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

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

p = [int(x) for x in input().split()]

for i in range(101):
    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:
import sys
x,n = map(int,input().split())
ls = list(map(int,input().split()))
p = float("inf")
s = 0
if n == 0:
    print(x)
    sys.exit()
for i in range(102):
    if i in ls:
        continue
    k = abs(x-i)
    if k < p:
        p = k
        s = i
print(s)

Submission status: Accepted

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

def main():
    x, n = map(int, input().split())

    p = set(map(int, input().split()))
    diff = set(range(-1, 150)) - p

    a = [(abs(x - q), q) for q in diff]
    a.sort()
    print(a[0][1])


main()

Submission status: Accepted

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

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

cnt = [0] * 102

for i in range(n):
    cnt[p[i]] = 1

ans = 0
sa = x
for i in range(1, 102):
    if cnt[i] == 0:
        if sa > abs(x - i):
            ans = i
            sa = abs(x - i)
print(ans)

Submission status: Accepted

Solution code:
x,n=map(int, input().split()) 
p=list(map(int,input().split()))
s=100
t=0
c=0
if p==[]:
    print(x)
    c=1
if c==0:
    for i in range(-201,201):
        if not i in p:
            if abs(x-i)<s:
                # print(i,abs(x-i))
                s = abs(x-i)
                t=i
    print(t)

Submission status: Accepted

Solution code:
import sys
import math
import itertools
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
import bisect
X,N = I()
if N == 0:
    print(X)
    exit()
p = l()
A = [i for i in range(-1,102)]
for i in range(N):
    if p[i] in A:
        A.remove(p[i])
i = bisect.bisect_left(A,X)
if abs(A[i-1]-X) > abs(A[i]-X):
    print(A[i])
else:
    print(A[i-1])

Submission status: Accepted

Solution code:
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
# from scipy.sparse.csgraph import floyd_warshall
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations, combinations_with_replacement
from heapq import heappop, heappush, heapify
from fractions import gcd
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

def main():
    x,n = inpm()
    l = inpl()
    for i in range(200):
        if x-i not in l:
            print(x-i)
            return
        if x+i not in l:
            print(x+i)
            return
    
if __name__ == "__main__":
    main()

Submission status: Accepted

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

sa=1000
ans=0
for i in range(110):
    if i in P:
        continue
    else:
        if sa>abs(i-X):
            sa=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()))
    p=set(p)
    mini=10**10
    ans=0
    for i in range(102):
        if i not in p:
            if abs(i-x)<mini:
                mini=abs(i-x)
                ans=i
    print(ans)
else:
    print(x)

Submission status: Accepted

Solution code:
def main():
    X,N  = map(int, input().split()) 
    c=list(map(int, input().split()))
    XY = [True]*(104)

    for i in range(len(c)):
        XY[c[i]]=False

    ans = 0
    sa = 10000

    for i in range(-1,104):
        if i==-1 or XY[i]:
            if sa > abs(X-i) :
                ans = i
                sa = abs(X-i)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
x,y=map(int,input().split())
if y==0:print(x);exit()
l=list(map(int,input().split()))
work=x
if not work in l:
    print(work)
    exit()
i=1
while 1:
    if not work-i in l:
        print(work-i)
        exit()
    if not work+i in l:
        print(work+i)
        exit()
    i+=1

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
if n == 0:
    print(x)
    exit()
p = sorted([-999] + list(map(int, input().split())) + [999])

from bisect import bisect_left, bisect_right

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

# 小さい方
m = p.index(x) - 1
target_L = x - 1
while True:
    if target_L not in p:
        break
    target_L -= 1

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

if abs(target_L - x) <= abs(target_R - x):
    print(target_L)
else:
    print(target_R)

Submission status: Accepted

Solution code:
X,N = map(int,input().split())
if N>0:
    p = list(map(int,input().split()))
else:
    p = []
ans = []
for i in range(100):
    ans.append(X-i)
    ans.append(X+i)
import sys
for j in ans:
    if j not in p:
        print(j)
        sys.exit()

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
for i in range(n+1):
    c = 10**5
    t = 10**5
    y = 0
    if x + i not in p:
        c = x+i
        y += 1
    if x - i not in p:
        t = x-i
        y += 1
    if y:
        print(min(t,c))
        exit()

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
p=list(map(int,input().split()))
p=sorted(p)
c=0
z=0
a=[]
for i in range(n):
    a.append(p[i]-x)
for i in range(100):
    if a.count(-i)==0:
        z=-c
        break
    elif a.count(i)==0:
        z=c
        break
    else:
        c+=1
print(x+z)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(200000)


def read():
    X, N = map(int, input().strip().split())
    P = list(map(int, input().strip().split()))
    return X, N, P


def solve(X, N, P):
    if N == 0:
        return X
    k = 0
    v = 10**5
    for i in range(102, -102, -1):
        if i in P:
            continue
        if v >= abs(X - i):
            v = abs(X - i)
            k = i
    return k


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))

Submission status: Accepted

Solution code:
X,N=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=list(map(int,input().split()))
p=list(map(int,input().split()))
dist=1000
ans=1000
for i in range(0,150):
    low=X-i
    high=X+i
    if p.count(low)==0:
        print(low)
        exit()
    elif p.count(high)==0:
        print(high)
        exit()

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
a = list(map(int,input().split()))
if n == 0:
    print(x)
    exit()
ans = min(a)-1
for i in range(1,102):
    if i in a:
        continue
    if abs(x-i) < abs(x-ans):
        ans = i
print(ans)

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(0)
l = []
for i in range(102):
    if i not in P:
        l.append(i)
tmp = 1000
ans = 0
for i in range(len(l)):
    if tmp > abs(X-l[i]):
        tmp = abs(X-l[i])
        ans = l[i]

print(ans)

Submission status: Accepted

Solution code:
# ANSHUL GAUTAM
# IIIT-D

from math import *
from copy import *					# ll = deepcopy(l)
from heapq import *					# heappush(hp,x)
from string import *				# alpha = ascii_lowercase
from random import *				# l.sort(key=lambda l1:l1[0]-l1[1]) => ex: sort on the basis difference
from bisect import *				# bisect_left(arr,x,start,end)  => start and end parameters are temporary
from sys import stdin				# bisect_left return leftmost position where x should be inserted to keep sorted
from sys import maxsize				# minn = -maxsize
from operator import *				# d = sorted(d.items(), key=itemgetter(1))
from itertools import *				# pre = [0] + list(accumulate(l))
from decimal import Decimal 		# a = Decimal(a)	# use this for math questions
from collections import Counter		# d = dict(Counter(l))
from collections import defaultdict # d = defaultdict(list)

'''
6 5
4 7 10 6 5
'''

def solve(l,x,n):
	n = len(l)
	diff,ans = maxsize,0
	for i in range(102):
		if(i not in l and abs(i-x) < diff):
			diff = abs(i-x)
			ans = i
	return ans
	

X,N = map(int, input().split())
l = list(map(int, stdin.readline().rstrip().split()))
ans = solve(l,X,N)
print(ans)

Submission status: Accepted

Solution code:
def main():
    X, N = [int(s) for s in input().strip().split()]

    if N == 0:
        print(X)
        return
    
    ps = [int(s) for s in input().strip().split()]

    p_max = max(ps)
    p_min = min(ps)

    for d in range(100):
        cand = X - d

        if cand < p_min:
            print(cand)
            return
        
        if cand not in ps:
            print(cand)
            return

        cand = X + d

        if cand > p_max:
            print(cand)
            return

        if cand not in ps:
            print(cand)
            return

main()

Submission status: Accepted

Solution code:
#

import sys
input=sys.stdin.readline

def main():
    X,N=map(int,input().split())
    p=list(map(int,input().split()))
    ans=[]
    for i in range(max(X,100-X)):
        if not X+i in p:
            ans+=[X+i]
        if not X-i in p:
            ans+=[X-i]
        if len(ans)>0:
            break
    if len(ans)==0:
        print(0)
    else:
        print(min(ans))
    
if __name__=="__main__":
    main()

Submission status: Accepted

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

minX = X
maxX = X
for i in range(100):
    if cnt[minX] == 0:
        print(minX)
        exit()
    elif cnt[maxX] == 0:
        print(maxX)
        exit()
    else:
        minX -= 1
        maxX += 1

Submission status: Accepted

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

p_list_raw = input()
if p_list_raw == "":
    print(X)
else:
    p_list = [int(_c) for _c in p_list_raw.split(" ")]

    ans = -1
    for i in range(101):
        target = X - i
        if target not in p_list:
            ans = target
            break
        target = X + i
        if target not in p_list:
            ans = target
            break

    print(ans)

Submission status: Accepted

Solution code:
X,N=map(int,input().split())
P=list(map(int,input().split()))
setP=set(P)
ANS=[]
for i in range(102):
  if i not in setP:
    ANS+=[i]
d=100
for i in ANS:
  if abs(X-i)<d:
    ans=i
    d=abs(X-i)
print(ans)

Submission status: Accepted

Solution code:
li = input().split()
x = int(li[0])
n = int(li[1])
if n == 0:
    print(x)
else:
    li = list(map(int,input().split()))
    count = 0
    while True:
        if  x - count not in li:
            print(x-count)
            break
        elif x+count not in li:
            print(x+count)
            break 

        count+= 1

Submission status: Accepted

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

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

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

if not x in plist:
    print(x)
    sys.exit()

for i in range(1,102):
    if not x-i in plist:
        print(x-i)
        sys.exit()
    elif not x+i in plist:
        print(x+i)
        sys.exit()

Submission status: Accepted

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

# print(s)

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

Submission status: Accepted

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

ans = -1
for k in range(X, -1, -1):
    if not k in P:
        ans = k
        break
for k in range(X, 102):
    if not k in P:
        if X-ans <= k-X:
            break
        else:
            ans = k
            break
print(ans)

Submission status: Accepted

Solution code:
x,n,*l = map(int,open(0).read().split())

import sys
if not x in l:
    print(x)
    sys.exit()
for i in range(1, 100):
    if  not x -i in l:
        print(x -i)
        sys.exit()
    if  not x +i in l:
        print(x +i)
        sys.exit()

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
P = sorted(list(map(int, input().split())))
ans = -1
diff = 100000
for i in range(-10,110):
    if i in P: continue
    if diff > abs(i-X):
        diff = abs(i-X)
        ans = i
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
if n == 0:
    print(x)
else:
    p=set([int(i) for i in input().split()])
    for i in range(1000):
        if not(x-i in p):
            ans=x-i
            break
        elif not(x+i in p):
            ans=x+i
            break
    print(ans)

Submission status: Accepted

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

x, n = LI()
p = LI()

d = dict()
for i in range(n):
    d[p[i]] = 1

i = 0
while True:
    if d.get(x-i, 0) == 0:
        print(x-i)
        break
    elif d.get(x+i, 0) == 0:
        print(x+i)
        break
    i += 1

Submission status: Accepted

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

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

for s in range(-101, 110):
    if s not in P:
        ans = s
        break

for s in range(-101, 110):
    if s not in P:
        if abs(ans-x) > abs(s-x):
            ans = s
        elif abs(ans-x) == abs(s-x):
            ans = min(ans, s)

print(ans)

Submission status: Accepted

Solution code:
l = list (map (int, input().strip().split()))
x = l[0]
n = l[1]
if (n==0):
    print(x)
else:
    l2 = list (map (int, input().strip().split()))
    d = 0
    while True:
        if (x-d) not in l2:
            print(x-d)
            break 
        elif (x+d) not in l2:
            print(x+d)
            break
        d+=1

Submission status: Accepted

Solution code:
# FOrbidden List
def nearest(x, arr):
    if x not in arr:
        return x
    lower = x - 1
    higher = x + 1
    while True:
        if lower not in arr:
            return lower
        if higher not in arr:
            return higher
        lower -= 1
        higher += 1

        


x = list(map(int, input().rstrip().split()))
a = list(map(int, input().rstrip().split()))
print(nearest(x[0], a))

Submission status: Accepted

Solution code:
[X,N] = [int(s) for s in input().rstrip().split(' ')]
if N == 0:
    print(X)
else:
    L = [int(s) for s in input().rstrip().split(' ')]
    k = 0
    a = 0
    while a == 0:
        if X - k not in L:
            print(X-k)
            a = 1
            continue
        elif X + k not in L:
            print(X+k)
            a = 1
            continue
        k += 1

Submission status: Accepted

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

for i in range(110):
    if ((x-i) not in li):
        print(x-i)
        break
    if ((x+i) not in li):
        print(x+i)
        break

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
apple = list(map(int, input().split()))
for i in range(101):
    a = x-i
    b = x+i
    if a not in apple:
        print(a)
        break
    elif b not in apple:
        print(b)
        break
    else:
        pass

Submission status: Accepted

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

diff = 10**10
ans = -1
for p in range(102):
    #print(p)
    if p in P:
        continue
    if abs(X-p) < diff:
        diff = abs(X-p)
        ans = p
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()))

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(4100000)

import math

import logging

logging.basicConfig(level=logging.DEBUG)

logger = logging.getLogger(__name__)


def resolve():
    # S = [x for x in sys.stdin.readline().split()][0]  # 文字列 一つ
    # N = [int(x) for x in sys.stdin.readline().split()][0]  # int 一つ
    X, N = [int(x) for x in sys.stdin.readline().split()]  # 複数int
    if N == 0:
        print(X)
        return
    if N >= 1:
        p_list = [int(x) for x in sys.stdin.readline().split()]  # 複数int

    # grid = [list(sys.stdin.readline().split()[0]) for _ in range(N)]  # 文字列grid
    # v_list = [int(sys.stdin.readline().split()[0]) for _ in range(N)]
    # grid = [[int(x) for x in sys.stdin.readline().split()]
    #         for _ in range(N)]  # int grid

    logger.debug('{}'.format([p_list]))

    p_set = set(p_list)
    for i in range(100):
        for s in (-1, 1):
            r = X + i * s
            if r not in p_set:
                print(r)
                return


if __name__ == "__main__":
    resolve()

# AtCoder Unit Test で自動生成できる, 最後のunittest.main は消す
# python -m unittest template/template.py で実行できる
# pypy3 -m unittest template/template.py で実行できる

import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """6 5
4 7 10 6 5"""
        output = """8"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """10 5
4 7 10 6 5"""
        output = """9"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """100 0"""
        output = """100"""
        self.assertIO(input, output)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

    for xi in range(x,102):
        if not xi in p:
            break
        
    for xi2 in range(x,-1,-1):
        if not xi2 in p:
            break

    if xi-x<x-xi2:
        print(xi)
    else:
        print(xi2)

Submission status: Accepted

Solution code:
x,n=input().split()
x=int(x)
n=int(n)
p=list(map(int,input().split()))
if(n==0):
    print(x)
    exit()
i=0
while(True):
    x_r=x+i
    x_l=x-i

    if(x_l not in p):
        a=x_l
        break
    if(x_r not in p):
        a=x_r
        break

    i+=1


print(a)