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: Accepted

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

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


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

Submission status: Accepted

Solution code:
import numpy as np
import sys
x,N = map(int, input().split())

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

abs_list = []

for p in P:
  abs_list.append(np.abs(x-p))
  
if len(abs_list) == 0:
  print(x)
  sys.exit()
   
abs_max = max(abs_list)
for i in range(100):
  if abs_list.count(i) == 0:
    print(x-i)
    sys.exit()
  elif abs_list.count(i) == 1 and x+i in P and i !=0:
    print(x-i)
    sys.exit()
  elif abs_list.count(i) == 1 and x-i in P and i != 0:
    print(x+i)
    sys.exit()

Submission status: Accepted

Solution code:
from sys import stdin
X, N = [int(x) for x in stdin.readline().rstrip().split()]
p = [int(x) for x in stdin.readline().rstrip().split()]

ans = 10000
ans_diff = 10000

list_100 = [0] * 100
for i in range(100):
  list_100[i] = i+1
  
list_100.append(0)
list_100.append(-1)
list_100.append(101)
  
live_list = list(set(list_100) - set(p))

for i in live_list:
  diff = abs(X - i)
  if diff < ans_diff:
    ans = i
    ans_diff = diff
  if diff == ans_diff:
    ans = min(ans, i)
 
print(ans)

Submission status: Accepted

Solution code:
xn = list(map(int, input().split()))
x = xn[0]
n = xn[1]
can = True
try:
    p = list(map(int, input().split()))
except:
    can = False

if can:
    num = []
    for i in range(0, 102): # x roop
        cnt1 = 0
        cnt2 = 0
        for j in range(n): # n roop
            if x-i==p[j]:
                cnt1 += 1
            else:
                pass

            if x+i==p[j]:
                cnt2 += 1
            else:
                pass

        if cnt1==0 and cnt2==0:
            num.append(x-i)
        elif cnt1==0:
            num.append(x-i)
        elif cnt2==0:
            num.append(x+i)
        else:
            pass

    min_abs = []
    for i in range(len(num)):
        min_abs.append([abs(x-num[i]), num[i]])

    min_abs.sort(key=lambda x: x[0])
    print(min_abs[0][1])
else:
    print(x)

Submission status: Accepted

Solution code:
def main():
    x, n = [int(v) for v in input().split(' ')]
    if n == 0:
        print(int(x))
        return

    lst_p = [int(v) for v in input().split(' ')]
    lst_p.sort()

    if lst_p[-1] < x:
        print(int(0))
        return

    # add dummy value
    lst_p.append(lst_p[-1] + 2)

    d = x
    ans = 0
    continueous_n = 1
    for p in lst_p:
        if p == continueous_n:
            continueous_n = p + 1
            continue
        for i in range(p - continueous_n):
            tmp = abs(x - (continueous_n + i))
            if tmp < d:
                d = tmp
                ans = continueous_n + i
            else:
                print(int(ans))
                return
        continueous_n = p + 1
    print(int(ans))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def find_num(lst, value):
    return [i for i, x in enumerate(lst) if x == value]

def resolve():
    X,N = map(int,input().split())
    if N == 0:
        print(X)
    else:
        p = list(map(int,input().split()))
        p.sort()
        idx = find_num(p,X)
        if idx == []:
            print(X)
        else:
            for i in range(1,100):
                if p[idx[0] - i ] != X - i or idx[0] - i == -1:
                    print(X-i)
                    break
                if idx[0] + i == N:
                    print(X+i)
                    break
                elif p[idx[0] + i ] != X + i:
                    print(X+i)
                    break
resolve()

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
result = x
for i in range(10000):
    a, b = x + i, x - i
    if b not in p:
        result = b
        break
    if a not in p:
        result = a
        break
print(result)

Submission status: Accepted

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

if len(p) == 0:
    print(X)
    exit()

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

