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

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

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

for i in range(200):
    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:
X, N = map(int, input().split())
given_list = [int(i) for i in input().split()]

ans = 0

if N == 0:
    print(X)
else:
    for diff in range(X):
        X_plus = X + diff
        X_minus = X - diff
        # print(X_plus)
        # print
        if (X_minus in given_list) == False:
            ans = X_minus
            break
        elif (X_plus in given_list) == False:
            ans = X_plus
            break
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
X ,N = map(int,input().split())
p = list(map(int,input().split()))
min_dif = 10000
output = 10000
for i in range(201):
  if (100 - i in p) == False:
    if abs(X-(100-i)) <= min_dif:
      min_dif = abs(X-(100 - i))
      output =  100 - i
print(output)

Submission status: Wrong Answer

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

if N==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)
    if max-X> X-min:
        print(min)
    if max-X==X-min:
        print(min)

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
if n != 0:
    p = set(map(int, input().split()))
    nums = set([])
    for i in range(1, 101):
        nums.add(i)
    rest = nums.difference(p)
    minVal = 100
    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 = (int(each) for each in input().split())
if n == 0:
    print(x)
else:
    p = [int(each) for each in input().split()]
    candidate = 0
    for i in range(101):
        if i not in p and abs(i-x) < abs(candidate-x):
            candidate = i
            # print('replaced')
    print(candidate)

Submission status: Wrong Answer

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

m=100
a=x
for i in range(-1,101):
    if i not in p:
        z=abs(i-x)
        if m>z:
            m=z
            a=i

print(a)

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
if (N == 0):
  print(X)
else:
  nums = list(map(int, input().split()))
    
  nums.sort()
  low = nums[0]
  high = nums[-1]
  minDiff = 100000000
  minNum = -1
  for i in range(1, 101):
    if i in nums:
      continue
    else:
      Dif = abs(X-i)
    if (Dif < minDiff):
      minDiff = Dif
      minNum=i
  print(minNum)

Submission status: Wrong Answer

Solution code:
import math
X, N = map(int, input().split())
p_list = list(map(int, input().split()))

if N == 0:
    print(X)
else:
    for i in range(1,100):
        if not X-i in p_list:
            print(X-i)
            break
        elif not X+i in p_list:
            print(X+i)
            break

Submission status: Wrong Answer

Solution code:
X,N = map(int, input().split())
P = list(map(int, input().split()))
maxP = 0 if P == [] else max(P)
INF = 1000
A = [0] * 100
for p in P:
  A[p-1] = INF
for k in range(maxP):
  if A[k] == 0:
    A[k] = abs(X - k - 1)
mi = INF
index = 0 if X in P else X
for k in range(maxP):
  if mi > A[k]:
    mi = A[k]
    index = k+1
print(index)

Submission status: Wrong Answer

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

c = collections.Counter(list)
res1=-1000
res2=-1000

for i in range (0, 100):
  if(c[X+i]==0):
    res1=X+i
    if(c[X-i]==0):
      res2=X-i
    break

if(abs(N-res1)<=abs(N-res2)):
  print(res1)
else:
  print(res2)

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
ps=list(map(int,input().split()))
c=1
while True:
    if not x-c in ps:
        print(x-c)
        exit()
    elif not x+c in ps:
        print(x+c)
        exit()
    c+=1

Submission status: Wrong Answer

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

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

exact=x
ansmin=x-1
ansmax=x+1

for i in range(n):
	if p[i]==exact:
		exact=200
#	if p[i]==ansmin:
#		ansmin-=1
	if p[i]==ansmax:
		ansmax+=1
		
p.sort(reverse=True)
#for i in range(n-1,0,-1):
for i in range(n):
	if p[i]==ansmin:
		ansmin-=1
	
#print(ansmin,exact,ansmax)
	
if exact==x:
	print(exact)
if abs(ansmax-x)<abs(ansmin-x):
	print(ansmax)
else:
	print(ansmin)

Submission status: Wrong Answer

Solution code:
x, n = input().split()
x = int(x)
n = int(n)
m = list(map(int,input().split()))
sa = 999
ans = 0

if x in m == False:
    print(x)
    exit()
