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: Wrong Answer

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

if n != 0:
  p = list(map(int, input().split()))
  lists = []
  for i in range(1, 101):
    if i in p:
      continue
    lists.append(i)
  ans = 1
  dist = 10**9
  for l in lists:
    if dist > abs(l-x):
      ans = l
      dist = abs(l-x)
  print(ans)
  
else:
  print(x)

Submission status: Wrong Answer

Solution code:
X,N = map(int,input().split())
p_li = sorted(list(map(int,input().split())))
p = [0] * 100
for i in p_li:
    p[i-1] = 1
sa_min = 10**9+7
ans = 10**9+7
if p_li == list():
    print(X)
    exit()
for i in range(101):
    if p[i-1] == 0:
        sa = abs(i-X)
        if sa < sa_min:
            sa_min = sa
            ans = i
print(ans)

Submission status: Wrong Answer

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

P.sort()
ans = abs(X)
for i in range(1, 101):
  if not i in P:
    ans = min(ans, abs(i-X))

if not X-ans in P:
  print(X-ans)
else:
  print(X+ans)

Submission status: Wrong Answer

Solution code:
X,N=map(int,input().split())
if N==0:
  print(X)
  exit()
P=list(map(int,input().split()))  
for i in range(1,200):
  if (X-i) not in P:
    ans=X-i
    break
  if (X+i) not in P:
    ans=X+i
    break
print(ans)

Submission status: Wrong Answer

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

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

while True:
    min-=1
    max+=1
    if min not in p:
        ans=min
        break
    if max not in p:
        ans=max
        break
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log,gcd
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
'''
#Pythonを用いる場合
#numpy 1.18.0, scipy 1.4.1, scikit-learn 0.22, numba 0.47.0, networkx 2.4
 
import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix
'''
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

x,n=mii()
arr0=limii()

if len(arr0)==0:
    print(x)
    exit()

arr=[]
for i in range(-1,101):
    if i not in arr0:
        arr.append(i)
arr.sort()
ans=[10**100,10*100]

for i in reversed(arr):
    if abs(i-x)<=ans[1]:
        
        if i<ans[0]:
            ans[0]=i
            ans[1]=abs(i-x)
print(ans[0])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
if n==0:
  print(x)
else:
  a=list(map(int,input().split()))
  tmp=1000
  for i in reversed(range(-1,102)):
    if i not in a:
      if tmp > abs(i-x):
        tmp=abs(i-x)
        ans=i
  print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    sys.setrecursionlimit(10**9)
    input = sys.stdin.readline

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

    P = list(map(int, input().split()))
    check = 1
    while True:
        if not X-check in P:
            print(X-check)
            return
        if not X+check in P:
            print(X+check)
            return
        check += 1    

main()

Submission status: Wrong Answer

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

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

    ans = 0
    sa = 10000

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
p = list(input().split())
p = [int(p[i]) for i in range(N)]
ans = float('inf')
dif = float('inf')

for i in range(0, 101):
    if i not in p and abs(i - X) < dif:
        ans = i
        dif = abs(i-X)

print(ans)

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
lists = list(input().split())
for i in range(n):
  lists[i] = int(lists[i])
for i in range(n):
  lists[i] = lists[i] - x
loop = True
number = x
while True:
  if number in lists:
    number = number - 1
  else:
    break
number_2 = x
while True:
  if number in lists:
    number = number + 1
  else:
    break
if abs(number - x) > abs(number_2 - x):
  print(number_2)
else:
  print(number)

Submission status: Wrong Answer

Solution code:
X, Y = map(int,input().split())
plist = list(map(int,input().split()))

distance = 1
while True:
    if X -distance not in plist:
        print(X-distance)
        break
    if X + distance not in plist:
        print(X+distance)
        break
    distance += 1

Submission status: Wrong Answer

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

pinv=[True for i in range(101)]
pinv[0]=False
for i in p:
    pinv[i]=False