small = [i for i in range(-101, X)]
big = [i for i in range(X+1, 102)]
small.reverse()
for i in range(max(len(big),len(small))):
    if not small[i] in p:
        print(small[i])
        exit()
    elif not big[i] in p:
        print(big[i])
        exit()

Submission status: Accepted

Solution code:
X,N=map(int,input().split())
P=list(map(int,input().split()))
P.sort()
#print(P)
def abs(a,b):
    if(a>b):
        ans=a-b
    else:
        ans=b-a

    return ans
h=100
for i in range(102):
    if(i not in P):
        if(h>abs(X,i)):
            h=abs(X,i)
            ans=i
            #print(i)
            #print(h)
print(ans)

Submission status: Accepted

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, 110):
    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: Accepted

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

if N==0:
    print(X)
    exit()

p = list(map(int,input().split()))
q = [i for i in range(-1000,1000)]
li = set(p) ^ set(q)
tmp = 0
ans = 0
while(1):
    if X-tmp in li:
        ans = X-tmp
        break
    elif X+tmp in li:
        ans = X+tmp
        break
    tmp += 1
print(ans)

Submission status: Accepted

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(210):
        j = i - 105
        if j not in p and abs(j-x) < abs(candidate-x):
            candidate = j
            # print('replaced')
    print(candidate)

Submission status: Accepted

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

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

Submission status: Accepted

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

pp=x
pm=x
while (pp in l) and (pm in l):
    pp=pp+1
    pm=pm-1

if (not pp in l) and (not pm in l):
    print(min(pp, pm))
elif pp in l:
    print(pm)
else:
    print(pp)

Submission status: Accepted

Solution code:
x,n = map(int, input().split())
if n ==0:
    print(x)
else:
    l = list(map(int, input().split())) 
    for i in range(0,52):
        if x-i not in l:
            print(x-i)
            break
        elif x+i not in l:
            print(x+i)
            break

Submission status: Accepted

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

L = list(range(0,102))
if y != 0:
    L2 = list(map(int,input().split()))
    
    #print(L)
    for i in range(len(L2)):
        L.remove(L2[i])
        
#print(L)
#L = sorted(L)

#print(L)

t = len(L)//2

for j in range(len(L)):
#    print(t,L[t])
    if L[t] >= x:
#        print("L[t] >= x")
        if t == 0:
            print(L[t])
            break
        elif L[t-1] <= x:
            if abs(L[t]-x) < abs(L[t-1]-x):
                print(L[t])
                break
            else:
                print(L[t-1])
                break
        
        t = t//2
    else:
        if t == y-1:
            print(L[t])
            break
        elif L[t+1] >= x:
            if abs(L[t]-x) > abs(L[t+1]-x):
                print(L[t+1])
                break
            else:
                print(L[t])
                break
        t = t + (len(L)-t)//2

Submission status: Accepted

Solution code:
X,N=map(int,input().split())
if N>0:
    p=list(map(int,input().split()))
else:
    print(X)
    exit()
if X not in p:
    print(X)
    exit()
Y=X
Z=X
s=0
t=0
while s==0:
    Y+=1
    if Y not in p:
        break
while t==0:
    Z-=1
    if Z not in p:
        break
if abs(X-Y)<abs(X-Z):
    print(Y)
elif abs(X-Y)>abs(X-Z):
    print(Z)    
else:
    print(Z)

Submission status: Accepted

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

Submission status: Accepted

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


tar1 = x
tar2 = x
ff1 = True
ff2 = True

while True:
    if (ff1 is True):
        tar1 -= 1
        if (tar1 not in a):
            print(tar1)
            exit()

    if (ff2 is True):
        tar2 += 1
        if (tar2 not in a):
            print(tar2)
            exit()
 

    if ((ff1 is False) and (ff2 is False)):
        break

Submission status: Accepted

Solution code:
import numpy as np

X, N = (int(x) for x in input().split())
if N == 0:
    print(X)