elif len(m) == 0:
    print(x)
    exit()

for k in range(1,n):
    if m.count((x - k)) == 0 and x - (x - k) < sa:
        sa =  x - (x - k)
        ans = x - k

for l in range(1,100):
    if m.count((x + l)) == 0 and (x+l) - x < sa:
        sa = (x+l) - x
        ans = x + l

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()))
  q=[i-X for i in p]
  qs=set(q)
  print(q)

  for i in range(N):
    if -i not in qs:
      print(X-i)
      break
    elif i not in qs:
      print(X+i)
      break

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
p = list(map(int, input().split()))
if N==0:
	p = [0]
pmax = max(p)
pmin = min(p)

sa = 0
a = 0
for i in range(pmin, pmax):
	n = abs(i-X)
	if a==0 or n<sa:
		if not(i in p):
			sa = n
	if a==0 and sa == 0:
		a = 1
		sa = pmax

b = X-sa
if b in p:
	b = X+sa
print(b)

Submission status: Wrong Answer

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


l = [0]*100

for i in range(N):
  l[abs(p[i] - X)] += 1

#print(p.index(9))
if N == 0:
  print(X)
else:
  for i in range(N):
    if i == 0:
      if l[0] == 1:
        continue
      else:
        print(X)
        break
    else:
      if l[i] == 0:
        print(X-i)
        break
      elif l[i] == 1:
        try:
          p_index = p.index(X-i)
          print(X+i)
        except:
          print(X-i)
        break

Submission status: Wrong Answer

Solution code:
import numpy as np
import itertools

x,n = map(int,input().split())
li = list(map(int,input().split()))
li.sort()
if x in li:
    idx = li.index(x)
    i = 0
    while(1):
        i = i+1
        if(idx-i<0):
            print(0)
            break
        if(idx+i>=len(li)):
            print(x+i)
            break
        if(li[idx-i]!=x-i):
            print(x-i)
            break
        elif(li[idx+i]!=x+i):
            print(x+i)
            break
else:
    print(x)

Submission status: Wrong Answer

Solution code:
n = input().split()
X = int(n[0])
N = int(n[1])

try:
    n2 = input()
except:
    pass

if N == 0:
    print(X)

else:
    n2 = n2.split()
    p = [int(item) for item in n2]

    for i in range(101):
        if i == 0:
            if X not in p:
                print(X)
        tmp = []

        if (X + i not in p ):
            tmp.append(X + i)

        if (X - i not in p ):
            tmp.append(X - i)
    
        if len(tmp)!=0:
            print(min(tmp))
            break

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = 0

big_x = x
sml_x = x