ab=100
ans=0
for i in range(101):
    if pinv[i] and abs(x-i)<ab:
        ab=abs(x-i)
        ans=i

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

c = float('inf')
ans = 0
for i in range(1, 101):
    if i not in p:
        if c > abs(x - i):
            c = abs(x - i)
            ans = i

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#import numpy as np
#import math

X, N = map(int, input().split())
if N != 0:
    P = list(map(int, input().split()))
    # a,b=map(int, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
    # c=list(map(int, input().split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき
    # s=[list(map(int,list(input()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき
    
    #K = int(input())
    #S = input()
    
    ##一次元配列の初期化
    #a=[0]*5
    #[i for i in range(100) if i%2==1] #奇数のみ
    ##二次元配列の初期化
    #[[float("inf") for i in range(N)] for i in range(N)]
    
    for diff in range(0,102):
        if X-diff not in P:
            print(X-diff)
            break
        elif X+diff not in P:
            print(X+diff)
            break
else:
    print(N)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
d = [0]*201
for i in p: d[i+100] = 1
if d[x+100] == 0:
    print(x)
else:
    i = 1
    while True:
        if x-i>=-100:
            if d[x-i+100] == 0:
                print(x-i)
                break
        if x+i<=100:
            if d[x+i+100] == 0:
                print(x+i)
                break
        i += 1

Submission status: Wrong Answer

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


def main():
    X, N = [int(i) for i in input().strip().split()]
    p_list = [int(i) for i in input().strip().split()]

    base = list()
    for i in range(1, 101):
        if i not in p_list:
            base.append(i)

    dif = float("inf")
    ans = None
    for j in base:
        if abs(j - X) < dif:
            dif = abs(j-X)
            ans = j

    return ans


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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

a = 0
for i in range(x-1, -1, -1):
  if i not in p:
    a = i
    exit()
b = 0
for i in range(x, 101):
  if i not in p:
    b = i
    break

if abs(x-a) <= abs(x-b):
  print(a)
else:
  print(b)

Submission status: Wrong Answer

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

sa = float("inf")
ans = 0
for i in range(100, 0, -1):
    if sa > abs(x - i) and (i not in p):
        ans = i
        sa = abs(x - i)
print(ans)

Submission status: Wrong Answer

Solution code:
nums = set(range(-100, 101))

X, N = map(int, input().split())
p = set(map(int, input().split()))
dist = 10**9
ans = 10**9

for k in sorted(nums - p):
    if abs(X - k) < dist:
        ans = k
        dist = abs(X - k)
print(ans)

Submission status: Wrong Answer

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

arr.sort()

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

ans = 1 << 60
cnt = 1
while True:
    lower = x - cnt
    upper = x + cnt
    if lower not in arr:
        ans = min(ans, lower)
    if upper not in arr:
        ans = min(ans, upper)
    if ans < 1 << 60:
        break
    cnt += 1

print(ans)

Submission status: Wrong Answer

Solution code:
#import sys
#input = sys.stdin.readline
def main():
    X, N = map( int, input().split())
    if N == 0:
        print(X)
        return
    Q = list( map( int, input().split()))
    # P.sort()
    Z = [True]*102
    for q in Q:
        Z[q] = False
    Z[0] = False
    P = []
    for i in range(1,102):
        if Z[i]:
            P.append(i)
    # print(P)
    now = P[0]
    ab = abs(X-P[0])
    for p in P:
        pab = abs(X-p)
        if pab == ab:
            if p < now:
                now = p
        elif pab < ab:
            now = p
            ab = pab
    print(now)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def resolve():
    x, n = map(int, input().split())
    if n ==0:
        print(x)
    else:
        p = list(map(int, input().split()))
        ans = 0
        diff = 10**5
        for i in range(-100, 100):
            if i in p:
                continue
            else:
                if diff > abs(x-i):
                    ans = i
                    diff = abs(x-i)
        print(ans)

