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) = [int(s) for s in input().split()]
p = set([int(s) for s in input().split()])
s = set(range(1, 101))

a = s - p

b = []
for i in a:
    b.append(abs(i - x))

min_val = 9999
ans = 9999
for (idx, (i, diff)) in enumerate(zip(a, b)):
    if min_val > diff:
        min_val = diff
        ans = i

print(ans)

Submission status: Wrong Answer

Solution code:
X, N = map(lambda x: int(x), input().split(" "))
if N != 0:
    Ps = set(map(lambda x: int(x), input().split(" ")))
    result = 0
    for i in range(1, 101):
        if i in Ps:
            continue
        if abs(X-result) > abs(X-i):
            result = i
else:
    input()
    result = X

print(result)

Submission status: Wrong Answer

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

for i in range(n):
    if x-i not in a:
        print(x-i)
        exit()
    elif x+i not in a:
        print(x+i)
        exit()

Submission status: Wrong Answer

Solution code:

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

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

  for i in range(N):
    if (X-i) not in set_p:
      print(X-i)
      return True

    if (X+i) not in set_p:
      print(X+i)
      return True

if __name__ == "__main__":
  resolve()

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)):
        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:
c,x = map(int,input().split())
if not x:
    print(c)
    exit()
a = list(map(int,input().split()))
s = list(range(1,100+1))
for i in a:
    s.remove(i)

diffB = 99999
n = 9999

for i in s:
    if diffB > abs(c-i):
        diffB = abs(c-i)
        n = i
print(n)

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
a=list(map(int,input().split()))
number=[0]*101

for num in range(len(a)):
    number[a[num]]=a[num]
    
counter=0
plus=0
ans=0

while counter==0:
    if number[x-plus]==0:
        counter+=1
        ans=x-plus
    elif number[x+plus==0]:
        counter+=1
        ans=x+plus
    else:
        plus+=1

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
x,n = map(int,input().split())
if n!=0:
    p = list(map(int,input().split()))
    q = [i for i in range(1,201)]
    r = set(q)-set(p)

    a = np.array(list(r))
    f = [x]*(len(list(r)))
    b = np.array(f)

    c = a-b
    d  = np.abs(c)
    e = np.argmin(d)

    print(int(c[int(e)])+x)
else:
    print(x)

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
ps = list(map(int, input().split()))
nums = list(range(1, 101))
for p in ps:
    nums.remove(p)
min_diff = float("inf")
min_original = float("inf")
for num in nums:
    diff = abs(num - x)
    if diff < min_diff:
        min_diff = diff
        min_original = num
    elif diff == min_diff:
        if num < min_original:
            min_original = num
print(min_original)

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()
    p2 = map(lambda a: a - x, p)
    ps = sorted(p2, key=abs)
    q = list(range((-1) * n, n))
    qs = sorted(q, key=abs)
    for i in range(n):
        if(ps[i] != qs[i]):
            print(qs[i] + x)
            break

Submission status: Wrong Answer

Solution code:
intX, length = map(int, input().split())
intList = input().split()
intList = [int(x) for x in intList]

for i in range(intX):
    if intX - i not in intList:
        print(intX - i)
        break
    elif intX + i not in intList:
        print(intX + i)
        break

Submission status: Wrong Answer

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

int_set = set(list(range(-101,101)))

for x in input().split():
    int_set.remove(int(x))

for i in range(101):
    if X - i in int_set:
        print(X - i)
        break
    elif X + i in int_set:
        print(X + i)
        break

Submission status: Wrong Answer

Solution code:
nums=[int(s) for s in input().split()]

x=nums[0]
n=nums[1]

if n==0:
  print(x)
else:
  row=[int(s) for s in input().split()]
  ls=[]
  for i in range(101):
    if i not in row:
      ls.append(abs(i-x))

  ls.sort()
  if x-ls[0] not in row and x-ls[0]>=0:
    print(x-ls[0])
  else:
    print(x+ls[0])

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
if N == 0:
    print(X)
else:
    P = list(map(int, input().split()))
    for i in range(1,100):
        if X-i >= 1 and X+i <= 100:
            if (X-i) not in P:
                print(X-i)
                break
            elif (X+i) not in P:
                print(X+i)
                break
        else:
            print(X)
            break

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
if n!=0:
    p = list(map(int,input().split()))
    li = set([i for i in range(101)])
    li = li-set(p)
    k=10**9
    m=0
    li=sorted(list(li))
    for i in li:
        if k>abs(x-i):
            k=abs(x-i)
            m=i
    print(m)