for i in range(n // 2 + 1):
    
    if sml_x not in p_lst:
        ans = sml_x
        # print("0")
        break
    elif big_x not in p_lst:
        ans = big_x
        # print("1")
        break
    # else:
    #     continue
    big_x += 1
    sml_x -= 1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
li1 = []
li2 = []

if n == 0:
    print(x)
else:
    p = list(map(int, input().split()))
    for i in range(max(p)):
        if i not in p:
            li1.append(i)

#print(li1)

    for j in li1:
        li2.append(abs(x - j))

    print(li1[li2.index(min(li2))])

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()
  p1 = {i for i in range(p[-1])}
  p = set(p)
  p2 = p1 - p
  p2 = list(p2)
  absv = x
  for i in range(len(p2)):
    if absv > abs(x - p2[i]):
      absv = abs(x - p2[i])
  print(x - absv)

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys
X, N = np.array(list(map(int, input().split())))
if N == 0:
    print(X)
    sys.exit()
p = np.array(list(map(int, input().split())))
p = np.sort(p)
a = np.ones(101, dtype = np.int)
a[p] = 0
m = X
n = 0
for i in range(1, 100):
    if a[i] == 1:
        if m>abs(i-X):
            if i-X != 0:
                m = abs(i-X)
                n = i
print(n)

Submission status: Wrong Answer

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

p.sort()
index = 0
for i in range(n):
    if p[i] == x:
        index = i

prev = x
right = x
left = x
for i in p[index + 1:]:
    if i != prev + 1:
        right = prev + 1
    prev = i

for i in reversed(p[: index]):
    if i != prev - 1:
        left = prev - 1
    prev = i

if n != 0:
    if index == n - 1:
        right = p[index] + 1
    elif index == 0:
        left = p[index] - 1

print(min(left, right))

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

#print(valid)

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

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 = X
  Flag =True
  for k in range(N):
    if List[k] == X:
      Flag = False
  if Flag:
    print(res,Flag)
  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 = map(int, input().split())
p = set(map(int, input().split()))

num_set = set(range(-101, 101))

ans_list = list(num_set - p)
min_diff = None
min_ans = None
for ans in reversed(ans_list):
    diff = abs(ans - X)
    if min_diff is None or diff <= min_diff:
        min_diff = diff
        min_ans = ans

print(min_ans)

Submission status: Wrong Answer

Solution code:
X,N=map(int, input().split())
A = list(map(int, input().split()))
def p(i):
    return i+1
def m(i):
    return i-1
if not X in A:
    print(X)
else:
    pl=p(X)
    mi=m(X)
    for _ in range(100):
        if not mi in A:
            if mi>=0:
                print(mi)
                break
        else:
            mi = m(mi)
        if not pl in A:
            if pl<101:
                print(pl)
                break
        else:
            pl = p(pl)

Submission status: Wrong Answer

Solution code:
def main():
    x, n = map(int, input().split())
    p = list(map(int, input().split()))
    if p != []:
        for i in range(1, 100):
            if not x-i in p and x-i >= 0:
                print(x-i)
                break
            else:
                if not x+i in p and x+i <= 100:
                    print(x+i)
                    break
    else:
        print(x)



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)
    exit()
if x not in p:
    print(x)
    exit()
dif = 2**60
ans = 2**60
for u in range(101):
    if u in p:
        continue
    else:
        tmp = abs(x-u)
        if tmp < dif:
            dif = tmp
            ans = u
for a in range(1,101):
    if a+x == dif:
        ans = -a
        break
print(ans)

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
P =  set(map(int, input().split()))
Nums = set(range(0, 100))
Nums = Nums - P
sorted(Nums)


minNum = 99999
minIndex = 0
for n in Nums:
    if minNum == abs(X-n):
        break
    if abs(X - n)< minNum:
        minNum = abs(X-n)
        minIndex = n

print(minIndex)

Submission status: Wrong Answer

Solution code:
X,N=map(int,input().split())
L=list(map(int,input().split()))
ans=10000
for i in range(1,100):
    if X-i in L:
        pass
    else:
        ans=X-i
        break
    if X+i in L:
        pass
    else:
        ans=X+i
        break
if N==0:
    ans=X
print(ans)

Submission status: Wrong Answer

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

candidates = list(map(lambda elm: (abs(x - elm), elm), range(101)))
for p_i in p:
    candidates[p_i] = (10000, p_i)

sorted_candidates = sorted(candidates, key=lambda elm: elm[0])
min_val = sorted_candidates[0][0]
res = []
for candidate in sorted_candidates:
    if min_val == candidate[0]:
        res.append(candidate[1])
print(sorted(res)[0])

Submission status: Wrong Answer

Solution code:
import math

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

if n == 0:
    print(x)

else:
    p = list(map(int, input().split()))
    ans = []

    for i in range(x+1, 102):
        if i not in p:
            ans.append(i)
            break

    for i in range(x-1, -1, -1):
        if i not in p:
            ans.append(i)
            break

    if abs(x-ans[0]) < abs(x-ans[1]):
        print(ans[0])
    elif abs(x-ans[0]) == abs(x-ans[1]):
        print(min(ans))
    else:
        print(ans[1])

Submission status: Wrong Answer

Solution code:
import sys
x,n=map(int,input().split())
p=list(map(int,input().split()))
if n==0:
    print(x)
    sys.exit()
for i in range(1,101):
    ans=x-i
    if ans<=0:
        if not ans in p:
            print(ans)
            sys.exit()
        else:
            continue
    if not ans in p:
        print(ans)
        sys.exit()
    an=x+i
    if not an in p:
        print(an)
        sys.exit()

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
# 0または最大値を入れておく
if(abs(X-0) < abs(X-V_RANGE)):
	ans_i = 0