resolve()

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
a = [i for i in range(1, 101)]
if N != 0:
    p = list(map(int, input().split()))
    for P in p:
        a.remove(P)

ans = -1
d = 10000
for A in a:
    if d > abs(A-X):
        ans = A
        d = abs(A-X)


print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    x, n = map(int, input().split())
    p = list(map(int, input().split()))
    arr = []
    for i in range(1, 101):
        if not i in p:
            arr.append(i)
    ans = -1
    for ai in arr:
        if abs(ai - x) < abs(ans - x):
            ans = ai
    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

chk=[0 for _ in range(101)]

for i in range(N):
    p=P[i]
    chk[p]=1
ans=10**7
res=-1
for x in range(-1,101):
    if x==-1:
        val=abs(X-x)
    else:
        if chk[x]==1:
            continue
        val=abs(X-x)
    if val<ans:
        ans=val
        res=x

print(res)

Submission status: Wrong Answer

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

li = [0]*(100+1)
for i in range(n):
    li[pi[i]] = 1
    
#print(li)

dif = 10**10
ans = -1
    
for i in range(101):
    if li[i] == 0:
        if dif > abs(x-i):
            dif = abs(x-i)
            ans = i
            
print(ans)

Submission status: Wrong Answer

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

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

res = -1
sa = 1000000
for i in range(1,101):
    if i not in p:
        if abs(i-X) < sa:
            res = i
            sa = abs(i-X)

print(res)

Submission status: Wrong Answer

Solution code:
X,N = map(int,input().split())
p_li = sorted(list(map(int,input().split())))
p = [0] * 100
for i in p_li:
    p[i-1] = 1
sa_min = 10**9+7
ans = 10**9+7
if p_li == list():
    print(X)
    exit()
for i in range(100):
    if p[i-1] == 0:
        sa = abs(i-X)
        if sa < sa_min:
            sa_min = sa
            ans = i
print(ans)

Submission status: Wrong Answer

Solution code:

X,N = map(int,input().split())
def seek(X):
    r=map(int,input().split())
    s= set()
    
    for it in r:
        s.add(it)
    for d in range(0,N):
        if not X-d in s:
            print(X-d)
            break
        if not X+d in s:
            print(X+d)
            break
if(N>0):
    seek(X)
else:
    print(X)

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
pn = list(map(int, input().split()))
diff = 100
ans = X
if pn:
    for i in range(min(pn)+1, max(pn)):
        if i in pn:
            continue
        if abs(X-i) < diff:
            ans = i
print(ans)

Submission status: Wrong Answer

Solution code:
x,y=map(int,input().split())
s=list(map(int,input().split()))
res=101
mn=101
for n in range(1,110):
    if n not in s:
        v=abs(x-n)
        if v<res:
            res=v
            mn=n

print(mn)

Submission status: Wrong Answer

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

ab = 100
num = 0
for i in range(101):
    if p.count(i):
        continue
    if abs(i-x) < ab:
        ab = abs(i-x)
        num = i
print(num)

Submission status: Wrong Answer

Solution code:
import sys

X, N = map(int, input().split())
P = list(map(int, sys.stdin.readline().rsplit()))

m = 1000
for i in range(101):
    if i in P:
        continue
    if abs(X - i) < m:
        m = abs(X - i)
        res = i
    else:
        break

print(res)

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
p = list(map(int,input().split()))
if(n == 0):
    print(x)
else:
    t = [0]*102
    q = 0
    for i in range(n):
        t[p[i]] += 1
    if(t[x] == 0):
        q = x
    i = 1
    while(q == 0):
        if(t[x-i] == 0):
            q = x-i
        elif(t[x+i] == 0):
            q = x+i
        i += 1
    print(q)

Submission status: Wrong Answer

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

diff= 1000
ans = 0
for i in range(101):
  if i in P: continue
  if abs(x-i)<diff:
    diff = abs(x-i)
    #print(diff,i)
    ans = i