else:
    print(x)

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
p = list(map(int, input().split()))
ans = 101
for i in range(-100,101):
    if not i in p:
        if abs(i-X) < abs(ans-X):
            ans = i

print(ans)

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()
if X<P[0]:
    print(X)
    exit()
if X>P[-1]:
    print(X)
    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:
X,N = map(int,input().split())
if N == 0:
    if(X <= 50):
        print("0")
    else:
        print("100")
else:
    P = list(map(int,input().split()))
    mini = 100
    ANS = 0
    for i in range(102):
        if P.count(i) == 0:
            if mini > abs(X-i):
                mini = abs(X-i)
                ANS = i
    print(str(ANS))

Submission status: Wrong Answer

Solution code:
# C

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

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

ans = X
temp1 = X
temp2 = X

for i in range(N):
  temp1 = temp1 - 1
  temp2 = temp2 + 1
  if not temp1 in P:
    ans = temp1
    break
  elif not temp2 in P:
    ans = temp2
    break

print(ans)

Submission status: Wrong Answer

Solution code:
X, N = map(int,input().split())
p = list(map(int,input().split()))
kazu = [i for i in range(-100,101)]
sa = [0]*201
for i in range(201):
    if kazu[i] in p:
        kazu[i] = 1000
for i in range(201):
    sa[i] = abs(X-kazu[i])
print(kazu[sa.index(min(sa))])

