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:
from collections import defaultdict
X, N = map(int, input().split())
P = [int(x) for x in input().split()]

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

d = defaultdict(bool)
for i in P:
    d[i] = True

i = 0
while True:
    if not d[X - i]:
        print(X - i)
        break
    elif not d[X + i]:
        print(X + i)
        break
    else:
        i += 1

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

p = list(map(int,input().split()))
p = sorted(p,reverse = False)
p_x = []
if p == []:
    print(X)
else:
    for i in range(200):
        if not(i in p):
            p_x.append(i)
    idx_x = bisect.bisect_left(p_x,X)
    if abs(X-p_x[idx_x-1]) < abs(X-p_x[idx_x]):
           print(p_x[idx_x-1])
    elif abs(X-p_x[idx_x-1]) > abs(X-p_x[idx_x]):
           print(p_x[idx_x])
    else:
        print(min(p_x[idx_x],p_x[idx_x-1]))

Submission status: Accepted

Solution code:
def run():
	X, N = [int(v) for v in input().rstrip().split()]
	p = []
	if N > 0:
		p = [int(v) for v in input().rstrip().split()]

	i = -1
	try:
		i = p.index(X)
	except ValueError:
		pass

	if i == -1:
		# not contained	
		return X

	d1 = {}
	for k in range(0, 102):
		d1[k] = k

	for v in p:
		del d1[v]

	l2 = sorted(list(d1.keys()))

	l2.append(X)
	l2.sort()
	i = l2.index(X)

	r = 0
	if i == 0:
		r = l2[1]
	elif (i + 1) == len(l2):
		r = l2[-2]
	else:
		v1 = l2[i + 1] - X
		v2 = X - l2[i - 1]
		if v1 < v2 :
			r = l2[i + 1]
		elif v1 > v2 :
			r = l2[i - 1]
		else:
			# v1 == v2
			r = l2[i - 1]


	return r

r = run()
print(r)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
from itertools import chain

def solve(X: int, N: int, p: "List[int]"):
    p = set(p)
    for d in range(0, 100):
        x = X - d
        if x not in p:
            return x
        x = X + d
        if x not in p:
            return x

def main():
    tokens = chain(*(line.split() for line in sys.stdin))
    # X, N, p = map(int, line.split())
    X = int(next(tokens))  # type: int
    N = int(next(tokens))  # type: int
    p = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    answer = solve(X, N, p)
    print(answer)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
p = list(map(int,input().split()))
p.sort()
right = x
left = x
while True:
    if left in p:
        left -= 1
    else:
        print(left)
        break
    if right in p:
        right += 1
    else:
        print(right)
        break

Submission status: Accepted

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

for y in range(x+1):
  for b in[-1,1]:
    c=x+y*b
    if a.count(c)==0:
      print(c)
      exit(0)

Submission status: Accepted

Solution code:
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

x,n = map(int,input().split())
S = set(map(int,input().split()))
for i in range(100):
  if x-i not in S:
    print(x-i)
    break
  if x+i not in S:
    print(x+i)
    break

Submission status: Accepted

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

for d in range(x + 1):
    for s in [-1, +1]:
        a = x + s * d
        if P.count(a) == 0:
            print(a)
            exit(0)

Submission status: Accepted

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

if len(p) == 0 or X < min(p) or X > max(p):
    print(X)
    exit()

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

Submission status: Accepted

Solution code:
X, N = list(map(int, input().split()))
p = list(map(int, input().split()))
integer = [i for i in range(102)]
for i in range(N):
   integer.remove(p[i])
l = len(integer)
ans = -200
for i in range(l):
   if abs(ans) > abs(integer[i]-X):
      ans = integer[i] - X
print(ans + X)

Submission status: Accepted

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

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

count_up= 0
count_down = 0
while True:
  if not X + count_up in p:
    break
  count_up += 1
    
while True:
  if not X - count_down in p:
    break
  count_down += 1

if count_up < count_down:
  print(X+count_up)
else:
  print(X-count_down)

Submission status: Accepted

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

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

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

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

x1,x2 = x,x
for i in range(100):
  x1 -= 1
  x2 += 1
  if x1 not in p:
    print(x1)
    exit()
  if x2 not in p:
    print(x2)
    exit()