print(ans)

Submission status: Wrong Answer

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

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

print(X)

Submission status: Wrong Answer

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

for i in range(100):
  pl = x+i
  mn = x-i
  if x-i>=0 and x-i not in p:
    print(x-i)
    break
  if x+i<=100 and x+i not in p:
    print(x+i)
    break

Submission status: Wrong Answer

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(-100,102))
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: Wrong Answer

Solution code:
X, N = map(int, input().split())
P = set(map(int, input().split()))
U = set(range(1, 101))
diff = list(U - P)

ans = 0
tmp = float('inf')
for i in diff:
    if tmp > abs(X - i):
        tmp = abs(X - i)
        ans = i
print(ans)

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
a = [i+1 for i in range(100)]
ans = 0
if x > 101 - x:
    ans = 101
else:
    ans = 0
for i in range(1,101):
    if i in a:
        continue
    if abs(x-i) < abs(x-ans):
        ans = i
print(ans)

Submission status: Wrong Answer

Solution code:

INF = float("inf")
MOD = 10 ** 9 + 7
# ----------

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

S = set([i for i in range(1, 101)])
S = S - P

ans = -1
diff = INF
for s in S:
    if abs(s - X) < diff:
        ans = s
        diff = abs(s - X)
    elif abs(s - X) == diff:
        ans = min(s, ans)
        diff = abs(s - X)

print(ans)

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
if n != 0:
    P = list(map(int,input().split()))
else:
    P = []
tmp = 999
ans = 0
for i in range(-1,101):
    if tmp > abs(x-i):
        if not i in P:
            tmp = abs(x-i)
            ans = i
print(ans)

Submission status: Wrong Answer

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

if N == 0:
  print(X)
else:
  ps = set(list(map(int, input().split())))

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

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
P = list(map(int, input().split()))
P.sort()
INF = 10**18
ans = INF
for i in range(-100, 101):
    if i not in P:
        if ans > abs(x-i):
            ans = abs(x-i)
            cnt = i
print(cnt)

Submission status: Wrong Answer

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

check = [0 for i in range(100)]
for i in range(N):
    check[P[i]-1] = 1
    
dx = 1000
ans = -1
for i in range(100):
    if check[i] == 0:
        if abs(X-(i+1)) < dx:
            dx = abs(X-(i+1))
            ans = i + 1
            
print(ans)

Submission status: Wrong Answer

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

pinv=[True for i in range(101)]
pinv[0]=True
for i in p:
    pinv[i]=False

ab=100
ans=0
for i in range(101):
    if pinv[i] and abs(x-i)<ab:
        ab=abs(x-i)
        ans=i

print(ans)

Submission status: Wrong Answer

Solution code:
nums = set(range(101))

X, N = map(int, input().split())
p = set(map(int, input().split()))
dist = 10**9
ans = 10**9

for k in sorted(nums - p):
    if abs(X - k) < dist:
        ans = k
        dist = abs(X - k)
print(ans)

Submission status: Wrong Answer

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

ans = 100
abs_ans = 100
for i in range(101):
    if i in P:
        continue
    if abs(x-i) < abs_ans:
        ans = i
        abs_ans = abs(x-i)
print(ans)

Submission status: Wrong Answer

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

a = [i for i in range(1, 1000)]
b = [i for i in range(1, 1000)]
c = []
for idx in range(len(a)):
    c.append(a[idx])
    c.append(b[idx])

tmp = []
for i in c:
    if not i in p:
        tmp.append([abs(X-i), i])
tmp2 = [10000000000, -1]
for i in tmp:
    if tmp2[0] > i[0]:
        tmp2[0] = i[0]
        tmp2[1] = i[1]

print(tmp2[1])

Submission status: Wrong Answer

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(-100,101)) - p

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


main()

Submission status: Wrong Answer

Solution code:
"""    Arnab Chanda    """