Submission status: Wrong Answer

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

  min = 200
  ans = 0
  for i in range(102):
    if abs(x-i)!=0 and abs(x-i)<min and (i in p)==False:
      min = abs(x-i)
      ans = i

  print(ans)

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(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 numpy as np
x,n = map(int, input().split())
if n != 0:
    p = list(map(int, input().split()))
if n == 0:
    print(x)
    exit()
ll = np.ones(1)
for i in range(99):
    ll = np.append(ll,int(i+2))
    
for j in p:
    ll= ll[~(ll == j)]

if len(ll) == 0:
    print(x)
    exit()
# print(ll)

a = np.zeros(len(ll))
for i in range(len(ll)):
    a[i]=abs(x-ll[i])
# print(ll)
print(int(ll[np.argmin(a)]))

Submission status: Wrong Answer

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

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

if n == 100:
    if abs(x-0) <= abs(101-x):
        print(0)
    else:
        print(101)
    exit()

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

ans = 0
for i in range(1,101):
    if i in a:
        continue
    if abs(x-ans) > abs(x-i):
        ans = i
print(ans)

Submission status: Wrong Answer

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

syou = 1000
kouho = 1000

for i in range(-100, 101):
    flag = 0
    for j in range(n):
        if i == p[j]:
            flag = 1

    if flag == 1:
        continue

    if syou > abs(x-i):
        kouho = i
        syou = abs(x-i)
        continue
    elif syou == abs(x-i):
        kouho = min([kouho, i])
        continue

print(kouho)

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(1,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())
P = list(map(int,input().split()))
if N == 0:
    print(X)
    exit(0)
A = list(range(0,max(P)))
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:
k = list(map(int, input().split()))
if k[1] == 0:
  print(k[0])
else:
  l = list(map(int, input().split()))
  a = [i for i in range(-100,101) if not i in l]
  m = []
  for i in a:
    m.append(abs(i - k[0]))
  print(a[m.index(min(m))])

Submission status: Wrong Answer

Solution code:
def intMap(): return map(int,input().split())
def intList(): return list(map(int, input().split())) #横並びの場合

x,n = intMap()
p = intList()

not_included = list(range(1,100))
for i in p:
    if i in not_included:
        not_included.remove(i)

mini = 101
mini_i = 1
for i in not_included:
#    print("i={}, abs={}, mini={}".format(i,abs(i-x),mini))
    if abs(i - x) < mini:
        mini = abs(i-x)
        mini_i = i

if mini > x:
    mini_i = 0
if n == 0:
    mini_i = x

print(mini_i)

Submission status: Wrong Answer

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


min= 100

p.sort()

for i in range(-100, 101):
  if (i not in p ) and len(p) > 0:
    a = abs(i-X)
    if a<min:
      min=a
      ans = i
print(ans)

Submission status: Wrong Answer

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

if len(List)==0:
    print(X)
else:
    s=True
    num=1
    num1=1
    max=0
    min=0
    while s:
        if not X+num in List:
            max=X+num
            break
        num+=1
    while s:
        if not X-num1 in List:
            min=X-num1
            break
        num1+=1
    #print(max,min)
    if max-X<X-min:
        print(max)
    else:
        print(min)

Submission status: Wrong Answer

Solution code:
a=[int(x) for x in input().split()]
b=[int(x) for x in input().split()]
b=sorted(b)
base = 1000
for i in range(-100, 101):
  if abs(a[0]-base)>abs(a[0]-i) and i not in b:
    base = i
print(base)

Submission status: Wrong Answer

Solution code:
X,N=list(map(int,input().split()))
if N==0:
  print(X)
else:
  p_list=list(map(int,input().split()))
  not_p_list=[]
  for i in range(101):
    if i not in p_list:
      not_p_list.append(i)

  nN=len(not_p_list)
  abs_list=[]
  for i in range(nN):
    temp=not_p_list[i]-X
    abs_list.append(abs(temp))

  abs_list.sort()    
  if abs_list[0]==0:
    print(X)
  else:
    ans=abs_list[0]
    for i in range(nN):
      if not_p_list[i]==X-ans:
        print(X-ans)
        break
      elif not_p_list[i]==X+ans:
        print(X+ans)
        break

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

import bisect as bis
p.sort()
now = x
n = 1

for i in range(100):
    pm = n * (-1)**n
    index = bis.bisect_left(p, now)
    if index < len(p) and p[index] == now:
        now += pm
        n += 1
    else:
        print(now)
        break

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
if n==0: exit(print(x))
p = list(map(int,input().split()))
p.sort()
if x not in p: exit(print(x))
h=1000
l=1000
for i in range(x,101):
    if i not in p:
        h = i
        break
for i in range(x,0,-1):
    if i not in p:
        l = i
        break
if abs(x-h)>=abs(x-l): print(l)
if abs(x-l)>abs(x-h): print(h)

Submission status: Wrong Answer

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

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

i=0
while True:
    if not x-i in p and 1<=x-i:
        print(x-i)
        break
    elif not x+i in p and x+i<=100:
        print(x+i)
        break
    i+=1

Submission status: Wrong Answer

Solution code:
X, N = [int(i) for i in input().split()]
if N == 0:
    print(X)
else:
    P = [int(i) for i in input().split()]
    ans = 0
    for i in range(100):
        if X - i < 1:
            ans = X - i
            break
        elif X + i > 100:
            ans = X + 1
            break
        elif X - i not in P:
            ans = X - i
            break
        elif X + i not in P:
            ans = X + i
            break
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys
x,n=map(int,input().split())
if n==0:
    print(x)
    sys.exit()
else:
    p=list(map(int,input().split()))
    res=1000
    ans=0
    for i in range(101,1,-1):
        p.append(i)
        if len(p)==len(set(p)):
            if res>=abs(x-i):
                res=abs(x-i)
                ans=i
        del p[-1]
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline

def main():
    x, n = map(int, input().rstrip().split())
    if n == 0:
        print(x)
        sys.exit()
    else:
        p = list(map(int, input().rstrip().split()))
        if x > max(p):
            print(x)
            sys.exit()
        else:
            p_x = set(range(max(p)+1))
            p_temp = set(p)
            p_diff = p_x - p_temp
            p_temp = list(p_diff)
            p_dir = []

        for i in range(len(p_temp)):
            p_dir.append(abs(p_temp[i] - x))
        print(p_temp[p_dir.index(min(p_dir))])
  
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
ans = 0
p.sort()
if n == 0:
    print(x)
    exit()
for i in range(p[0], p[n - 1] + 1):
    if (i not in p) and abs(x - i) < abs(ans - x):
        ans = i

print(ans)

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
p = list(map(int,input().split()))
min_num = 1000
num = 0
for i in range(101):
    if i not in p:
        if abs(x-i) < min_num:
            min_num = abs(x-i)
            num = i
print(num)

Submission status: Wrong Answer

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

li = []


for i in range(101):
    if not i in p:
        li.append(i)

zzz = float('inf')
ans = 0

for i in li:
    if zzz > abs(x - i):
        zzz = abs(x - i)
        ans = i


print(ans)

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 - 1
min_val = 1
for y in range(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:
if __name__ == '__main__':
	x,n = map(int,input().split())
	p = [int(a) for a in input().split()]
	p.sort()
	if x in p:
		if p[0] > x:
			print(p[0])
		elif p[-1] < x:
			print(p[-1])
		else:
			m = 100
			ans = 0
			for i in range(p[0],p[-1]):
				if not i in p:
					v = abs(i-x)
					if m > v:
						m = v
						ans = i
			print(ans)
	else:
		print(x)

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(1,N):
    if abs(N-i) not in p or abs(N+i) not in p:
      print(max([abs(N-i),abs(N+i)]))
      break

Submission status: Wrong Answer

Solution code:
X,N = map(int,input().split())
if N>0:
  p=set(map(int,input().split()))
  px={_ for _ in range(1,101)}
  p=px-p
  sorted(p)
  min_diff,min_p=101,101
  for pi in p:
    diff=abs(pi-X)
    if min_diff>diff:
      min_diff=diff
      min_p=pi
  print(min_p)
else:print(X)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left

x,n=list(map(int,input().split()))
if n:
  A=list(map(int,input().split()))
else:
  print(x)
  exit()
  
for i in range(n):
  if x-i in A and x+i in A:
    continue
  elif x+i in A or (not x-i in A and not x+i in A):
    print(x-i)
    break
  else:
    print(x+i)
    break

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())
if n == 0:
    print(x)
    exit()
p = list(map(int, input().split()))
d = [0]*101

for i in p: d[i] = 1

else:
    i = 0
    while True:
        if x-i>=0:
            if d[x-i] == 0:
                print(x-i)
                break
        if x+i<=100:
            if d[x+i] == 0:
                print(x+i)
                break
        i += 1

Submission status: Wrong Answer

Solution code:
import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
x, n = M()
if n == 0:
    print(x)
else:
    n_l = LI()
    suchi_list = [i for i in range(1, 101)] # 1~100までのリスト
    ans = -1
    for i in n_l:
        suchi_list.remove(i)
    if x in suchi_list:
        ans = x
    else:
        for j in range(1, 101):
            if x-j in suchi_list:
                ans = x-j
            elif x+j in suchi_list:
                ans = x+j
            if ans != -1:
                break
    print(ans)

Submission status: Wrong Answer

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

for i in range(101):
    sub = x - i
    if sub < 0:
        continue
    if sub not in ps:
        print(sub)
        break

    add = x + i
    if add > 100:
        continue
    if add not in ps:
        print(add)
        break

Submission status: Wrong Answer

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

if x not in p:
    print(x)
else:
    for num in p:
        ll.remove(num)
    l2 = []
    ans = float('inf')
    for i in ll:
        if abs(i-x) < abs(x-ans):
            ans = i
        if abs(i-x) == abs(ans-x):
            ans = min(i, ans)

    print(ans)

Submission status: Wrong Answer

Solution code:
x,n=input().split()
a = list(map(int,input().split()))
if a==[]:
    print(int(x))

xx=int(x)
for i in range(int(n)):
    if xx+i not in a:
        print(i+xx)
        exit()
    elif xx-i not in a:
        print(xx-i)
        exit()

Submission status: Wrong Answer

Solution code:
import numpy as np

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

ret = X

for i in range(50):
  if X-i not in plist:
    ret -= i
    break
  elif X+i not in plist:
    ret += i
    break

print( ret )

Submission status: Wrong Answer

Solution code:
import sys


def main():
    X, N = list(map(int, input().split()))
    dis = 200
    ans = 101
    if N == 0:
        print(X)
        sys.exit()
    P = list(map(int, input().split()))
    for i in range(0, 101):
        if i not in P:
            if dis > abs(i - X):
                dis = abs(i - X)
                ans = i
    print(ans)


if __name__ == '__main__':
    main()

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-1] in p:
        print(x+p[i-1])
      else:
        print(x-p[i-1])
      sys.exit()