Submission status: Accepted

Solution code:
#C
x, n = map(int, input().split())
if n ==0:
    print(x)
else:
    p = list(map(int, input().split()))
    num = list(range(-1, 102))

    num_removed=num
    for i in range(len(p)):
        num_removed=[num_removed for num_removed in num_removed if num_removed != p[i]]

    num_list=[]
    for i in num_removed:
        num_list.append(abs(x-i))

    min_index=min([i for i, j in enumerate(num_list) if j == min(num_list)])

    print(num_removed[min_index])

Submission status: Accepted

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

for i in range(1000):
    right = x-i
    left = x+i

    if right not in P:
        ans = right
        break

    if left not in P:
        ans = left
        break
print(ans)

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
p=list(map(int,input().split()))
if(n==0):
    print(x)
    exit()
ans=1000
c=1000
for i in range(-1,102):
    b=1
    for j in range(n):
        if(p[j]==i):
            b=0
    if(b==0):
        continue
    else:
        a=abs(x-i)
        if(ans==a):
            if(c>i):
                c=i
        elif(a<ans):
            ans=a
            c=i
print(c)

Submission status: Accepted

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

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

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

L = sorted([abs(X-p) for p in P])
if 0 not in L :
    print(X)
    exit()

DL = list(set([x for x in L if L.count(x) > 1]))

ans_abs = 1
for i,x in enumerate(DL) :
    if x == i+1 :
        ans_abs += 1
    else :
        break

if X-ans_abs in P :
    print(X+ans_abs)
else :
    print(X-ans_abs)

Submission status: Accepted

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

if N == 0:
  print(X)
else:
  for i in range(X,-2,-1):
    if i not in P:
      a = abs(X - i)
      break
  for j in range(X+1,102):
    if j not in P:
      b = abs(j - X)
      break
  if a <= b:
    print(i)
  else:
    print(j)

Submission status: Accepted

Solution code:
X, N = map(int, input().split(' '))
diff, rst = -1, 0
if N == 0:
    print(X)
else:
    P_ls = list(map(int, input().split(' ')))
    for i in range(101, -1, -1):
        if i not in P_ls:
            if diff == -1:
                diff = abs(X - i)
                rst = i
            else:
                diff = min(diff, abs(X - i))
                if diff == abs(X - i):
                    rst = i
    print(rst)

Submission status: Accepted

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

l = [i - x for i in p]
m = [0]
for i in range(1, 101):
    m.append(-i)
    m.append(i)
for i in range(201):
    if (m[i] in l) == True:
        continue
    if (m[i] in l) == False:
        print(x + m[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()))
  A = [0]
  for i in range(1, 102):
    if (i in P) == False:
      A.append(i)
      
  c = 101
  for j in range(len(A)):
    if abs(X - A[len(A)-int(j)-1]) <= abs(X - c):
      c = A[len(A)-int(j)-1]
    else:
      c = c
  print(c)

Submission status: Accepted

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

Submission status: Accepted

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


for i in range(200):
    if x-i not in l:
        print(x-i)
        exit()
    if x+i not in l:
        print(x+i)
        exit()

Submission status: Accepted

Solution code:
N,M=list(map(int,input().split()))
L=list(map(int,input().split()))
if N not in L:
  print(N)
  exit()
c=N
d=N
while True:
  if c not in L:
    break
  else:
    c-=1
while True:
  if d not in L:
    break
  else:
    d+=1
if abs(d-N)>=abs(c-N):
  print(c)
else:
  print(d)

Submission status: Accepted

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

X, N = map(int, input().split())
p = list(map(int, input().split()))
st = set(p)
for i in range(X+1):
    if X - i not in st:
        print(X - i)
        break
    if X + i not in st:
        print(X + i)
        break

Submission status: Accepted

