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 = map(int, input().split())
if N ==0:
  print(X)
else:
  List = list(map(int, input().split()))
  res = 0
  Flag =False
  for i in range(N):
    if List[i] == X:
      Flag == True
  if Flag:
    res = X
    print(res)
  else:
    for i in range(1,103):
      med_p = X+i
      med_n = X-i
      Flag_p = False
      Flag_n = False
      for j in range(N):
        if List[j] == med_p:
          Flag_p = True
        elif List[j] == med_n:
          Flag_n = True
        else:
          pass
      if Flag_p and Flag_n:
        pass
      elif not Flag_p and Flag_n:
        res = med_p
        break
      elif Flag_p and not Flag_n:
        res = med_n
        break
      else:
        res = med_n
        break
    print(res)

Submission status: Wrong Answer

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

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

min_diff_val = X + 100
min_val = -100
for y in range(-100, 101):
    if not (y in p):
        if min_diff_val > abs(y - X):
            min_val = y
            min_diff_val = abs(y - X)
print(min_val)

Submission status: Wrong Answer

Solution code:
A1 = [int(x) for x in input().split()]
p = [int(x) for x in input().split()]

X = A1[0]
N = A1[1]
diff = 100

for i in range(N):
  diff0 = abs(p[i]-X)
  if diff0 < diff:
    diff = diff0
print(diff)

Submission status: Wrong Answer

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

# 0~100
data_list = [1 for i in range(V_RANGE)]

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

# 候補外を0にする
for i in range(len(in_value)):
	data_list[in_value[i]] = 0

min_abs = 10**4
ans_i = V_RANGE
for i in range(V_RANGE):
	# 候補の値
	if(data_list[i] == 1):
		# 絶対値を求める
		t_abs = abs(X - i)
		# 絶対値が小さい場合は更新
		if(min_abs > t_abs):
			min_abs = t_abs
			ans_i = i

print(ans_i)

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
if n != 0:
    p = set(map(int, input().split()))
    nums = []
    for i in range(0, 101):
        nums.append(i)
    nums_set = set(nums)
    rest = nums_set.difference(p)
    minVal = 101
    for j in rest:
        if abs(minVal-x) > abs(x - j):
            minVal = j
        else:
            pass
    print(minVal)
else:
    print(x)

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
if(n==0):
  print(x)
else:
  l=list(map(int,input().split()))
  d=100
  m=x
  for i in range(1,101):
      if(i not in l and (abs(i-x)<d)):
          d=abs(x-i)
          m=i
  print(m)

Submission status: Wrong Answer

Solution code:
x,n = map(int, input().split())
valid = [1] *101
p = list(map(int, input().split()))
for i in range(n):
	valid[p[i]] = 0

for j in range(x):
#	print(x,j,x-j,x+j)
	if((x-j) >= 1):
		if(valid[x-j] == 1):
			print(x-j)
			break
	elif((x+j) <= 100):
		if(valid[x+j] == 1):
			print(x+j)
			break

Submission status: Wrong Answer

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

ans = 300
for i in range(1, 101):
    if i not in list:
        if abs(x-i) < abs(x-ans):
            ans = i

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
x,n=map(int,input().split())
if n==0:
  print(x)
  sys.exit()
p=list(map(int,input().split()))
jud=[0 for i in range(101)]
for i in p:
  jud[i]=1
if jud[x]==0:
  print(x)
  sys.exit()
