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())
p=list(map(int, input().split()))
youso=[]
for i in range(-100,101):
    if not i in p:
        youso+=[i]
hikaku=[]
for i in youso:
    hikaku+=[(i,abs(x-i))]
hikaku1=sorted(hikaku,key=lambda x:x[1])
if n == 0:res = x
elif n == 100:res=0
else :res=hikaku1[0][0]
print(res)

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
p=list(map(int, input().split()))
youso=[]
for i in range(101):
    if not i in p:
        youso+=[i]
hikaku=[]
for i in youso:
    hikaku+=[(i,abs(x-i))]
hikaku1=sorted(hikaku,key=lambda x:x[1])
if n == 0:res = x
elif n == 100:res=0
else :res=hikaku1[0][0]
print(res)

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
p=list(map(int, input().split()))
youso=[]
for i in range(101):
    if not i in p:
        youso+=[i]
hikaku=[]
for i in youso:
    hikaku+=[(i,abs(x-i))]
hikaku1=sorted(hikaku,key=lambda x:x[1])
if n == 0:res = x
else :res=hikaku1[0][0]
print(res)

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
p=list(map(int, input().split()))
youso=[]
for i in range(100):
    if not i in p:
        youso+=[i]
hikaku=[]
for i in youso:
    hikaku+=[(i,abs(x-i))]
hikaku1=sorted(hikaku,key=lambda x:x[1])
if n == 0:res = x
else :res=hikaku1[0][0]
print(res)

Submission status: Wrong Answer

Solution code:
x,n = map(int, input().split())
p = list(map(int, input().split()))
ans = 100
num = 0
for i in range(101):
    if i not in p:
        if abs(x - i) < ans:
            ans = 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()))
ans = 101
num = 0
for i in range(101):
    if i not in p:
        if abs(x - i) < ans:
            ans = 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()))
ans = 101
num = 0
for i in range(1,100):
    if i not in p:
        if abs(x - i) < ans:
            ans = abs(x - i)
            num = i
print (num)

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()))
p = [-1] + p + [101]
import bisect
p.sort()
i = bisect.bisect_left(p,x)
if p[i] != x:
    print(x)
    exit()

for h in range(102):
  if p[i-h] != x-h:
    print(x-h)
    exit()
  elif p[i+h] != x+h:
    print(x+h)
    exit()

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()))
p = [-1] + p + [101]
import bisect
p.sort()
i = bisect.bisect_left(p,x)
if p[i] != x:
    print(x)
    exit()

for h in range(102):
  if p[i-h] != x-h:
    print(p[i])
    exit()
  elif p[i+h] != x+h:
    print(x+h)
    exit()

Submission status: Wrong Answer

Solution code:
x,n = map(int, input().split())
p = list(map(int, input().split()))
ans = 101
num = 100 - x
for i in range(101):
    if i not in p:
        if abs(x - i) < ans:
            ans = 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()))
ans = 101
num = 100
for i in range(101):
    if i not in p:
        if abs(x - i) < ans:
            ans = abs(x - i)
            num = i
print (num)

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()))
p = [-1] + p + [101]
import bisect
p.sort()
i = bisect.bisect_left(p,x)

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()))
p = [-1] + p + [101]
import bisect
p.sort()
i = bisect.bisect_left(p,x)

for h in range(102):
  if p[i] != x:
    print(x)
    exit()
  elif p[i-h] != x-h:
    print(p[i])
    exit()
  elif p[i+h] != x+h:
    print(x+h)
    exit()

Submission status: Wrong Answer

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

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()))
p = [-1] + p + [101]
import bisect
p.sort()
i = bisect.bisect_left(p,x)

for h in range(p[-1]-p[0]+1):
  if p[i-h] != x-h:
    print(x-h)
    exit()
  elif p[i+h] != x+h:
    print(x+h)
    exit()

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

forbid = [True]*102

for i in range(len(p)):
    if forbid[p[i]]:
        forbid[p[i]] = False
        
pp = []

for i in range(len(forbid)):
    if forbid[i]:
        pp.append(i-X)

num = pp[len(pp)-1]        
for i in range(len(pp)-1,0,-1):
    if abs(num) >= abs(pp[i]):
        num = pp[i]
        
print(num+X)

Submission status: Wrong Answer

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

forbid = [True]*102

for i in range(len(p)):
    if forbid[p[i]]:
        forbid[p[i]] = False
        
pp = []

for i in range(len(forbid)):
    if forbid[i]:
        pp.append(i-X)