print(x)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

import math
import re
import numpy as np
import copy


S = input().split(" ")
X = int(S[0])
N = int(S[1])

#初期値
ans = 0

#空行の場合
if N == 0:
    ans = X

else:
    pn = [int(i) for i in input().split(" ")]

    #距離の最小値の初期値
    min_dist = 1000

    #大きい数字から全探索（超える場合のみ更新）
    for i in range(1,102):
        if not i in pn:
            dist = abs(X - i)
            if dist < min_dist:
                ans = i
                min_dist = dist

    #-1との距離も調べる
    if abs(X + 1) < min_dist:
        ans = -1

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]
    ans_p = math.inf
    for i, pp in enumerate(pre, start=1):
        if X!=(pp+i):
            ans_p = X-i

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

    print(min(ans_a, ans_p))

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    x, n = map(int, input().split())
    if n >0:
        a = [int(i) for i in input().split()]
        listN = [i for i in range(-1,100)]
        diffList = list(set(listN) -set(a) )
        ans = 0
        diff = 100
        for i in diffList:
            now = 0
            if i>0:
                now = abs(i-x)
            else:
                now = abs(i)+abs(x)
            if diff > now:
                diff=now
                ans =i
        print(ans)
    else:
        print(x)

Submission status: Wrong Answer

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