diff=1
while 1:
  if x >= diff and jud[x-diff]==0:
    print(x-diff)
    break
  if x + diff < 101 and jud[x+diff]==0:
    print(x+diff)
    break
  diff+=1

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
from collections import deque
def main():
    X, N =  map(int, input().split())
    p = list(map(int, input().split()))
    if N > 0:
        P = deque(sorted(p))
        L = P.popleft()
    else:
        print(X)
        return
    diff = 101
    ans = 101

    for i in range(-100,101):
        if i == L:
            if len(P) > 0:
                L = P.popleft()
            else:
                L = 101
        else:
            diff = abs(X-i)
        if diff < ans:
            ans = min(diff, ans)
    if X-ans in p:
        print(X+ans)
    else:
        print(X-ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

x, n = map(int, input().split())
p = list(map(int, input().split()))
flag = [False]*100
for i in p:
    flag[i-1] = True
for j in range(0, n+1):
    l = max(0, x-1-j)
    r = min(99, x-1+j)
    if not flag[l]:
        print(l+1)
        sys.exit()
    if not flag[r]:
        print(r+1)
        sys.exit()

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
P = set(map(int,input().split()))
Z = {_ for _ in range(-1,101)}
Z = Z-P
d = 101
ans = 101
for s in Z:
    y = abs(x-s)
    if y<d:
        d = y
        ans = s
print(ans)

Submission status: Wrong Answer

Solution code:
X,N=map(int,input().split())
P=list(map(int,input().split()))
def b():
    if(N==0):
        return X
    for n in range(1,N+3):
        a=X-n
        if(a not in P):
            return a
        a=X+n
        if(X+n not in P):
            return a
print(b())

Submission status: Wrong Answer

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

if N == 0:
  print(X)
  exit()
  
p = list(map(int, input().split()))
r = 0
l = 0

for i in range(X + 1, 100 + 1):
  if not i in p:
    l = i
    break
    
for i in range(X - 1, -1, -1):
  if not i in p:
    r = i
    break

dl = abs(X - l)
dr = abs(X - r)

if dr <= dl:
  print(r)
else:
  print(l)

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

kouho = list(range(1, 100 ** 2))
# print(kouho)

for i in range(len(p)):
  if p[i] != x:
    del kouho[kouho.index(p[i])]

kouho_num = kouho.index(x)
right = kouho_num + 1
left = kouho_num - 1


if abs(kouho[right] - kouho[kouho_num]) > abs(kouho[kouho_num] - kouho[left]):
  print(kouho[left])
elif abs(kouho[right] - kouho[kouho_num]) == abs(kouho[kouho_num] - kouho[left]):
  print(kouho[left])
else:
  print(kouho[right])

Submission status: Wrong Answer

Solution code:
import sys


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

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

    for i in range(101):
        x1 = max(0, x - (i + 1))
        x2 = min(101, x + (i + 1))

        print(x1, x2)
        if x1 == 0:
            print(0)
            sys.exit()
            
        if not (x1 in P):
            print(x1)
            sys.exit()

        if x2 == 101:
            print(101)
            sys.exit()
            
        if not (x2 in P):
            print(x2)
            sys.exit()


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
if n != 0:
    p = list(map(int, input().split()))
    mini = 10 ** 5
    for i in range(-100, 100):
        if i in p:
            pass
        else:
            if abs(x - mini) > abs(x - i):
                mini = i
            elif abs(x - mini) == abs(x - i):
                mini = min(mini, i)
    else:
        print(mini)
else:
    print(x)

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
p_lst = list(map(int, input().split()))
o_lst = list(range(0,102))
lst = list(set(p_lst) ^ set(o_lst))

if X in lst:
    print(X)
else:
    for i in range(len(lst)):
        if X - i in lst:
            print(X-i)
            break
        if X + i in lst:
            print(X+i)
            break

Submission status: Wrong Answer

Solution code:
X,N=map(int,input().split())
hazusu=list(map(int,input().split()))
kouho=100
ans=0
for i in reversed(range(101)):
    if i in hazusu:
        continue
    d=abs(X-i)
    if d<=kouho:
        kouho=d
        ans=i
print(ans)

Submission status: Wrong Answer

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

import math

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

if N==0:
    p = []
else:
    p = list(map(int, input().split()))

p = sorted(p)

if X not in p:
    print(X)
else:
    ind = p.index(X)
    pre = p[:ind]
    pre = pre[::-1]
    pre += [100] * 100
    ans_p = math.inf
    for i, pp in enumerate(pre, start=1):
        if X!=(pp+i):
            ans_p = X-i
            break

    aft = p[ind+1:]
    aft += [-1] * 100
    ans_a = math.inf
    for i, pp in enumerate(aft, start=1):
        if X!=(pp-i):
            ans_a = X+i
            break

    print(min(ans_a, ans_p))

Submission status: Wrong Answer

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

if(N == 0): 
  print(X)
else:
  j = 0
  #min=X-(-1)
  min = abs(X+1)
  ans = -1
  for i in range(1,101):
    if(i != s[j]):
      if(abs(X-i) < min):
        min = abs(X-i)
        ans = i
    else:
      j += 1
    if(j >= len(s)):break
  if(abs(X-101)<min):
    ans = 101
  print(ans)

Submission status: Wrong Answer

Solution code:
import collections
import sys
x,n=map(int,input().split())
p=list(map(int,input().split()))
p=list(map(lambda i:abs(x-i),p))
c=collections.Counter(p)
p.sort()

for i in range(len(p)):
  if p[i]!=(i+1)//2:
    if p[i-1]==p[i-2]:
      if x-p[i-1]-1 in p:
        print(x-p[i-1]+1)
      else:
        print(x-p[i-1]-1)
      sys.exit()
    elif i==1:
      if x-1 in p:
        print(x+1)
      else:
        print(x-1)
      sys.exit()
    elif i==0:
      print(x)
      sys.exit()
    else:
      if x-p[i] in p:
        print(x+p[i])
      else:
        print(x-p[i])
      sys.exit()
print(x)

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
import sys
if n==0:
    _=input()
    print(x)
    sys.exit()
    
p_list=list(map(int,input().split()))
r=list(range(100))
a=list(set(r)-set(p_list))
 
ans=100000
kkk=100000
for i in a:
    tem=abs(i-x)
    if ans>tem:
        ans=tem
        kkk=i
    
print(kkk)

Submission status: Wrong Answer

Solution code:
def resolve():
    x,n = map(int, input().split())
    if n == 0:
        print(x)
        return

    p = list(map(int, input().split()))
    p.sort()
    i = 0  # (p < X) p[i] (X < p)
    s_i = 0
    l_i = n
    while i < n:
        if p[i] >= x: break
        else: i += 1

    s_i = i-1
    l_i = i+1 if p[i] == x else i

    ans = 0
    diff = 1
    while True:
        if s_i < 0 or p[s_i] < x-diff:
            ans = x-diff
            break
        elif l_i >= n or p[l_i] > x+diff:
            ans = x+diff
            break
        else:
            s_i -= 1
            l_i += 1
            diff += 1

    print(ans)

resolve()

Submission status: Wrong Answer

Solution code:
X, N = map(int,input().split())
if 1 < N:
    P = list(map(int,input().split()))
    count1 = int()
    count2 = int()
    ans1 = 101
    ans2 = 101
    i = 0
    while 100 < ans1 and 100 < ans2:
        i += 1
        count1 = X-i
        count2 = X+i
        if P.count(count1) == 0:
            ans1 = count1
        if P.count(count2) == 0:
            ans2 = count2
    if ans1 < ans2:
        print(ans1)
    else:
        print(ans2) 
else:
    print(X)

Submission status: Wrong Answer

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

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

for i in range(x+1):
    if i+x not in PS and x-i not in PS:
        print(min(i+x, x-i))
        break
    elif i+x not in PS:
        print(i+x)
        break
    elif i+x not in PS:
        print(x-i)
        break

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
if n!=0:
    y=100
    p=list(map(int,input().split()))
    for i in range(max(p)+1):
        if i not in p:
            if abs(x-i)<y:
                ans=i
                y=abs(x-i)
    print(ans)
            
    
    
    
    
else:
    print(x)

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
len=float("inf")
ans=[[float("inf")] for i in range(101)]
for i in range(100+1):
    if i in p:
        continue
    else:
        if i<=x and len>=x-i:
            if len==x-i:
                ans[len].append(i)
            else:
                len=x-i
                ans[len].append(i)
        elif i>=x and len>=i-x:
            if len == i-x:
                ans[len].append(i)
            else:
                len=i-x
                ans[len].append(i)
ans[len].sort()
print(ans[len][0])

Submission status: Wrong Answer

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

d=150
pa = 0
px =range(1,101,1)
py = list(set(px) - set(p))

for i in py:

    if d> abs(i-x):
        pa = i
        d = abs(i-x)
    elif d == abs(i-x):
        if i < pa:
            pa =i

print(pa)

Submission status: Wrong Answer

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

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

    p_set = set(p_list)
    new_list = []
    for i in range(1, 101):
        if i in p_set:
            pass
        else:
            new_list.append(i)

#    print(new_list)

    min_x = 100 #絶対値の最小
    min_diff = 100
    for x in new_list:
        if abs(x - X) <= min_diff:
            if min_diff == abs(x - X):
                pass
            else:
                min_x = x
                min_diff = abs(x - X)
            
        else:
            pass
    print(min_x)

Submission status: Wrong Answer

Solution code:
X ,N = map(int,input().split())
P = list(map(int,input().split()))
if N == 0:
    print(X)
    exit(0)
A = list(range(0,101))
ans = 0
mins = 100


for a in A:
    if a not in P:
        if abs(a-X) < mins:
            mins = abs(a-X)
            ans = a
print(ans)

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
fb = [0] * 100
sa = float("inf")
for i in range(1, 100 + 1):
    if i not in p:
        fb[i - 1] += i
for i in fb:
    sa = min(sa, abs(i - x))
if sa + x not in p and x - sa not in p:
    print(min(sa + x, x - sa))
elif sa + x in p:
    print(x - sa)
else:
    print(x + sa)

Submission status: Wrong Answer

Solution code:
abs, N = map(int,input().split())
if N:
    s = list(map(int,input().split()))
    flag = 1
else:
    flag = 0
cnt = 0
while flag:
    if not(abs - cnt) in s and (abs - cnt) > 0:
        result = abs - cnt
        break
    if not(abs + cnt) in s:
        result = abs + cnt
        break
    cnt += 1
if flag:
    print(result)
else:
    print(abs)

Submission status: Wrong Answer

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

ans = 0
msf = 1000
for i in range(100,-101,-1):
    if i not in lis:
        diff = abs(i-x)
        if(min(diff,msf)==diff):
            msf = diff
            ans = i
print(ans) if(n!=0) else print(x)

Submission status: Wrong Answer

Solution code:
# coding=UTF-8
from collections import deque
from operator import itemgetter
from bisect import bisect_left, bisect
import itertools
import sys
import math
import numpy as np
import time
sys.setrecursionlimit(10**6)
input = sys.stdin.readline


def main():
    x, n = map(int, input().split())
    p = list(map(int, input().split()))
    if n == 0 or x not in p:
        print(x)
    else:
        for i in range(n):
            num1 = x-i
            num2 = x+i
            if num1 not in p and num2 not in p:
                print(min(num1, num2))
                break
            elif num1 not in p:
                print(num1)
                break
            elif num2 not in p:
                print(num2)
                break


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
X,N=map(int,input().split())
p=list(map(int,input().split()))
if N==0:
  print(X)
else:
  for i in range(0,N):
    if abs(X-i) not in p or abs(X+i) not in p:
      print(max([abs(X-i),abs(X+i)]))
      break

Submission status: Wrong Answer

Solution code:
X,N = map(int, input().split())
if N == 0:
    print(X)
elif N == 100:
    print(0)
else:
    p = list(map(int,input().split()))
    K = X
    L = 0
    for i in range(X,101):
        if i in p:
            continue
        else:
            K = i-X
            L = i
            break
    if i == X:
        print(X)
    else:
        for i in range(X-K,X):
            if i in p:
             continue
            else:
             L = i
        print(L)

Submission status: Wrong Answer

Solution code:
import os

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

n_list = []
for i in range(-101,101):
    n_list.append(i)
p.sort()

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

mini = 0
min = 1000
for b in n_list:
    if min>abs(x-b):
        if b not in p:
            min = abs(x-b)
            mini = b

print(mini)

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
l = [i for i in range(-100, 101)]
z = list(set(p)^set(l))
y = []
for i in z:
    y.append(abs(x-i))
z2 = sorted(y)
ans1 = x-z2[0]
ans2 = x+z2[0]
m = min(ans1, ans2)
M = max(ans1, ans2)
if m in z:
    print(m)
else:
    print(M)

Submission status: Wrong Answer

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

    check = [True]*101

    for i in p:
        check[i] = False

    mini = 100000
    index = 1

    for i in range(0,101):
        if check[i]:
            if mini > abs(x-i):
                #print(mini, abs(x-i), i)
                mini = abs(x-i)
                index = i

    #マイナス
    for i in range(1,101):
        if mini > abs(x+i):
            #print(mini, abs(x+i), -i)
            mini = abs(x+i)
            index = -i

    print(index)

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
if n == 0:
  print(x)
  exit()
else:
  ps = list(map(int, input().split()))
counters = [0 for _ in range(len(ps))]
counters[0] = 1

for i,p in enumerate(ps):
  distance = abs(x - p)
  if distance < len(ps):
    counters[distance] += 1

print(counters)
for i,counter in enumerate(counters):
  if counter == 0:
    print(x-i)
    break
  elif counter == 1:
    if x-i in ps:
      print(x+i)
    else:
      print(x-i)
    break

Submission status: Wrong Answer

Solution code:
import sys

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

if n == 0:
    print(x)
    sys.exit()
elif not(x in p_list):
    print(x)
    sys.exit()
elif len(p_list) == 100 and x < 50:
    print(0)
    sys.exit()
elif len(p_list) == 100 and x >= 50:
    print(101)
    sys.exit()

list.sort(p_list, reverse=True)
dis_list = list(range(102))
for p in p_list:
    dis_list.pop(p)

min_dis = 102
ans = 0
for index in dis_list:
    dis = abs(index - x)
    if dis < min_dis:
        min_dis = dis
        ans = index
print(ans)

Submission status: Wrong Answer

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

	diff_1 = abs(X-p[-1])
	diff_2 = abs(X-p[0])
	diff = max(diff_1,diff_2)

	for x in range(1,diff+1):
		if X-x not in p:
			print(X-x)
			break
		if X+x not in p:
			print(X+x)
			break

Submission status: Wrong Answer

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

a = X
i = 0
for i in range(X):
    if P.count(a) == 0:
        print(a)
        break
    else:
        i += 1
        a = a - i
        if P.count(a) == 0:
            print(a)
            break
        else:
            i += 1
            a = a + i
            if P.count(a) == 0:
                print(a)
                break

Submission status: Wrong Answer

Solution code:
from math import *
from copy import *
from string import *				# alpha = ascii_lowercase
from random import *
from sys import stdin,stdout
from sys import maxsize
from operator import *				# d = sorted(d.items(), key=itemgetter(1))
from itertools import *
from collections import Counter		# d = dict(Counter(l))
import math
import math
import time
from queue import Queue
# PradeepGhosh_2017076

def seive(n):
	l=[True]
	l=l*(n+1)
	for i in range(2,int(sqrt(n))+1):
		if(l[i]==True):
			val=i*i
			while(val<len(l)):
				l[val]=False
				val+=i
	prime=[]
	for i in range(2,len(l)):
		if(l[i]==True):
			prime.append(i)
	return prime

def dp(l,i,n,val,ans):
	if(i>=n or val<0):
		return 1000000
	elif(val==0):
		return 0
	else:
		if(ans[i]==1000000):
			ans[i]=min(min(1+dp(l,i+1,n,val-l[i],ans),1+dp(l,i,n,val-l[i],ans)),dp(l,i+1,n,val,ans))
		return ans[i]
from queue import Queue
def factors(n):
	l=[]
	for i in range(1,int(sqrt(n))+1):
		if(n%i==0):
			if(n//i==i):
				l.append(i)
			else:
				l.append(i)
				l.append(n//i)
	return l
def check1(s,v,x):
	while(True):
		if(v not in s):
			return v
		else:
			v-=1
def check2(s,v,x):
	while(True):
		if(v not in s):
			return v
		else:
			v+=1

if __name__ == '__main__':
	x,n=map(int,input().split(" "))
	if(n==0):
		print(x)
	else:
		l=list(map(int,input().split(" ")))
		s=set(l)
		a=x
		b=x
		while(True):
			if(a not in s):
				break
			else:
				a+=1
		while(True):
			if(b not in s):
				break
			else:
				b-=1

		v1=abs(a-x)
		v2=abs(b-x)
		print(a,b)
		if(v1<v2):
			print(a)
		elif(v2<v1):
			print(b)
		else:
			print(min(a,b))

Submission status: Wrong Answer

Solution code:
X,N=map(int,input().split())
P=list(map(int,input().split()))
hako=set(P)
ans=[]
P.sort()
kari=[]
if len(P)==0:
    print(100)
    exit()
for i in range(-200,101):
    if i not in hako:
        kari.append(i)
for i in range(len(kari)):
    ans.append([abs(X-kari[i]),kari[i]])
ans.sort()
print(ans[0][1])

Submission status: Wrong Answer

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

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

    arr.sort()
    mn = arr[0]
    mx = arr[-1]
    if x > mx :
        print(x)
    elif x  <mn  :
        print(x)
    else:
        c = 1e5
        d = {}
        res = 0 
        for i in range(n) :
            d[arr[i]]= 1
        for i in range(mn , mx):
            if not d.get(i , 0 ) :
                if abs(i - x)  <c :
                    res  = i
                    c = abs(i -x)

        print(res)

Submission status: Wrong Answer

Solution code:
x, n = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]
if n == 0:
    ans = x
else:
    p = sorted(p)
    min_p = min(p)
    max_p = max(p)
    j = 0
    ans = 0
    if x < min_p:
        ans = x
    elif x > max_p:
        ans = x
    else:
        for i in range(min_p+1, max_p):
            if i == p[j+1]:
                j += 1
            else:
                if abs(ans-x) > abs(i-x):
                    ans = i
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    x, n = map(int, input().split())
    p = list(map(int, input().split()))
    ans = x
    absol = 1000

    for i in range(x + 1, 101):
        if i not in p:
            if abs(i - x) < absol:
                absol = abs(i - x)
                ans = i
                break
    for i in range(x, 0, -1):
        if i not in p:
            if abs(i - x) <= absol:
                absol = abs(i - x)
                ans = i
                break    
    print(ans)

if __name__ == '__main__':
    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()))