Solution code:
X,N=map(int,input().split())
P=set(map(int,input().split()))
l=[0]+[(1+i//2)*(-1 if i%2==0 else 1) for i in range(101)]
for i in l:
    if X+i not in P:
        print(X+i)
        break

Submission status: Accepted

Solution code:
X,N=map(int,input().split())
p=list(map(int,input().split()))
i=0
j=0
while X+i in p:
    i+=1
while X-j in p:
    j+=1
if i>j:
    print(X-j)
elif i<j:
    print(X+i)
else:
    print(min([X+i,X-j]))

Submission status: Accepted

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

if x not in P:
  print(x)
  exit()
i,c = 1, 0
while i <= n:
  m = x - i
  l = x + i
  if m not in P:
    print(m)
    break
  elif l not in P:
    print(l)
    break
  i += 1

Submission status: Accepted

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

Submission status: Accepted

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]:
        ans = X + i * j

        if p.count(ans) == 0:
            print(ans)
            break
    else:
        continue
    break

Submission status: Accepted

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

for i in range(x+1):
    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())
if n == 0:
  ans = x
else:
  p = [int(i.strip()) for i in input().split()]
  for i in range(n+1):
    ch_1 = x-i
    ch_2 = x+i
    if p.count(ch_1) == 0:
      ans = ch_1
      break
    elif p.count(ch_2) == 0:
      ans = ch_2
      break
print(ans)

Submission status: Accepted

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 a not in p:
            print(a)
            exit()

Submission status: Accepted

Solution code:
X,N=map(int,input().split())
p=list(map(int,input().split()))
upper=float("inf")
lower=float("inf")
a=X
b=X
while True:
    if not a in p:
        upper=a
        break
    a+=1
while True:
    if not b in p:
        lower=b
        break
    b-=1
if abs(upper-X)==abs(lower-X):
    print(lower)
elif abs(upper-X)>abs(lower-X):
    print(lower)
else:
    print(upper)

Submission status: Accepted

Solution code:
from bisect import bisect_left
X, N = list(map(int, input().split()))
P = list(map(int, input().split()))
P.sort()
S = set(P)

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


def bisectsearch_left(L, a):
    i = bisect_left(L, a)
    return(i)


k = bisectsearch_left(P, X)
if X != P[k]:
    print(X)
else:
    ct = 0
    while True:
        ct += 1
        if X-ct not in S:
            print(X-ct)
            break
        elif X+ct not in S:
            print(X+ct)
            break

Submission status: Accepted

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

pN.sort()

diff = 0

if n == 0:
    print(x)
else:
    while(1):
        if x-diff not in pN:
            print(x-diff)
            exit()
        elif x+diff not in pN:
            print(x+diff)
            exit()
        diff+=1

Submission status: Accepted

Solution code:
X, N = map(int, input().split(' '))
if N == 0:
    print(X)
else:
    P_ls = list(map(int, input().split(' ')))
    diff = -1
    for i in range(101, -1, -1):
        if i not in P_ls:
            if diff == -1:
                diff = abs(X - i)
                rst = i
            else:
                diff = min(diff, abs(X - i))
                if diff == abs(X - i):
                    rst = i
    print(rst)

Submission status: Accepted

Solution code:
N,M=list(map(int,input().split()))
ans=[]
if M==0:
  print(N)
  exit()
c=N
L=list(map(int,input().split()))
while True:
  if c not in L:
    ans.append(c)
    break
  else:
    c+=1
c=N
while True:
  if c not in L:
    ans.append(c)
    break
  else:
    c-=1
if abs(ans[0]-N)>=abs(ans[1]-N):
  print(ans[1])
elif abs(ans[0]-N)<abs(ans[1]-N):
  print(ans[0])

Submission status: Accepted

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

a = list(range(102))
for i in range(N):
    a[P[i]] = -2
m = 102
for i in range(102):
    if m > (abs(X - a[i])):
        m = (abs(X - a[i]))
        ans = a[i]
print(ans)

Submission status: Accepted

Solution code:
import bisect


def abc170c_forbidden_list():
    x, n = map(int, input().split())
    p = list(map(int, input().split()))
    if n == 0:
        print(x)
        return
    p.sort()
    for i in range(100):
        idx = bisect.bisect_left(p, x - i)
        if idx >= n or p[idx] != x - i:
            print(x - i)
            return
        idx = bisect.bisect_left(p, x + i)
        if idx >= n or p[idx] != x + i:
            print(x + i)
            return


abc170c_forbidden_list()

Submission status: Accepted

Solution code:
X, N =map(int, input().split())
p_list=list(map(int, input().split()))
#i=N
#1st Xがp_listにあるか
	#あれば+=!
	#なければ答え