num = pp[len(pp)-1]        
for i in range(len(pp)-1,0,-1):
    if abs(num) >= abs(pp[i]):
        num = pp[i]
        
print(num+X)

Submission status: Wrong Answer

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

min = 1000
pre_i = 0
for i in range(102):
    if i in p:
        continue
    if min > abs(x - i):
        min = abs(x - i)
    else:
        print(pre_i)
        break
    pre_i = i

Submission status: Wrong Answer

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

if n > 0:
    p_list = [int(i) for i in input().split()]
else:
    print(x)
    sys.exit(0)

table = {i for i in range(-n, 101)}
table = list(table - set(p_list))
table.sort()
d_min = 101
pre_i = table[0]

for i in table:
    diff = abs(x - i)
    if d_min > diff:
        d_min = diff
    else:
        break
    pre_i = i

print(pre_i)

Submission status: Wrong Answer

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

if n > 0:
    p_list = [int(i) for i in input().split()]
else:
    print(x)
    sys.exit(0)

table = {i for i in range(101)}
table = list(table - set(p_list))
diff = 0
d_min = 101
pre_i = table[0]

for i in table:
    diff = abs(x - i)
    if d_min > diff:
        d_min = diff
    else:
        break
    pre_i = i

print(pre_i)

Submission status: Wrong Answer

Solution code:
a,b = map(int,input().split())
if(b != 0):
  c = list(map(int,input().split()))
else:
  print(a)
  exit()
ans = 0
for i in range(101):
  if(a+i not in c):
    if(a+i > 101):
      break
    else:
      ans = a+i
      break
for i in range(101):
  if(a-i not in c):
    if(a-i < 0):
      break
    else:
      if(abs(ans-(a-i)) < abs(a-ans)):
        ans = a-i
      elif(abs(ans-(a-i)) == abs(a-ans)):
        ans = min(a-i,ans)
      break
print(ans)

Submission status: Wrong Answer

Solution code:
a,b = map(int,input().split())
if(b != 0):
  c = list(map(int,input().split()))
else:
  print(a)
  exit()
ans = 0
for i in range(100):
  if(a+i not in c):
    if(a+i > 101):
      break
    else:
      ans = a+i
      break
for i in range(100):
  if(a-i not in c):
    if(a-i < 0):
      break
    else:
      if(abs(ans-(a-i)) < abs(a-ans)):
        ans = a-i
      elif(abs(ans-(a-i)) == abs(a-ans)):
        ans = min(a-i,ans)
      break
print(ans)

Submission status: Wrong Answer

Solution code:
a,b = map(int,input().split())
if(b != 0):
  c = list(map(int,input().split()))
else:
  print(a)
  exit()
ans = 0
for i in range(100):
  if(a+i not in c):
    if(a+i > 100):
      break
    else:
      ans = a+i
      break
for i in range(100):
  if(a-i not in c):
    if(a-i < 1):
      break
    else:
      if(abs(ans-(a-i)) < abs(a-ans)):
        ans = a-i
      elif(abs(ans-(a-i)) == abs(a-ans)):
        ans = min(a-i,ans)
      break
print(ans)

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
if N == 0:
	print(X)
if N == 1:
	p = [int(input())]
	print(102)
else:
    p = list(map(int, input().split()))