p.sort()
ans = []
key = []

for i in range(0-max(p),max(p)+1):
  if i in p:
    continue
  else:
    #print(i)
    key.append(i)
    ans.append(abs(x-i))

aa = zip(ans,key)
aa = sorted(aa)
d,f = zip(*aa)
print(f[0])

Submission status: Wrong Answer

Solution code:
x, n = map(int,input().split())
p = list(map(int,input().split()))
l=[]
judge=[]
for i in range(120):
    l.append(i+1)

for i in range(n):
    l.remove(p[i])
for i in range(len(l)):
    judge.append((l[i]-x)**2)
judge.sort()
if x - judge[0]**0.5 in l :
    print(int(x - judge[0]**0.5))
else:
    print(int(x + judge[0]**0.5))

Submission status: Wrong Answer

Solution code:
def resolve():
    X, N = map(int, input().split())
    if N != 0:
        P = list(map(int, input().split()))
        if X in P:
            for j in range(N):
                if X+j in P:
                    continue
                else:
                    print(X+j)
                    exit()
                if X-j in P:
                    continue
                else:
                    print(X-j)
                    exit()
        else:
            print(X)
    else:
        print(X)
resolve()

Submission status: Wrong Answer

Solution code:
X,N= map(int,input().split())
p = list(map(int, input().split()))
p = sorted(p)
ans_tmp = 10**9+7
ans = 0
if N==0:
    print(X)