if p is None or not x in p:
  print(x)
else:
  for i in range(1, n):
    if not (x - i) in p:
      print(x - i)
      break
    elif not (x + i) in p:
      print(x + i)
      break

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
p=list(map(int,input().split()))
ans=1e9
for i in range(1,x+101):
  if i in p:
    continue
  ans=min(ans,abs(x-i))

if x-ans in p:
  print(x+ans)
else:
  print(x-ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
X,N = map(int, input().split())
if N != 0:
  p = list(map(int, input().split()))
  min_val = -100
  max_val = 100
  not_p = [i for i in range(min_val,max_val+1,1)]
  not_p.remove(0)
  
  for i in range(N):
    not_p.remove(p[i])
  #print(not_p)

  min_val = 101
  out_num = 101
  for i in range(len(not_p)):
    if abs(X-not_p[i]) < min_val:
      min_val = abs(X-not_p[i])
      out_num = not_p[i]
else:
  out_num = 0
print(out_num)

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
q = []
cnt = 1000
ans = 0
for i in range(1,101):
    if not i in p:
        q.append(i)
for i in q:
    if cnt > abs(x-i):
        ans = i
        cnt = abs(x-i)
print(ans)

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:
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def read_a_int(): return int(read())


def read_ints(): return list(map(int, read().split()))


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_tuple(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_matrix(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right

X, N = read_ints()
if N == 1:
    print(X)
    exit()
P = read_ints()
candi = []
for i in range(-1, 103):
    if i in P:
        continue
    candi.append(i)
candi.sort(key=lambda x: abs(X - x))
if candi[0] == candi[1]:
    print(min(candi[0], candi[1]))
else:
    print(candi[0])

Submission status: Wrong Answer

Solution code:
import sys
from bisect import bisect_left, bisect_right

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

X,N = LI()
P_jyogai = LI()

P = list(range(-100,101))

P_difference = set(P)-set(P_jyogai)
P_difference = list(P_difference)
P_difference.sort()

sabun = 100000000
ans = 0
for p_diff in P_difference:
    temp = abs(X-p_diff)
    if sabun > temp:
        sabun = temp
        ans = p_diff
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()]
mn = 1000
for i in reversed(range(101)):
	if i in P:
		continue
	if mn >= abs(X-i):
		ans = i
		mn = min(mn,abs(X-i))

print(ans)

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):
    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 = list(map(int, input().split()))
p = list(map(int, input().split()))
# ab_sorted = sorted(ab, key=lambda x: x[0])
#p = [list(map(int, input().split())) for i in range(n)]
# print(min(15*n, 100*(n//10+1), 100*(n//10)+15*(n % 10)))
dif = 1000
ans = 1000
for i in range(-101, 101):
    if not(i in p):
        if abs(i-x) < dif:
            dif = abs(i-x)
            ans = i
        elif abs(i-x) == dif:
            if ans > i:
                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()
else:
  l = list(map(int, input().split()))
  
  ze = [0 for i in range(101)]
  
  for i in range(n):
    ze[abs(x-l[i])] += 1
    
  if ze[0] == 0:
    print(x)
  else:
    for i in range(1, 101):
      if ze[i] < 2:
        if x+i not in l:
          print(x+i)
          sys.exit()
        else:
          print(x-i)
          sys.exit()

Submission status: Wrong Answer

Solution code:
X,N = map(int,input().split())
if N > 0:
  p = list(map(int,input().split()))
a = 100
ans = 0
for i in range(-101,101):
  if N == 0:
    ans = X
    break
  if p.count(i) == 0 and a >= abs(X - i):
    a = abs(X - i)
    ans = i
if N > 0:
  for i in range(-101,101):
    if abs(X-i) == abs(X-ans) and p.count(i) == 0:
      ans = i
      break
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

p = sorted(list(map(int, input().split())))
P = []

for i in range(102):
    P.append(i)


MOD = 10**9+7
tmp = 0
m = 9999999999999
ans = 0

for i in range(N):
    P[p[i]] = MOD


for i in reversed(range(1,len(P))):

    tmp = abs(P[i]-X)
    m = min(m,tmp)
    if m == tmp:
        ans = i
print(ans)