#|X-i|=1がp_listにあるか
	#あれば+=!
	#なければ答え

i=N
j=0
while True:
	if X-j not in p_list:
		print(X-j)
		exit()
	elif X+j not in p_list:
		print(X+j)
		exit()
	else:
		j+=1

Submission status: Accepted

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

if n==0:
    print(x)
else:
    q=[abs(p[i]-x) for i in range(n)]
    re=max(q) #xと最も離れているものはどれだけ離れてるか
    i=0
    if re==0:
        print(x-1)
    else:
        while(i < re+1):
            if x-i not in p:
                print(x-i)
                break
            elif x+i not in p:
                print(x+i)
                break
            i += 1
        if i==re+1:
            print(x-i)

Submission status: Accepted

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

p = list(map(int, input().split()))
count = 0
res = 0
while True:
    before = X - count
    after = X + count
    if before not in p:
        res = before
        break
    elif after not in p:
        res = after
        break
    count += 1
print(res)

Submission status: Accepted

Solution code:
X,N = map(int,input().split())
p = list(map(int,input().split()))
diff = 1
if(X not in p):
    print(X)
    exit()
while(diff < 200):
    if(X-diff not in p):
        print(X-diff)
        exit()
    elif(X+diff not in p):
        print(X+diff)
        exit()
    diff += 1

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
if n == 0:
    print(x)
else:
    p = list(map(int,input().split()))
    absolute = list(map(lambda i:abs(i-x),p))
    if 0 not in absolute:
        print(x)
    else:
        ab = set(p)
        i = 1
        while i < 100:
            if absolute.count(i) == 2:
                i += 1
            else:
                opt = set([x-i,x+i])
                ans = opt - ab
                break

        print(min(ans))

Submission status: Accepted

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

Q = list()
for i in range(200):
    Q.append(i+1)
for j in P:
    Q.remove(j)

Q_len = len(Q)
swich = True

if N == 0:
    print(X)
else:
        for i in range(Q_len+1):
            if swich == True:
                xm = X-i
                xp = X+i
                for j in range(Q_len):
                    if xm == 0:
                        print(0)
                        swich = False
                        break
                    elif xm == Q[j]:
                        print(xm)
                        swich = False
                        break
                    elif xp == Q[j]:
                        print(xp)
                        swich = False
                        break
            else:
                break

Submission status: Accepted

Solution code:
X,N =  map(int,input().split())
N_List = list(map(int,input().split()))
ct = 0
pos = 0
while True:
    if pos == 0:
        if X not in N_List:
            ans = X
            break
        else:
            pos += 1
    elif pos > 0:
        if X-pos not in N_List:
            ans = X - pos
            break
        elif X + pos not in N_List:
            ans = X + pos
            break
        else:
            pos += 1
print(ans)

Submission status: Accepted

Solution code:
def main():
    x,n = map(int,input().split())
    p = list(map(int,input().split()))
    ans = -100
    for i in range(-1,102):
        if i not in p and abs(i-x) < abs(ans-x):
            ans = i
    print(ans)
    
    return

if __name__ == '__main__':
    main()

Submission status: Accepted

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

for i in range(1000):
    if x-i not in p:
        print(x-i)
        exit()
    elif x+i not in p:
        print(x+i)
        exit()

Submission status: Accepted

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

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

for i in range(x+1):
    if x-i not in p:
        print(x-i)
        exit()
    elif 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:
    ls = list(map(int, input().split(' ')))
    diff, rst = -1, 0
    for i in range(101, -1, -1):
        if i not in ls:
            if diff == -1:
                diff = abs(X - i)
                rst = i
            else:
                diff = min(diff, abs(X - i))
                if diff == abs(X - i):
                    rst = i
    print(rst)

Submission status: Accepted

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

for i in range(x+1):
    if not(x - i) in p:
        print(x - i)
        exit()
    elif not(x + i) in p:
        print(x + i)
        exit()
print(x)

Submission status: Accepted

Solution code:
def solve():
    X,N = [int(i) for i in input().split()]
    if N == 0:
        print(X)
        return

    P = set([int(i) for i in input().split()])
    for i in range(len(P)+1):
        target = X - i
        if target not in P:
            print(target)
            break
        target = X + i
        if target not in P:
            print(target)
            break