else:
    for i in range(-10000,10000):
        if i in p:
            continue
        else:
            tmp = abs(i-X)
            if tmp <ans_tmp:
                ans = i
                ans_tmp= min(tmp,ans_tmp)
print(ans)

Submission status: Wrong Answer

Solution code:

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

d=150
pa = 0
px =range(1,101,1)
py = list(set(px) - set(p))

for i in py:
    print(i)
    if d> abs(i-x):
        pa = i
        d = abs(i-x)
    elif d == abs(i-x):
        if i < pa:
            pa =i

print(pa)

Submission status: Wrong Answer

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

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

ans = 1

if N != 0 :
    for i in range(1,p[-1]+1):
        if p.count(i)==0 :
            if abs(X-i) < abs(X-ans) :
                ans = i
    print(ans)
else :
    print(X)

Submission status: Wrong Answer

Solution code:
import sys
X, N = map(int, input().split())
if (N==0):
    print(X)
    sys.exit()
elif(N==100):
    if(X<51):
        print(-1)
        sys.exit()
    else:
        print(101)
        sys.exit()
p = list(map(int, input().split()))

n_ans = 1
sa = 100
for k in range(1,101,1):
    if (k in p):
        continue
    if(abs(k-X) < sa):
        n_ans = k
        sa = abs(k-X)
    else:
        break