from collections import defaultdict, deque
from itertools import permutations
from sys import stdin,stdout
from bisect import bisect_left, bisect_right
from copy import deepcopy
import heapq

int_input=lambda : int(stdin.readline())
string_input=lambda : stdin.readline().split()
multi_int_input =lambda : map(int, stdin.readline().split())
multi_input = lambda : stdin.readline().split()
list_input=lambda : list(map(int,stdin.readline().split()))
string_list_input=lambda: list(string_input())
MOD = pow(10,9)+7


x, n = multi_int_input()

arr = list_input()

arr = set(arr)

a = 0

while(True):
    l = x+a
    r = x - a

    if (l not in arr):
        print(l)
        break
    elif (r not in arr):
        print(r)
        break

    a+=1

Submission status: Wrong Answer

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


def myfunc(X, Y):
    for tsuru in range(X+1):
        turtle = X - tsuru
        legs = turtle * 4 + tsuru * 2

        if legs == Y:
            return "Yes"

    return "No"

print(myfunc(X,Y))

Submission status: Wrong Answer

Solution code:
def main():
    x,n = tuple([int(t)for t in input().split()])

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

    nums = set(range(1,101))
    nums.add(-1)
    nums.add(101)

    for p_i in p:
        nums.discard(p_i)

    dist = 10**8
    ans = -1
    for i in nums:
        if dist>abs(x-i):
            dist = abs(x-i)
            ans = i

    print(ans)
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

def ans(P, X):
    P = set(P)
    for i in range(200):
        if X + i not in P:
            return X+i
        if X - i not in P:
            return X-i 

X, N = input().split(' ')
X = int(X)
N = int(N)
if N == 0:
    print(X)
else:
    P = input().split(' ')
    P = [int(x) for x in P]

    print(ans(P, X))

Submission status: Wrong Answer

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

ls = sorted(ls)
d = 10**3
ans = 0
for p in ls:
  if abs(x-p)<d:
    d = abs(x-p)
    ans = p
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import collections
import itertools as it
import math
#import numpy as np
 
#  = input()
#  = int(input())
x, n  = map(int, input().split())
p  = list(map(int, input().split()))
#  = [int(input()) for i in range(N)]
#
# c = collections.Counter()

li = []
for i in range(1, 101):
    if not i in p:
        li.append(i)

ans = 1000
min_ = 1000
for i, l in enumerate(li):
    if min_ > abs(x - l):
        min_ = abs(x - l)
        ans = l

print(ans)

Submission status: Wrong Answer

Solution code:
def LI():return list(map(int,input().split()))
def MI():return map(int,open(0).read().split())
def I():return int(input())
def yes():print("Yes")
def no():print("No")

from collections import deque, Counter
from heapq import heappop, heappush
INF=float("inf")
# import math
# pi=math.pi

# import numpy as np
x,n=LI()
if n==0:
    print(x)
    exit()
p=LI()
p.sort()

# print(p)

ans=-1
tmp=INF
for i in range(1,100+1):
    if i in p:continue
    k=abs(i-x)
    if k<tmp:
        tmp=k
        ans=i
    # print(i,k,ans)
print(ans)

Submission status: Wrong Answer

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

import sys
from collections import defaultdict, deque
from heapq import heappush, heappop
import math
import bisect
input = sys.stdin.readline

# 再起回数上限変更
# sys.setrecursionlimit(1000000)

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

all = list(range(101))
val = 10000000000
# print(list(set(all) - set(p)))

for a in list(set(all) - set(p)):
    if abs(a - x) < val:
        ans = a
        val = abs(a - x)
        # print(val)
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
X, N = map(int, input().split())
if N == 0:
    print(X)
    exit()
P = list(map(int, input().split()))
P.sort()
ans = 10 ** 9
d = [True for _ in range(0, 101)]
for i in range(N):
    d[P[i]] = False
for i in range(len(d)):
    if d[i] and abs(ans - X) > abs(i - X):
        ans = i