else:
    p = np.array([int(x) for x in input().split()])
    x_arange = set(np.arange(-100, 101))
    p_x = set(np.array(p - X))
    sub_list = list(x_arange - p_x)
    sub_abs_list = np.abs(np.array(sub_list))

    min_sub = min(sub_abs_list)
    if (X - min_sub) not in p:
        print(X - min_sub)
    else:
        print(X + min_sub)

Submission status: Accepted

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

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

Submission status: Accepted

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

X_max = X
X_min = X

while True:
    if N == 0 or (X in p) == False:
        print(X)
        break
        break
    X_max += 1
    X_min -= 1
    if (X_min in p) == False:
        print(X_min)
        break
        break
    if (X_max in p) == False:
        print(X_max)
        break
        break

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
#8:47
MOD=10**9+7
INT_MAX=10**20+7
def INPUT():return list(int(i) for i in input().split())
def LIST_1D_ARRAY(n):return [0 for _ in range(n)]
def LIST_2D_ARRAY(m,n):return [[0 for _ in range(n)]for _ in range(m)]
#################################################################################
x,n=INPUT()
A=INPUT()
if x not in A:
    print(x)
else:
    for d in range(1,102):
        if x-d not in A:
            print(x-d)
            break
        elif x+d not in A:
            print(x+d)
            break

Submission status: Accepted

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)
        ans = i

print(ans)

Submission status: Accepted

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

for i in range(100):
    if not str(x-i) in n_list:
        print(x-i)
        break
    elif not str(x+i) in n_list:
        print(x+i)
        break

Submission status: Accepted

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

P = list(map(int, input().split()))
if N==1:
    if X!=P[0]:
        print(X)
        sys.exit()
    if X==P[0]:
        print(X-1)
        sys.exit()
PP=sorted(P, reverse=True)
sab=abs(X-P[0])
#print(PP[0])
for i in range(N):
    if PP.count(X-i)==0 :
        print(X-i)
        sys.exit()
    if PP.count(X+i)==0:
        
        print(X+i)
        sys.exit()

Submission status: Accepted

Solution code:
X,N = map(int,input().split())
P = list(map(int,input().split()))
num = sorted([[abs(X - i),i] for i in range(-200,200) if i not in P],key = lambda x: x[0])

inf = 10 ** 3
inf2 = 10 ** 3 * -1

for i in range(X,inf):
  if i in P:
    continue
  plus = abs(X - i)
  break

for j in range(X,inf * -1,-1):
  if j in P:
    continue
  minus = abs(X - j)
  break

if plus < minus:
  print(i)

else:
  print(j)

Submission status: Accepted

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

u = [i for i in p if i >= x]
if len(u) == 0:
    u = [x]

l = [i for i in p if i <= x]
if len(l) == 0:
    l = [x]

if len(p)==0:
    print(x)
else:
    for i in range(x,max(u)+2):
        if i not in u:
            um = i
            break
        else:
            continue       
    for i in range(x,min(l)-2,-1):
        if i not in l:
            lm = i
            break
        else:
            continue   
    if abs(x-um) == abs(x-lm):
        print(lm)
    else:
        uu = abs(um - x)
        ll = abs(lm - x)
        if uu > ll:
            print(lm)
        else:
            print(um)

Submission status: Accepted

Solution code:
x,n = map(int, input().split())
l = list(map(int, input().split()))
l_dis = [num - x for num in l]

def s_func(x):
    if x < 0:
        return abs(x) - 0.5
    else:
        return abs(x)
    
l_dis = sorted(l_dis, key=s_func)
if len(l_dis)==0:
    print(x)
elif l_dis[0] != 0:
    print(x)
else:
    i = 1
    j = 1
    b = -1
    while True:
        if i > len(l_dis)-1 or l_dis[i] != j*b:
            print(x + j*b)
            break
        i += 1
        b *= -1
        if i > len(l_dis)-1 or l_dis[i] != j*b:
            print(x + j*b)
            break
        i += 1
        b *= -1
        j += 1

Submission status: Accepted

Solution code:

def resolve():
    X, N = map(int, input().split())
    if N == 0:
        print(X)
        return
    A = set(map(int, input().split()))
    dic = {}
    for i in range(-10, 110):
        if i not in A:
            dic[i] = abs(X-i)

    sorted_A = sorted(dic.items(), key=lambda x:(x[1], x[0]))
    print(sorted_A[0][0])

if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

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

for i in range(1, 100):
    if x - i not in P:
        dif_mis = x-i
        break

for i in range(0, 100):
    if x + i not in P:
        dif_pls = x+i
        break

if (x-dif_mis)**2 > (x-dif_pls)**2:
    print(dif_pls)
else:
    print(dif_mis)

Submission status: Accepted

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 and nums2[x-i]==True:
        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: Accepted

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

if n == 0:
  print(x)
  exit(0)
  
p = [int(x) for x in input().split()]

a = x
b = x

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

for i in range(1,101):
  a = a + 1
  b = b - 1
  if b not in p:
    print(b)
    exit(0)
  elif a not in p:
    print(a)
    exit(0)

Submission status: Accepted

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

def check():
    for i in range(105):
        if not((X - i) in p):
            return X - i
        if not((X + i) in p):
            return X + i

print(check())

Submission status: Accepted

Solution code:
import numpy as np

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

    p.sort()
    q = p
    ans = list(map(lambda _: abs(_ - x), q))
    
    cnt = 0
    while cnt <= 101:
        if ans.count(cnt) == 2 and cnt != 0:
            pass
        elif ans.count(cnt) == 1 and cnt == 0:
            pass
        else:
            if (x - cnt) in p:
                return x + cnt
            else:
                return x - cnt

        cnt += 1   


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

Submission status: Accepted

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

    min = 1000

    for i in range(-50, 150):

        if i in p:
            continue

        elif min > abs(x - i):
            result = i
            min = abs(x - i)

    print(result)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

diff = [200, 0]


for i in range(-1, 102): # 1~100
    if i not in p_list:
        new_diff = abs(i - X)
        if new_diff < diff[0]:
            diff[0] = new_diff
            diff[1] = i

print(diff[1])

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
l=list(map(int,input().split()))
loop = True
j = 0
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: Accepted

Solution code:
import sys
import numpy as np
x, n = map(int, input().split())
if n == 0:
    print(x)
    sys.exit()
p = np.array([int(i) for i in input().split()])
a = abs(p - x)
for i in range(101):
    if i == 0 and x not in p:
        print(x)
        break
    if x - i not in p:
        print(x - i)
        break
    elif x + i not in p:
        print(x + i)
        break

Submission status: Accepted

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 + 1):
    if not (x - i) in p:
      print(x - i)
      break
    elif not (x + i) in p:
      print(x + i)
      break

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
if n == 0:
  print(x)
else:
  p = list(map(int,input().split()))
  dic = {}
  ans = 0
  for i in range(n):
    dic[p[i]] = abs(x-p[i])
  i = 1
  while ans==0:
    if not x in dic:
      print(x)
      break
    elif (not x+i in dic) and (not abs(x-i) in dic):
      print(x-i)
      break
    elif not abs(x-i) in dic:
      print(x-i)
      break
    elif not x+i in dic:
      print(x+i)
      break
    else:
      i += 1

Submission status: Accepted

Solution code:
XN = input().split()
P = input().split()
X = int(XN[0])
N = int(XN[1])
pi = [int(a) for a in P]
if N == 0:
    print(X)
    exit()
i = 0
while True:
    koho1 = X + i
    koho2 = X - i
    if not koho2 in pi:
        print(koho2)
        break
    elif not koho1 in pi:
        print(koho1)
        break
    else:
        i = i + 1
        continue

Submission status: Accepted

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

	if n==0:
		print(x)
		return

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


	dic = {}
	for i in arr:
		dic[i]=1

	res = -300

	for i in range(n+1):
		if x-i not in dic:
			res = x-i
			break
		elif x+i not in dic:
			res = x+i
			break
	if res==-300:
		print(x-n)
	else:
		print(res)