print(n_ans)

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
if n ==0:
    print(x)
    
else:
    p = list(map(int, input().split()))
    p.sort()
    #print(p)
    ans = 1000
    xx = 0
    for i in range(100):
        if not i in p:
            if x-i>=0 and ans>x-i:
                ans = x-i
                xx = i
            elif i-x>0 and ans>i-x:
                ans = i-x
                xx = i
    print(xx)

Submission status: Wrong Answer

Solution code:
import sys
x,n = map(int, sys.stdin.readline().rstrip("\n").split())
p = [int(s) for s in sys.stdin.readline().rstrip("\n").split()]
num = [i for i in range(1,101)]
for i in range(n):
    num.remove(p[i])
if not num:
    pass
elif x in num:
    print(x)
else:
    d = 1
    while True:
        if x-d in num:
            print(x-d)
            break
        elif x+d in num:
            print(x+d)
            break
        else:
            d += 1

Submission status: Wrong Answer

Solution code:
X,N=map(int,input().split())
p=list(map(int,input().split()))
p_bar=[]
for i in range(1,101):
  if i not in p:
    p_bar.append(i)

d_min=1000
i_min = 0
for i in p_bar:
  d = abs(X-i)
  if d < d_min:
    d_min = d
    i_min = i
print(i_min)