for d in range(N+1):
	for s in [-1, +1]:
		a = X + s * d
		if p.count(a) == 0:
			print(a)
			exit(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 d in range(N):
	for s in [-1, +1]:
		a = X + s * d
		if p.count(a) == 0:
			print(a)
			exit(0)

Submission status: Wrong Answer

Solution code:
X,N = list(map(int, input().split()))
if N == 0:
	print(X)
else:
	p = list(map(int,input().split()))
a = 0
b = 0
for i in range(N):
  a = X + i
  b = X - i
  if p.count(b) == 0:
    print(b)
    exit(0)
  elif p.count(a) == 0:
    print(a)
    exit(0)

Submission status: Wrong Answer

Solution code:
X,N = list(map(int, input().split()))
if N == 0:
	print(X)
else:
	p = list(map(int,input().split()))
a = 0
b = 0
for i in range(N):
  a = X + i
  b = X - i
  if p.count(b) == 0:
    print(b)
    break
  elif p.count(a) == 0:
    print(a)
    break

Submission status: Wrong Answer

Solution code:
X,N = list(map(int, input().split()))
if N == 0:
	print(X)
else:
	p = list(map(int,input().split()))
a = 0
b =0
for i in range(N):
  a = X + i
  b = X - i
  if int(b in p) == 0:
    print(b)
    break
  elif int(a in p) == 0:
    print(a)
    break

Submission status: Wrong Answer

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

list = []

a = x
while True:
    if not a in plist:
        list.append(a)
        break
    a += 1

b = x-1
while True:
    if not b in plist:
        list.append(b)
        break
    b -= 1

print(min(list))

Submission status: Wrong Answer

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

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

    i = 1
    while True:
        minus = x - i
        plus = x + i

        if not minus in ps:
            print(minus)
            break
        elif not plus in ps:
            print(plus)
            break
        
        i += 1

Submission status: Wrong Answer

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

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

    i = 1
    while True:
        minus = x - i
        plus = x + i

        if not minus in ps and not plus in ps:
            print(minus)
            break
        elif not minus in ps and plus in ps:
            print(minus)
            break
        elif minus in ps and not plus in ps:
            print(plus)
            break
        
        i += 1

Submission status: Wrong Answer

Solution code:
x,n = list(map(int,input().split()))
a = list(map(int,input().split()))
xp = x
xm = x
for i in range(n//2+1):
  if xm not in a:
    print(xm)
    exit(0)
  if xp not in a:
    print(xp)
    exit(0)    
  xp += 1
  xm -= 1

Submission status: Wrong Answer

Solution code:
X,N = map(int,input().split())
A = list(map(int,input().split()))
for d in range(X+1):
  for i in [1,-1]:
    B = X + d*i
    if A.count(B) == 0:
      print(B)
      exit(0)

Submission status: Wrong Answer

Solution code:
X,N = map(int,input().split())
A = list(map(int,input().split()))
import sys
for d in range(X+1):
  for i in [1,-1]:
    B = X + d*i
    if A.count(B) == 0:
      print(B)
      sys.exit()

Submission status: Wrong Answer

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

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

Ans = 400

for i in range(102):
    if max(0,X-i) in p:
        Ans = Ans
    else:
        Ans = max(0,X-i)
        break
    if min(101,X+i) in p:
        Ans=Ans
    else:
        Ans = min(100,X+i)
        break
print(Ans)

Submission status: Wrong Answer

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

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

Ans = 400

for i in range(100):
    if max(0,X-i) in p:
        Ans = Ans
    else:
        Ans = max(0,X-i)
        break
    if min(101,X+i) in p:
        Ans=Ans
    else:
        Ans = min(100,X+i)
        break
print(Ans)

Submission status: Wrong Answer

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

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

Ans = 400

for i in range(100):
    if max(0,X-i) in p:
        Ans = Ans
    else:
        Ans = max(0,X-i)
        break
    if min(100,X+i) in p:
        Ans=Ans
    else:
        Ans = min(100,X+i)
        break
print(Ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
p = list(map(int, input().split()))
for i in range(X+1):
  for j in [-1, +1]:
    a = X + j * i
    if p.count(a) == 0:
      print(a)
      break

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
p = list(map(int, input().split()))
i = 1
while True:
  if (X - i) >= 0 and not (X - i) in p:
    answer = X - i
    break
  elif (X + i) <= 100 and not (X + i) in p:
    answer = X + i
    break
  else:
    i += 1

print(answer)

Submission status: Wrong Answer

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


if N == 0:
  answer = X
else:
  p = list(map(int, input().split()))
  i = 1
  while True:
    if (X - i) >= 0 and not (X - i) in p:
      answer = X - i
      break
    elif (X + i) <= 100 and not (X + i) in p:
      answer = X + i
      break
    else:
      i += 1

print(answer)

Submission status: Wrong Answer

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


if N == 0:
  answer = X
else:
  p = list(map(int, input().split()))
  i = 1
  while True:
    if not (X - i) in p and (X - i) >= 0:
      answer = X - i
      break
    elif not (X + i) in p and (X + i) <= 100:
      answer = X + i
      break
    else:
      i += 1

print(answer)

Submission status: Wrong Answer

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


if N == 0:
  answer = X
else:
  p = list(map(int, input().split()))
  i = 1
  while True:
    if not (X - i) in p:
      answer = X - i
      break
    elif not (X + i) in p:
      answer = X + i
      break
    else:
      i += 1

print(answer)

Submission status: Wrong Answer

Solution code:
# cook your dish here
def fun():
    x, n = list(map(int, input().split()))
    if n == 0: return x
    num_list = list(map(int, input().split()))
    hashmap = {num: True for num in num_list}
    m = []
    i = 1
    a, b = (-1, +1) if x >= 0 else (+1, -1)
    answer = float('inf')
    for _ in range(n):
        for dif in (a*i, b*i):
            if x+dif not in hashmap:
                m.append(x + dif)
            if len(m) == 2:
                break
        if len(m) == 2:
            break
        i += 1
    #print(m)
    answer = min([(abs(num-x), num) for num in m])
    return answer[1]
    
print(fun())

Submission status: Wrong Answer

Solution code:
def fun():
    x, n = list(map(int, input().split()))
    if n == 0: return x
    num_list = list(map(int, input().split()))
    
    hashmap = {num: True for num in num_list}
    a = []
    i = 1
    answer = float('inf')
    for _ in range(n):
        for dif in (-1*i, +1*i):
            if x+dif not in hashmap:
                a.append(x + dif)
            if len(a) == 2:
                break
        if len(a) == 2:
            break
        i += 1
    #print(a)
    answer = min([(abs(num-x), num) for num in a])
    return answer[1]
    
print(fun())

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
from collections import defaultdict

x,n = map(int,input().split())
if n==0:
    print(x)
else:
    dd = defaultdict(int)
    arr = list(map(int,input().split()))
    for i in range(len(arr)):
        dd[x-arr[i]]+=1
    
    print(dd)

    for i in range(101):
        if dd[i]==0:
            print(x-i)
            break
        elif dd[-i]==0:
            print(x+i)
            break

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left

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


if N == 0:
    print(X)

else:
    plist.sort()
    not_plist = [x for x in range(plist[0]-1, plist[-1]+2, 1)  if x not in plist]

    print(not_plist)

    idx = bisect_left(not_plist, X)

    if idx == 0:
        print(X)

    elif idx == len(not_plist):
        print(X)

    else:
        left = X - not_plist[idx-1]
        right = not_plist[idx] - X
        if left <= right:
            print(not_plist[idx-1])
        else:
            print(not_plist[idx])

Submission status: Wrong Answer

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

except:
    pass

Submission status: Wrong Answer

Solution code:
x,n=map(int, input().split())
try:
    l=list(map(int ,input().split()))
    i=1
    while(True):
        if (x-i) not in l:
            print(x-i)
            break
        if(x+i) not in l:
            print(x+i)
            break
        i+=1

except:
    print(x)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

i = 1
while True:
    low_x = x - i
    if low_x not in p_list:
        print(low_x)
        break
    
    high_x = x + i
    if high_x not in p_list:
        print(high_x)
        break

    i += 1

Submission status: Wrong Answer

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

if not p_list:
    print(x)
    exit()

i = 1
while True:
    low_x = x - i
    if low_x not in p_list:
        print(low_x)
        break
    
    high_x = x + i
    if high_x not in p_list:
        print(high_x)
        break

    i += 1

Submission status: Wrong Answer

Solution code:


x, n = map(int, input().split())
try:
	p_li = list(map(int, input().split()))
except:
	print(x)
	exit()

for i in range(1000):
	
	if not((x - i) in p_li):
		print(x - i)
		break
	
	if not((x - i) in p_li):
		print(x - i)
		break

Submission status: Wrong Answer

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

for i in range(101):
  xl = x - 1
  xr = x + 1
  if xl not in P:
    print(xl)
    break
  if xr not in P:
    print(xr)
    break

Submission status: Wrong Answer

Solution code:
X,N = map(int,input().split())
n = [0]*101
p = list(map(int,input().split()))
for i in range(N):
    n[p[i]]=1
for i in range(100):
    if X-i>0:
        if n[X-i]==0:
            print(X-i)
            break
    if X+i<100:
        if n[X+i]==0:
            print(X+i)
            break

Submission status: Wrong Answer

Solution code:
mod = int(1e9+7)
def add(a, b):
    c = a + b
    if c >= mod:
        c -= mod
    return c

def main():
    INF = 1e9+7
    
    x, n = map(int,raw_input().split())
    
    arr = map(int,raw_input().split())
    
    s = set(arr)
    
    ret = INF
    
    for num in range(1, 102):
        if num not in s:
            diff = abs(num - x)
            ret_diff = abs(ret - x)
            if diff < ret_diff:
                ret = num
            elif diff == ret_diff and num < ret:
                ret = num
    
    print(ret)
    

main()

Submission status: Wrong Answer

Solution code:
mod = int(1e9+7)
def add(a, b):
    c = a + b
    if c >= mod:
        c -= mod
    return c

def main():
    INF = 1e9+7
    
    x, n = map(int,raw_input().split())
    
    arr = map(int,raw_input().split())
    
    s = set(arr)
    
    ret = INF
    
    for num in range(1, 101):
        if num not in s:
            diff = abs(num - x)
            ret_diff = abs(ret - x)
            if diff < ret_diff:
                ret = num
            elif diff == ret_diff and num < ret:
                ret = num
    
    print(ret)
    

main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from sys import stdin,stdout
LI=lambda:list(map(int,input().split()))
MAP=lambda:map(int,input().split())
IN=lambda:int(input())
S=lambda:input()
import math
from collections import Counter,defaultdict


x,n=MAP()
if n==0:
    print(x)
    exit()
a=LI()
l=-1;r=-1
for i in range(1,101):
    if x-i not in a:
        l=x-i
        break
for i in range(1,101):
    if x+i not in a:
        r=x+i
        break
if abs(r-x)>=abs(l-x):
    print(l)
else:
    print(r)

Submission status: Wrong Answer

Solution code:
from sys import stdin,stdout
LI=lambda:list(map(int,input().split()))
MAP=lambda:map(int,input().split())
IN=lambda:int(input())
S=lambda:input()
import math
from collections import Counter,defaultdict


x,n=MAP()
if n==0:
    print(x)
    exit()
a=LI()
l=-1;r=-1
for i in range(1,100):
    if x-i not in a:
        l=x-i
        break
for i in range(1,100):
    if x+i not in a:
        r=x+i
        break
if abs(r-x)>=abs(l-x):
    print(l)
else:
    print(r)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
x,n = map(int,input().split())
l = list(map(int,input().split()))
not_l,ans = [],[]
if not x in l:
	print(x)
	sys.exit()
l = sorted(l)
for i in range(1,max(l)+3):
	if not i in l:
		not_l.append(i)
for j in range(len(not_l)):
	ans.append([not_l[j],abs(not_l[j]-x)])
ans.sort(key=lambda x:x[1])
print(ans[0][0])

Submission status: Wrong Answer

Solution code:
def main():
  X,N = list(map(int, input().split()))
  P = list(map(int, input().split()))
  # handle corner case:
  if N==0: return
  #allowed elements
  Q = set([i for i in range(0,101+1)])
  for p in P:
    Q.remove(p)
  Q = sorted(Q)
  # distance from X
  D = [abs(q-X) for q in Q]
  # find smallest minimizer
  minD = min(D)
  for d,q in zip(D,Q):
    if d==min(D):
      break
  print(q)
    
if __name__=='__main__':
  main()

Submission status: Wrong Answer

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

list_100 = []
for i in range(1,102):
    list_100.append(i-1)

def xx(n):
    return abs(n-X)

numberlist = list(set(list_100) - set(numberlist)) #初期リストに含まれない数のリスト
number_x = sorted(map(xx, numberlist) ) #n-X絶対値順
#print(number_x)

ans1 = X + number_x[0]
ans2 = X - number_x[0]
if ans2 in numberlist:
    print(ans2)
else:
    print(ans1)

Submission status: Wrong Answer

Solution code:

from collections import Counter
a,b=list(map(int,input().split()))
m=list(map(int,input().split()))
#m.sort()
c=[]
for i in range(b):
    c.append(abs(m[i]-a))
c=Counter(c)

if b>0:
    i=0
    while i<b:
        if i not in c:
            print(a-i)
            break
        
        elif c[i]<2 and i!=0:
            if a-i in m:
                print(i+a)
            else:
                print(-i+a)
            break
        i+=1
else:
    print(a)

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split()) 
p = list(set(range(1,100)).difference(map(int, input().split())))[::-1]

abs_num = abs(X - 100)
result = 100

for x in p:
  tmp_abs = abs(X - x)
  if tmp_abs <= abs_num:
    abs_num = tmp_abs
    result = x
    
print(result)

Submission status: Wrong Answer

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

if N==0:
  print(X)
else:
  P = list(map(int,input().split()))
  hash_p = [0]*102
  for i in P:
    hash_p[i] += 1
  for i in range(N):
    if hash_p[X-i]==0:
      print(X-i)
      break
    if hash_p[X+i]==0:
      print(X+i)
      break

Submission status: Wrong Answer

Solution code:
import numpy as np
#from numba import njit

def getVar():
    return map(int, input().split())
def getArray():
    return np.array(list(map(int, input().split())))

(X,N) = getVar()
p = getArray()

if (len(p) == 0):
  print(X)
else:
  subp = p - X
  i = 0
  while (True):
    if (not i in subp or not -i in subp):
      print(X + i)
      break
    i += 1

Submission status: Wrong Answer

Solution code:
import numpy as np
#from numba import njit

def getVar():
    return map(int, input().split())
def getArray():
    return np.array(list(map(int, input().split())))

(X,N) = getVar()
p = getArray()

if (len(p) == 0):
  print(X)
else:
  subp = p - X
  i = 0
  while (True):
    if (not i in subp):
      break
    i += 1
  print(X - i)

Submission status: Wrong Answer

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

mi = 101
ans=-1
for i in range(-1,101):
    if i in p:
        continue
    if abs(x-i) < mi:
        ans = i
        mi = abs(x-i)
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

else:
    p = list(map(int, input().split()))
    main = set(np.arange(101))
    main = main - set(p)

    main1 = abs(np.array(list(main)))
    idx = abs(main1 - X).argmin()
    print(main1[idx])

Submission status: Wrong Answer

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

dif = float("INF")
ans = 0

for i in range(101):
    if i not in lst:
        if dif>abs(i-x):
            dif = abs(i-x)
            ans = i
        elif dif==abs(i-x):
            ans = min(ans,i)

print(ans)

Submission status: Wrong Answer

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

dif = float("INF")
ans = 0

for i in range(1,101):
    if i not in lst:
        if dif>abs(i-x):
            dif = abs(i-x)
            ans = i
        elif dif==abs(i-x):
            ans = min(ans,i)

print(ans)

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
p = set(map(int, input().split()))
ans = -1
d = float("inf")

for i in range(100, -1, -1):
    if i in p: continue
    c = abs(x-i)
    if c <= d:
        ans = i
        d = c

print(ans)

Submission status: Wrong Answer

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

for i in range(101):
    if i in p: continue
    c = abs(x-i)
    if c < d:
        ans = i
        d = c

print(ans)

Submission status: Wrong Answer

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

try:
  p = set(map(int, input().split()))
  num = set(range(-100,201))
  mem = []

  ref = sorted(list(num - p))

  for item in ref:
    mem.append(abs(item - X))
  
  print(ref)
  print(mem)
  print(ref[mem.index(min(mem))])

except EOFError:
  print(X)

Submission status: Wrong Answer

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

try:
  p = set(map(int, input().split()))
  num = set(range(-1,201))
  mem = []

  ref = sorted(list(num - p))

  for item in ref:
    mem.append(abs(item - X))
  
  print(ref)
  print(mem)
  print(ref[mem.index(min(mem))])

except EOFError:
  print(X)

Submission status: Wrong Answer

Solution code:
def main():
	a,b = map(int,input().split())
	h = list(map(int,input().split()))
	av = 0
	i = 1
	while av == 0:
		if b ==0:
			print(a)
			break
		plus = a+i
		minus = a-i
		if minus not in h:
			print(minus)
			av = 1
		elif plus not in h:
			print(plus)
			av = 1
		else:
			i += 1


if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
import sys
x, n = map(int, input().split())
if n == 0:
    print(x)
    sys.exit()
p = [int(x) for x in input().split()]


diff = 0
while(True):
    if not x + diff in p:
        print(x+diff)
        sys.exit()

    if diff < 0:
        diff *= -1
        diff += 1
    else: # 0以上 
        diff *= -1
        diff -= 1

Submission status: Wrong Answer

Solution code:
import sys
x, n = map(int, input().split())
p = [int(x) for x in input().split()]

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

diff = 0
while(True):
    if not x + diff in p:
        print(x+diff)
        sys.exit()

    if diff < 0:
        diff *= -1
        diff += 1
    else: # 0以上 
        diff *= -1
        diff -= 1

Submission status: Wrong Answer

Solution code:
import sys
x, n = map(int, input().split())
p = [int(x) for x in input().split()]

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

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

    if diff < 0:
        diff *= -1
        diff += 1
    else:
        diff *= -1
        diff -= 1

Submission status: Wrong Answer

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

for i in range(n//2 +1):
    if x-i not in s:
        print(x-i)
        exit(0)
    if x+i not in s:
        print(x+i)
        exit(0)

Submission status: Wrong Answer

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

for i in range(1, n//2 +1):
    if x-i not in s:
        print(x-1)
        exit(0)
    if x+i not in s:
        print(x+i)
        exit(0)