else:
	ans_i = V_RANGE-1

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 = list(map(int, input().split()))
if(N == 0):
  print(X)
  exit()
p = list(map(int, input().split()))
a = [num for num in range(1, 101)]
diff = list(set(a) - set(p))
diff.sort(reverse=True)
ans = 10**10
for i in diff:
  if(abs(ans - X) >= abs(i - X)):
    ans = i
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
X ,N = map(int,input().split())
p = list(map(int,input().split()))
min_dif = 10000
output = 10000
kari = 10000
for i in range(200):
  if (100 - i in p) == False:
    if abs(X-(100-i)) <= min_dif:
      min_dif = abs(X-(100 - i))
      output =  100 - i
print(output)

Submission status: Wrong Answer

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

diff = 1000
for i in range(-100, 110):
    if i in p:
        continue
    if abs(i - x) < diff:
        diff = abs(i - x)
        print(diff)
        ans = i

print(ans)

Submission status: Wrong Answer

Solution code:
d = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]

int_x = int(d[0])
int_n = int(d[1])




ans = 100000
tmp = abs(int_x - ans)
for i in range(101):
  if tmp > abs(int_x - i):
    if not i in p:
      ans = i
      tmp = abs(int_x - ans)

if len(p) == 0:
  ans = int_x

print(ans)

Submission status: Wrong Answer

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

if N!=0:

	P=sorted(list(map(int, input().split())))
	pabs=[]
	for p in P:
		pabs.append(abs(X-p))
	
	pabs.sort()
	
	
	cnt=0
	temp=0
	
	
	if 0 in pabs:
		for i in range(1,max(pabs)):
			
			if i in pabs:
				
				if pabs.count(i)==1:
					if X-i not in P:
						print(X-i)
						break
					else:
						print(X+i)
						break
					
				else:
					continue
				
			else:
				print(X-1)
				break
										
	else:
		print(X)
		
else:
	print(X)

Submission status: Wrong Answer

Solution code:
# coding:utf-8


def main():
    X, N = map(int, input().split())
    if (N > 0):
        P = list(map(int, input().split()))
        ans = X
        temp = X
        for pi in range(0, 102):
            n = abs(pi - X)
            if n < temp and pi != X and not pi in P:
                ans = pi
                temp = n
            elif n == temp and pi != X and not pi in P and pi < ans:
                ans = pi
                temp = n

        print(ans)

    else:
        print(X)


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)


for i in range(100):
    if (X-(i+1)) and (X+i+1) in p:
        continue
    
    elif (X-i-1) not in p:
        print(X-i-1)
        break
    
    elif (X+i+1) not in p:
        print(X+i+1)
        break

Submission status: Wrong Answer

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

x, n = list(map(int  , input().split()))
if n ==0  :
    arr = list(map(int ,input().split()))
    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+1):
            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 = map(int, input().split())