Submission status: Wrong Answer

Solution code:
def iput(): return int(input())
def mput(): return map(int, input().split())
def lput(): return list(map(int, input().split()))

def solve():
    x, n = mput()
    p = lput()
    ans = []
    for i in range(x, x-n-1, -1):
        boo = i in p
        if boo != True:
            ans.append(i)
            break
    for i in range(x, x+n+1):
        boo = i in p
        if boo != True:
            ans.append(i)
            break
    print(min(abs(x-ans[0]),abs(x-ans[1])))
    return 0

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
import sys


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

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

    for i in range(n):
        x1 = max(0, x - (i + 1))
        x2 = min(101, x + (i + 1))

        print(x1, x2)
        if x1 == 0:
            print(0)
            sys.exit()
            
        if not (x1 in P):
            print(x1)
            sys.exit()

        if x2 == 101:
            print(101)
            sys.exit()
            
        if not (x2 in P):
            print(x2)
            sys.exit()


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
try:
  p=list(map(int,input().split()))
except:
  print(x)
  exit()
ans=float('inf')
for i in range(1,101):
  if i not in p:
    ans=min(ans,abs(x-i))
    
    
if x-ans not in p and (x-ans)>=0 and (x-ans)<=x:
  print(x-ans)
  
elif x-ans not in p and (x-ans)<=x:
  print(x+ans)