if __name__ == "__main__":
    solve()

Submission status: Accepted

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

sa = 0


while(True):
  if x - sa not in l:
    ans = x - sa
    break
    
  elif x +sa not in l:
    ans = x + sa
    break
  else:
    sa +=1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
#if n==0:
#    print(x)
p = list(range(n))
p = list(map(int, input().split()))
p_2 = list(range(n))
for i in range(n):
    p_2[i] = x-p[i]
for i in range(100):
    h = p_2.count(i)
    h_2 = p_2.count(-i)
    if h==0 and h_2!=0:
        print(x-i)
        break
    elif h!=0 and h_2==0:
        print(x+i)
        break
    elif h==0 and h_2==0:
        print(x-i)
        break
#if n==0:
#    print(x)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = list(map(int,input().split()))
if x not in p:
    y = x
else:
    i = 1
    y = x
    while y == x:
        if x - i not in p:
            y = x - i
        elif x + i not in p:
            y = x + i
        i += 1
print(y)

Submission status: Accepted

Solution code:
# Forbidden List
X,N = map(int,input().split())
p = list(map(int, input().split()))
ans = 200
for i in range(-1,102):
    if i not in p:
        ans = [ans, i][abs(X-i) < abs(X-ans)]
print(ans)

Submission status: Accepted

Solution code:
X, N = map(int, input().split(' '))
if N == 0:
    print(X)
else:
    ls = list(map(int, input().split(' ')))
    diff = -1
    for i in range(101, -1, -1):
        if i not in ls:
            if diff == -1:
                diff = abs(i - X)
                result = i
            else:
                diff = min(diff, abs(i - X))
                if diff == abs(i - X):
                    result = i
    print(result)

Submission status: Accepted

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

if N != 0:
    p_list = list(map(int, input().split()))
    p_list_min = sorted(p_list)
    
non_p_list = []

if N >= 1:
    for i in range(p_list_min[0]-1, p_list_min[-1]+2):
        if i not in p_list_min:
            non_p_list.append(i)
            ans_diff = abs(X - non_p_list[-1])+1
        for i in range(len(non_p_list)):
            temp_diff = abs(X - non_p_list[i])
            if ans_diff > temp_diff:
                ans_diff = temp_diff
                ans = non_p_list[i]
    #print(non_p_list)
    print(ans)
else:
    print(X)

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
if not N == 0:
  p_l = list(map(int, input().split()))
if N == 0:
  print(X)
  exit()
a = b = X
if not a in p_l:
  if not b in p_l:
    if a > b:
      print(b)
      exit()
    else:
      print(a)
      exit()
  print(a)
  exit()
elif not b in p_l:
  if not a in p_l:
    if a > b:
      print(b)
      exit()
    else:
      print(a)
      exit()
  print(b)
while True:
  a += 1
  if b > 0:
    b -= 1
  if a in p_l and b in p_l:
    continue
  if not a in p_l:
    if not b in p_l:
      if a > b:
        print(b)
#        print("A")
        exit()
      else:
#        print("B")
        print(a)
        exit()
#    print("C")
    print(a)
    exit()
  elif not b in p_l:
    if not a in p_l:
      if a > b:
        print(b)
#        print("D")
        exit()
      else:
        print(a)
#        print("E")
        exit()
#    print("F")
    print(b)
    exit()

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
if x not in p:
    print(x)
else:
    a, b = 1, 1
    while True:
        if (x + a) not in p:
            break
        else:
            a += 1

    while True:
        if (x - b) not in p:
            break
        else:
            b += 1

    if a >= b:
        print(x - b)
    else:
        print(x + a)

Submission status: Accepted

Solution code:
x, n = list(map(int, input().split()))
if n == 0:
  inputs = []
else:
  inputs = list(map(int, input().split()))
nums = [0] * 201
diff = 1000
n = 100
for i in inputs:
  nums[i] = 1
for i in range(0, 201):
  d = abs(i - x)
  if nums[i] == 1:
    continue
  if d < diff:
    diff = d
    n = i
print(n)