if __name__ == "__main__":
	solve()

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
if N == 0:
    print(X)
    quit()
p = set(map(int, input().split()))
not_p = sorted(set(range(0, 102)) - p)
ans = 0
minval = 101
for i in not_p:
    if minval > abs(X - i):
        minval = abs(X - i)
        ans = i
print(ans)

Submission status: Accepted

Solution code:
def main():
    x, n = map(int,input().split())
    li = list(map(int,input().split()))
    li2 = []
    ans = 0
    for i in range(102):
        check = True
        for j in li:
            if j == i:
                check = False
        if check:
            li2.append(i)
    for i in li2:
        if abs(ans - x) > abs(i - x):
            ans = i
    print(ans)
 
 
if __name__ == '__main__':
    main()

Submission status: Accepted

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

min_ = 0
while True:
    front = X - min_
    back = X + min_
    if front in P and back in P:
        min_ += 1
    else:
        break

front = X - min_
back = X + min_
if front not in P:
    print(front)
else:
    print(back)

Submission status: Accepted

Solution code:
import numpy as np
x, n = map(int, input().split())
pn = np.array([int(p) for p in input().split()])


sub = pn - x

res = 0
i = 0
while True:
    if sub[sub == -i].size == 0:
        res = x - i
        break

    if sub[sub == i].size == 0:
        res = x+i
        break
    i += 1

print(res)

Submission status: Accepted

Solution code:
x,N=map(int,input().split())
p=list(map(int,input().split()))
p_set=set(p)
flag=0
if x not in p_set:
    ans=x
else:
    count=0
    while flag==0:
        count+=1
        if x+count not in p_set:
            ans=x+count
            flag=1
        if x-count not in p_set:
            ans=x-count
            flag=1
print(ans)

Submission status: Accepted

Solution code:
X,N=map(int,input().split())
if N==0:
  print(X)
else:
  P=list(map(int,input().split()))
  A=[]
  for i in range(N):
    A.append(abs(P[i]-X))
  if 0 not in A:
    print(X)
  else:
    for i in range(1,N+1):
      if i not in A:
        print(X-i)
        break
      else:
        A.remove(i)
        if i not in A:
          if X+i in P:
            print(X-i)
            break
          if X-i in P:
            print(X+i)
            break
        else:
          A.remove(i)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
X,N=map(int,input().split())
if(N==0):
  print(X)
else:
  p=list(map(int,input().split()))
  x=0
  while(True):
      if(X-x not in p):
          print(X-x)
          break
      if(X+x not in p):
          print(X+x)
          break
      x+=1

Submission status: Accepted

Solution code:
X,N=map(int,input().split())
A = list(map(int, input().split()))
def me(X,A,p):
    if X-p in A:
        if X+p in A:
            return me(X,A,p+1)
        else:
            print(X+p)
    else:
        print(X-p)
if X in A:
    me(X,A,1)
else:
    print(X)

Submission status: Accepted

Solution code:
import sys

x, n = map(int, input().split())
if n == 0:
  print(x)
  sys.exit()
li = list(map(int, input().split()))

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

i = 1
while i <= 100:
  if x - i not in li:
    print(x - i)
    break
  elif x + i not in li:
    print(x + i)
    break
  else:
    i += 1

Submission status: Accepted

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

nai=[]
if n==0:
  print(X)
  sys.exit()
else:
  if X not in p:
    print(X)
    sys.exit()
  else:
    for i in range(-200,301):
      if i not in p:
        nai.append(i)
    nai.append(X)
    nai.sort()

    ind=nai.index(X)
    
    if abs(nai[ind-1]-X)<=abs(nai[ind+1]-X):
      print(nai[ind-1])
      sys.exit()
    else:
      print(nai[ind+1])
      sys.exit()

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
p = list(map(int,input().split()))
p_ans = [200] * 2001
count = 0
for i in range(-1000,1001):
    if not(i in p):
        p_ans[count] = abs(x-i) 
    count += 1