elif x-ans not in p and (x-ans)>=0:
  print(x-ans)
else:
  print(x+ans)

Submission status: Wrong Answer

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

num = []
for i in range(100):
    num.append(i+1)
for j in range(n):
    num.remove(p[j])

a = 100 
b = 0
for k in range(100-n):
    if(abs(x-num[k]) < a):
        a = abs(x-num[k])
        b = num[k]

print(b)

Submission status: Wrong Answer

Solution code:
X, N = map( int, input().split() )
ret = X
if N > 0:
  P = sorted( list( map( int, input().split() ) ))
  dis = 10 ** 18
  for i in range( 100, -100, -1 ):
    if i in P:
      continue
    if dis - abs( i - X ) >= 0:
      ret = i
      dis = abs( i - X )
  
print( ret )

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
if n==0:
    print(x)
    exit()
elif n==100:
    print(-1)
    exit()
List=list(map(int,input().split()))
num=list(range(1,101))
min_num=0
for i in range(len(List)):
    if num.count(List[i])>=1:
        num.remove(List[i])
for i in range(len(num)):
    if abs(num[i]-x)<abs(min_num-x):
        min_num=num[i]
print(min_num)

Submission status: Wrong Answer

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

all_numbers = set(list(range(0, 101)))

search_numbers = list(all_numbers - Ps)

absolute_value = 1000
out = X
for i in search_numbers:
    if abs(i - X) < absolute_value:
        absolute_value = abs(i - X)
        out = i

print(out)