int_set = set(list(range(1,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:
x, n = map(int, input().split())
if n == 0:
    print(x)
    exit()

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

for i in range(1, 100):
    i1 = x - i
    i2 = x + i
    if i1 not in p:
        print(i1)
        break
    elif i2 not in p:
        print(i2)
        break
    else:
        continue

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
P =  set(map(int, input().split()))
Nums = set(range(0, 101))
Nums = Nums - P
sorted(Nums)


minNum = 99999
minIndex = 0
for n in Nums:
    if minNum == abs(X-n):
        break
    if abs(X - n)< minNum:
        minNum = abs(X-n)
        minIndex = n

print(minIndex)

Submission status: Wrong Answer

Solution code:
[_x, _n] = list(map(int, input().split(" ")))
if _n == 0:
  print(_x)
else:
  _list = list(map(int, input().split(" ")))
  _answer = 0
  _flag = False

  if _x not in _list or _n == 0:
    _answer = _x
    _flag = True
  else:
    for _i in range(_n):
      if _i / 2 == 0:
        if _x - _i//2 - 1 not in _list and _flag == False:
          _answer = _x - _i//2 - 1
          _flag = True
      else:
        if _x + _i//2 + 1 not in _list and _flag == False:
          _answer = _x + _i//2 + 1
          _flag = True
  print(_answer)

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

table = [0 for i in range(100)]
for i in p:
    table[i-1] = 1

mx = 10000
ans = mx
dis = mx
for i in range(len(table)):
    idx = 99-i
    if (table[idx] == 0) and (dis >= abs(idx+1-x)):
        ans = idx+1
        dis = abs(idx+1-x)
if ans == mx:
    print(0)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
from math import *
from bisect import bisect_left

def cin(): # To take limited number of inputs
    return map(int,input().split())

def cins(): # To take space sepreated strings
    return input.split()

def cino(test=False): # To take individual int input (test = False)
    if not test:
        return int(input())
    else: # To take string input (test = True)
        return input()

def cina(): # array input
  return list(map(int,input().split()))

def ssplit(): # multiple string input
    return list(input().split())

def printlist(l): # To print space seperated array
    for i in l:
        print(i,end=" ")

def bs(arr, l, r, x): 
  
    while l <= r: 
  
        mid = l + (r - l) // 2; 
          
        # Check if x is present at mid 
        if arr[mid] == x: 
            return mid 
  
        # If x is greater, ignore left half 
        elif arr[mid] < x: 
            l = mid + 1
  
        # If x is smaller, ignore right half 
        else: 
            r = mid - 1
      
    # If we reach here, then the element 
    # was not present 
    return -1


def main():
    a,b = cin()
    # print(a,b)
    if b==0:
        print(a)
    else:
        # print("hey")
        arr = cina()
        arr.sort()
        init = 1
        # print(bs(arr,0,b-1,a))
        if bs(arr,0,b-1,a)==-1:
            print(b)
        else:
            # print("hey")
            o,t = bs(arr,0,b-1,a-init),bs(arr,0,b-1,a+init)
            # print(o,t)
            while o!=-1 and t!=-1:
                init+=1
                o,t = bs(arr,0,b-1,a-init),bs(arr,0,b-1,a+init)
            if o==-1:
                print(a-init)
            else:
                print(a+init)




if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def i():
	return int(input())
def i2():
	return map(int,input().split())
def s():
	return str(input())
def l():
	return list(input())
def intl():
	return list(int(k) for k in input().split())

x,n = i2()
p = intl()

m = 100
ls = [int(i) for i in range(-100,101)]
for i in range(n):
	ls.remove(p[i])
for j in range(len(ls)):
	if abs(x - ls[j]) < m :
		m = abs(x - ls[j])
		ans = ls[j]
print(ans)

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
X, N = list(map(int, input().split()))
if N != 0:
    P = list(map(int, input().split()))
    ans = 0
    L = X
    H = X
    for _ in range(N // 2 + 1):
        L = L - 1
        H = H + 1
        if L not in P:
            print(L)
            break
        if H not in P:
            print(H)
            break
else:
    print(X)

Submission status: Wrong Answer

Solution code:
#C
X,N = map(int,input().split())
p = list(map(int,input().split()))
r = 100
for i in range(100,-1,-1):
    if i in p:
        pass
    else:
        if abs(r-X) >= abs(i-X):
            r = i
        else:
            pass
print(r)

Submission status: Wrong Answer

Solution code:
import numpy as np

a = input()
a, b = a.split()
a = int(a)
if int(b) == 0:
  print(a)
  exit()
n = input()
n = [int(i) for i in n.split()]
li = list(range(-101, 101))
print(li)
for i in n:
  li.remove(i)
mini = [np.inf, 0]
for i in li:
  if abs(i - a) == mini[0]:
    if i < mini[1]:
      mini = [abs(i - a), i]
  elif abs(i - a) < mini[0]:
    mini = [abs(i - a), i]
print(mini[1])

Submission status: Wrong Answer

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

def check(x,n):
    if int(n) == 0:
        print(x)
        return

    p_list = input().split()

    x = int(x)
    n = int(n)

    # 差数を１ずつ上昇させていってみる
    for i in range(1, 50):
        min_x = str(x - int(i))
        max_x = str(x + int(i))

        # この二つのうちのどちらかがp＿listに含まれるかを求める
        if min_x in p_list and max_x in p_list:
            continue
        else:
            if min_x not in p_list:
                print(min_x)
                return
            
            if max_x not in p_list:
                print(max_x)
                return

check(x,n)

Submission status: Wrong Answer

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

ps = list(map(int, input().split()))
if not x in ps:
    print(x)
    quit()

min_near = 0
big_near = 0

m = x
while min_near == 0:
    m -= 1
    if not m in ps:
        min_near = m

b = x
while big_near == 0:
    b += 1
    if not b in ps:
        big_near = b


min_diff = x - min_near
big_diff = big_near - x

if (min_diff > big_diff):
    # big_diffの方が差が小さければbig_near
    print(big_near)
else:
    # それ以外はmin_near
    print(min_near)

Submission status: Wrong Answer

Solution code:
# coding:utf-8


def main():
    X, N = map(int, input().split())
    if (N > 0):
        P = list(map(int, input().split()))
        ans = X
        temp = X
        for pi in range(0, 101):
            n = abs(pi - X)
            if n < temp and pi != X and not pi in P:
                ans = pi
                temp = n
            elif n == temp and pi != X and not pi in P and pi < ans:
                ans = pi
                temp = n

        print(ans)

    else:
        print(X)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import bisect as bs

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

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

nums = list(map(int,input().split()))
nums2 = [False]*101
# print(nums)
for p in nums:
    nums2[p] = True

for i in range(102):
    # print(x-i,x+i)
    if x - i < 1:
        print(0)
        exit(0)
    elif x + i > 100:
        print(101)
        exit(0)
    elif nums2[x-i]==False:
        print(x-i)
        exit(0)
    elif nums2[x+i]==False:
        print(x+i)
        exit(0)

Submission status: Wrong Answer

Solution code:
def main():
    x,y = list(map(int, input().split()))

    if y == 0:
        print(x)
        exit()
    nums = list(map(int, input().split()))
    ans = 101
    for i in range(1, 101):
        if i not in nums:
            ans = ans if abs(ans-x) <= abs(i-x) else i
    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()
mi=100000000000000
for i in range(1,100):
  if(i in P):
    continue
  mi=min(abs(X-i),mi)
  if(i>X):
    break 
co=X-mi
co2=X+mi
if(X-mi in P):
  print(co2)
else:
  print(co)

Submission status: Wrong Answer

Solution code:
X,N = map(int,input().split())
p = list(map(int, input().split()))
num=list(range(-100,101))
for i in range(N):
    num.remove(p[i])
min_=210
for i in range(len(num)):
    s=abs(X-num[i])
    if s<min_:
        min_=s
        min_list=[num[i]]
    elif s==min_:
        min_list.append(num[i])
print(min(min_list))

Submission status: Wrong Answer

Solution code:
import sys


def int1(x): return int(x) - 1
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def mi1(): return map(int1, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def lli(rows_number): return [li() for _ in range(rows_number)]


if __name__ == "__main__":
    x, n = mi()
    if n == 0:
        print(x)
        exit()
    p_l = li()
    a = list(range(1, 101))
    for p in p_l:
        a.remove(p)
    ans = 0
    min_dif = 10000
    for i in a:
        dif = abs(i-x)
        if dif < min_dif:
            min_dif = dif
            ans = i
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline


def main():
    X, N = list(map(int, input().split(" ")))
    if N==0:
        print(X)
        exit(0)
    arr = list(map(int, input().split(" ")))
    if X not in arr:
        print(X)

    arr.sort()
    for i in range(len(arr)):
        if arr[i] >= X:
            diff = 1
            while True:
                if X - diff not in arr:
                    print(X-diff)
                    exit(0)
                if X + diff not in arr:
                    print(X+diff)
                    exit(0)
                diff +=1


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#H, W = map(int,input().split())
#N = int(input())
#al = list(map(int,input().split()))
X, N = map(int,input().split())
pl = list(map(int,input().split()))

lst = [i for i in range(-100,101)]

anslst = []
for n in lst:
    if not n in pl:
        anslst.append(n)


an = 101
idx = 0
for i in range(len(anslst)):
    tmp = abs(X - anslst[i])
    if tmp < an:
        an = tmp
        idx = i


ans = anslst[idx]
print(ans)