Submission status: Accepted

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

    if n == 0:
        minimum = x
    else:
        if x not in p_lst:
            minimum = x

        else:
            lst = []
            flag = False
            x1 = x
            x2 = x

            while True:
                x1 += 1
                x2 -= 1

                if x1 not in p_lst:
                    lst.append(x1)
                    flag = True
                if x2 not in p_lst:
                    lst.append(x2)
                    flag = True

                if flag:
                    break

            minimum = min(lst)

    print(minimum)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
X,N=map(int,input().split())
if N==0:
    print(X)
else:
    w=input()
    w=w.split()
    t=list(w)
    b=list(range(-150,151))
    tt=[int(a) for a in t]

    ttt=set(tt)
    bb=set(b)

    c=bb^ttt

    cc=list(c)

    u=1000


    for s in cc:
        if abs(s-X)<u:
            u=abs(s-X)

    if (X-u) in cc:
            print(X-u)
    else :
            print(X+u)

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
if N>0:
  p = [int(i) for i in input().split()]
else:
  p = [-1]
  
p = sorted(p)
#print(p)
 
try:
  idx=p.index(X)
  flag=False
  for i in range(X+1):
    for o in [-1,+1]:
      if idx+(i*o) < 0 or idx + (i*o) >= N:
        print(X+(i*o))
        flag=True
        break
      elif X+(i*o)!=p[idx+(i*o)]:
        print(X+(i*o))
        flag=True
        break
    if flag:
      break
except:
  print(X)

Submission status: Accepted

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

if N==0:
  print(X)
  exit(0)
  
p = [int(i) for i in input().split()]

for i in range(X+1):
  for s in [-1,1]:
    a = X + i*s
    if a not in p:
      print(a)
      exit(0)

Submission status: Accepted

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

if N==0:
  print(X)
  exit(0)
  
p = [int(i) for i in input().split()]

for i in range(101):
  for s in [-1,1]:
    a = X + i*s
    if a not in p:
      print(a)
      exit(0)

Submission status: Accepted

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

if n == 0:
  print(x)
else:
  lis = list(map(int, input().split()))
  if x not in lis:
    print(x)
  else:
    y = x + 1
    z = x - 1
    while True:
      if y in lis and z in lis:
        y += 1
        z -= 1
      elif z not in lis:
        print(z)
        break
      elif y not in lis:
        print(y)
        break

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
p = list(map(int,input().split()))
dic = {}
lis = []
for i in range(0,102):
    if i not in p:
        dic[i] = abs(x-i)
        lis.append(i)

mini = min(dic.values())
for j in lis:
    if mini == dic[j]:
        print(j)
        break

Submission status: Accepted

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

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


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

Submission status: Accepted

Solution code:
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [input() for _ in range(n)]

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

ans = x
for i in range(x, 102):
    if i not in p:
        ans = i
        break

ans2 = x
for i in range(x-1, -1, -1):
    if i not in p:
        ans2 = i
        break

#print(ans,ans2)
tmp1 = abs(ans - x)
tmp2 = abs(x - ans2)

if (tmp1 < tmp2):
    print(ans)
elif (tmp1 == tmp2):
    print(min(ans, ans2))
else:
    print(ans2)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))

x, n = inm()
a = inl()
count = 1
if x not in a:
    print(x)
else:
    while True:
        if x - count not in a:
            print(x - count)
            break
        if x + count not in a:
            print(x + count)
            break
        count += 1

Submission status: Accepted

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

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

arr.sort()
if x in arr:
  i = arr.index(x)
else:
  print(x)
  exit(0)

if not i and i != 0:
  print(x)
  exit(0)

j = 1
for _ in range(n):
  row = i - j
  high = i + j
  if x - j not in arr:
    print(x - j)
    exit(0)
  elif x + j not in arr:
    print(x + j)
    exit(0)
  j += 1

print(x-1)

Submission status: Accepted

Solution code:
inp = [int(a) for a in input().split()]
X = inp[0]
N = inp[1]
if N == 0:
  print(X)
else:
  P = [int(b) for b in input().split()]

  found = 0
  num = 0
  answer = X
  while(found == 0):
    if not (X - num in P):
      found = 1
      answer = X - num
    elif not (X + num in P):
      found = 1
      answer = X + num
    num += 1
  print(answer)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
p.sort()
ans = 0
for i in range(102):
    if i in p:
        pass
    elif abs(x - ans) > abs(x - i):
        ans = i
print(ans)