if abs(-1 - X) < abs(ans - X):
    ans = -1
print(ans)

Submission status: Wrong Answer

Solution code:
X,N = map(int,input().split())
if N==0:
    print(X)
    exit()
P = [int(i) for i in input().split()]

ans = X+10
tmp = X**2
P2 = [int(i) for i in range(min(P),max(P)+1)]
P3 = list(set(P2)-set(P))

for i in P3:
    if ans > abs(X-i) :
        ans = abs(X-i)
        tmp=i
print(tmp)

Submission status: Wrong Answer

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

ans = 0
mini = 1000
for i in range(-100, 101):
    if not i in p:
        if abs(X - i) < mini:
            mini = abs(X - i)
            ans = i
print(ans)

Submission status: Wrong Answer

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

sa=1000
ans=0
for i in range(-2,101):
    if i in P:
        continue
    else:
        if sa>abs(i-X):
            sa=abs(i-X)
            ans=i

print(ans)

Submission status: Wrong Answer

Solution code:
from math import *
x,n=map(int,input().split())
p=[]
if n>0:
	p=[int(i) for i in input().split()]
mn=float('inf')
ans=-1
for i in range(-1,101):
	if not i in p:
		if abs(x-i) < mn:
			ans=i
			mn=abs(x-i)
print(ans)

Submission status: Wrong Answer

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

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

_,res = min((abs(X-y),y) for y in range(-1,101) if y not in P)
print(res)

Submission status: Wrong Answer

Solution code:
"""    Arnab Chanda    """

from collections import defaultdict, deque
from itertools import permutations
from sys import stdin,stdout
from bisect import bisect_left, bisect_right
from copy import deepcopy
import heapq

int_input=lambda : int(stdin.readline())
string_input=lambda : stdin.readline().split()
multi_int_input =lambda : map(int, stdin.readline().split())
multi_input = lambda : stdin.readline().split()
list_input=lambda : list(map(int,stdin.readline().split()))
string_list_input=lambda: list(string_input())
MOD = pow(10,9)+7


x, n = multi_int_input()

arr = list_input()

arr = set(arr)

a = 1

while(True):
    l = x+a
    r = x - a

    if (l not in arr):
        print(l)
        break
    elif (r not in arr):
        print(r)
        break

Submission status: Wrong Answer

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

if len(arr)==0:
  print(target[0])
else:
  i=0
  while(1):
    if target[0]-i in arr:
      i+=1
    else:
      print(target[0]-i)
      break

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
ans = None
dif = 10**10

for i in range(-100, 101):
    if i in p:
        continue
    if abs(i - x) < dif:
        dif = abs(i - x)
        ans = i

print(ans)

Submission status: Wrong Answer

Solution code:
X,N = map(int,input().split())
P = set(map(int,input().split()))
ans = 1001
diff = 1000
for i in range(101):
    if i in P:
        continue
    if abs(X-i) < diff:
        ans = i
        diff = abs(X-i)
print(ans)

Submission status: Wrong Answer

Solution code:
# itne me hi thakk gaye?
x, n = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort()
if x in arr:
    # print('hereh')
    ans = -1
    diff = 10**9
    for i in range(arr[0]-1, arr[-1] + 1):
        if abs(i - x) < diff and (i not in arr):
            diff = abs(i-x)
            ans = i
    print(ans)
else :
    print(x)

Submission status: Wrong Answer

Solution code:
INF = float("inf")
MOD = 10 ** 9 + 7
# ----------

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

S = set([i for i in range(1, 101)])
S = S - P

ans = -1
diff = INF
for s in S:
    if abs(s - X) < diff:
        ans = s
        diff = abs(s - X)

print(ans)

Submission status: Wrong Answer

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

if N == 0:
    print(X)

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

for i in range(100):
    if X - i not in p_array:
        print(X - i)
        exit()
    if X + i not in p_array:
        print(X + i)
        exit()