p_min = min(p_ans)
for i in range(len(p_ans)):
    if p_min == p_ans[i]:
        print(i-1000)
        exit()

Submission status: Accepted

Solution code:
X,N = map(int,input().split())
if N ==0:
    print(X)
else:
    p = list(map(int,input().split()))
    x_min = 101
    num_list = list(range(102))
    for i in range(N):
        num_list.remove(p[i])
    for j in reversed(num_list):
        x = abs(j-X)
        if x_min >= x:
            x_min = x
            close=j
    print(close)

Submission status: Accepted

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

if N == 0:
     print(X)
else:
    given_list = [int(i) for i in input().split()]
    ans = 0

    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: Accepted

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

#S = input()
#N = int(input())
#n = [list(map(int,input().split())) for i in range(N)]
#n, y = map(int, input().split())

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

p = sorted(list(map(int,input().split())) )
#print(X, N, p)

r = 999
for _p in range(0,102):
    if _p in p:
        continue
    if (abs(_p - X) < abs(r-X)):
        r = _p


print(r)

Submission status: Accepted

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

d={}
for i in range(110):
    d[str(i)]=0
for i in range(110):
    d[str(-i)]=0
 
 
if xn[1]!=0:
    p = list(map(int, input().split()))
    
    for i in range(xn[1]):
        d[str(p[i])]=1
    for i in range(101):
        if d[str(xn[0]-i)]==0:
            miflag=1
            mi=i
            print(xn[0]-mi)
            break
        if d[str(xn[0]+i)]==0:
            maflag=1
            ma=i
            print(xn[0]+ma)
            break
else:
    print(xn[0])

Submission status: Accepted

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(-102,102):
        if i == L:
            if len(P) > 0:
                L = P.popleft()
            else:
                L = 200
        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: Accepted

Solution code:
x, n = map(int, input().split())
try:
    a = list(map(int, input().split()))
except EOFError:
    a = []
    
if not x in a:
    print(x)
else:
    d = 1
    while True:
        if x-d not in a:
            print(x-d)
            break
        elif x+d not in a:
            print(x+d)
            break
        else:
            d+=1

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
if N == 0:
    P = []
else:
    P = list(map(int, input().split()))

a = X
b = X

while a in P and b in P:
    a -= 1
    b += 1

if a not in P:
    print(a)
else:
    print(b)

Submission status: Accepted

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

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

x1 = x
while x1 in p:
    x1 += 1

x2 = x
while x2 in p:
    x2 -= 1

if abs(x-x1) < abs(x-x2):
    print(x1)
else:
    print(x2)

Submission status: Accepted

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

if n == 0:
  print(x)
else:
  p = list(map(int, input().split()))
  p.sort()
  if not x in p:
    print(x)
  else:
    i = p.index(x)
    j = 0
    while True:
      j += 1
      if j % 2 == 0:
        k = j
      else:
        k = -j
      i += k
      x += k
      if i < 0 or i >= n:
        print(x)
        break
      if p[i] != x:
        print(x)
        break

Submission status: Accepted

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


def ans():
    if n == 0:
        return x
    for i in range(100):
        if x - i not in p:
            return x-i
        if x + i not in p:
            return x+i


print(ans())

Submission status: Accepted

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

    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: Accepted

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

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

Submission status: Accepted

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

flag=True
k = 0

while(True):
    b = x - k
    c = x + k
    if(not(b in a)):
        print(b)
        flag = False
        break
    elif(not(c in a) and flag):
        print(c)
        break
    k = k + 1

Submission status: Accepted

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

Submission status: Accepted

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

if n == 0:
    print(x)
else:
    num = list(set(range(-200, 200)) ^ set(p))
    num = sorted([[abs(i - x), i] for i in num])
    if len(num) >= 2 and num[0][0] == num[1][0]:
        print(min(num[0][1], num[1][1]))
    else:
        print(num[0][1])