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

# titleの通り、使用を禁止された数字のリストが与えられる。
flist = list(map(int,input().split()))

if flist.count(X) == 0:
    print(X)
    exit()

# 使用禁止の数字を除いたリストを作るために、リストの素を作る。
l = list(range(0,102)) # ここの範囲設定が一番難しい部分だと思う。

# 使用を許可された数字のリストを作成する。
plist = []
for i in range(len(l)):
    if flist.count(l[i]) == 0:
        plist.append(l[i])

# Xを投入して、前後の数字との距離を計測していく。
plist.append(X)
anslist = sorted(plist)
t = anslist.index(X)

dist1 = anslist[t] - anslist[t-1] # Xと1つ前の数字との距離
dist2 = anslist[t+1] - anslist[t] # Xと1つ後ろの数字との距離
if dist1 <= dist2:
    print(anslist[t-1])
else:
    print(anslist[t+1])

Submission status: Accepted

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

Submission status: Accepted

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

    if x not in p:
        print(x)
    else:
        for i in range(1, 200):
            if x - i not in p:
                print(x - i)
                break
            if x + i not in p:
                print(x + i)
                break

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
x,y=map(int,input().split())
a=list(map(int,input().split()))
dif=1
if x not in a:
  print(x)
else:
  while True:
    if x-dif not in a:
      dif*=-1
      break
    elif x+dif not in a:
      break
    else:
      dif+=1
  print(x+dif)

Submission status: Accepted

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

if X not in p:
    print(X)
else:
    variable_val = 1
    while True:
        if X - variable_val not in p:
            print(X - variable_val)
            exit(0)
        if X + variable_val not in p:
            print(X + variable_val)
            exit(0)
        variable_val += 1

Submission status: Accepted

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

# C - Forbidden List
x, n = map(int, input().split())

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

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

Submission status: Accepted

Solution code:
from collections import defaultdict as dd
x, n = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
d = dd(int)
for i in a:
    d[i] = 1

left, right = x-1, x+1

if x not in d:
    print(x)
else:
    while(1):
        if left not in d:
            print(left)
            break
        if right not in d:
            print(right)
            break
        left -=1
        right +=1

Submission status: Accepted

Solution code:
"""A問題
x= list(map(int,input().split()))
a = 1
for i in x:
    if i == 0:
        print(a)
    a+=1
"""
"""B問題
[x,y]= list(map(int,input().split()))
if (y-2*x)%2==0 and y-2*x>=0 and 4*x-y>=0 :
    print("Yes")
else:
    print("No")
"""
[x,n]= list(map(int,input().split()))
p= list(map(int,input().split()))
q= [i for i in range(102)]
p= [i for i in q if i not in p]
r = [abs(i-x) for i in p]
print(p[r.index(min(r))])

Submission status: Accepted

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

p.sort()

if n == 0:
    print(x)
else:
    for i in range(0, 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:
from sys import stdin, stdout, setrecursionlimit
from collections import deque, defaultdict
import math

rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: map(int, stdin.readline().split())
rlf = lambda: map(float, stdin.readline().split())

INF, NINF = float('inf'), float('-inf')

def bs(L, x):
	i, jump = 0, len(L)-1
	while jump >= 1:
		while i + jump < len(L) and L[i+jump] <= x:
			i += jump
		jump //= 2
	return i


def main():
	x, n = rli()
	P = list(rli())
	P.sort()
	forbidden = set(P)
	if x not in forbidden:
		print(x)
		return
	# c = bs(P, x)
	for diff in range(0, 101):
		a, b = x - diff, x + diff
		if a not in forbidden:
			print(a)
			return
		if b not in forbidden:
			print(b)
			return
	stdout.close()

if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
if n!=0:
  p=list(map(int,input().split()))
  hantei=10**9+1
  sp=set(p)
  ans=0
  for i in range(-10000,10000):
    if not i in sp:
      if hantei>abs(i-x):
        hantei=abs(i-x)
        ans=i
  print(ans)
else:
  print(x)

Submission status: Accepted

Solution code:
X, N = map(int,input().split())
if N == 0:
  print(X)
else:
  plist = list(map(int,input().split()))
  ans = -2000
  dist1 = 1000
  for i in range(-200,200):
    dist2 = abs(X-i)
    if dist2 < dist1 and not(i in plist):
      ans = i
      dist1 = dist2
  print(ans)

Submission status: Accepted

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

p.sort()

p0 = [0]
j = 0
for i in range(1,100):
    if p[j]!=i:
        p0.append(i)
    elif p[j] == i:
        j+=1
    if j == N:
        for i0 in range(i+1,100):
            p0.append(i0)
        break
p0.append(101)
p1 = [0 for i in range(len(p0))]
for i in range(len(p0)):
    p1[i] = p0[i]-X
    p1[i] = np.abs(p1[i])
    
ii = np.argmin(p1)

print(p0[ii])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
def main():    
    x, n = map(int, input().split())
    if n == 0:
        print(x)
        return
    p = list(map(int, input().split()))
    check = 0
    while(1):
        s = check//2
        if check%2 == 0:
            ans = x-s
        else:
            ans = x+s
        if not ans in p:
            print(ans)
            return
        check += 1
main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
arr = list(map(int, input().split()))
ans = 10000
for i in range(0,110):
    if i not in arr:
        if abs(X-i) < abs(X-ans):
            ans = i
print(ans)

Submission status: Accepted

Solution code:
x,y=map(int,input().split())
a=list(map(int,input().split()))
a=set(a)
for i in range(101):
  
  if x-i not in a:
        print(x-i)
        exit()
  elif x+i not in a:
      print(x+i)
      exit()

Submission status: Accepted

Solution code:
x,_,*l=map(int,open(0).read().split())
print(min((abs(i-x),i) for i in {*range(102)}-{*l})[1])

Submission status: Accepted

Solution code:
x,n,*l=map(int,open(0).read().split())
print(min((abs(i-x),i) for i in range(102) if i not in l)[1])

Submission status: Accepted

Solution code:
x,n,*l=map(int,open(0).read().split())
l=set(l)
t=101
for i in range(102):
  if i not in l and abs(i-x)<t: a,t=i,abs(i-x)
print(a)

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
p = list(map(int,input().split()))
for i in range(101):
    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())
a=list(map(int,input().split()))

def ok(n):
	if not n in a:
		print(n)
		exit()


for i in range(1000):
	ok(x-i)
	ok(x+i)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
X, N=map(int, input().split())
a=list(map(int, input().split()))
s=set(a)
ans=0
for i in range(-1,102):
  if (i not in s) and abs(ans-X)>abs(i-X):
    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()))
if p.count(X) == 0:
    print(X)
    exit()


l = list(range(0,102)) #ここの範囲設定が一番難しい部分だと思う
flist = []
for i in range(len(l)):
    if p.count(l[i]) == 0:
        flist.append(l[i])


flist.append(X)
anslist = sorted(flist)
t = anslist.index(X)

dist1 = anslist[t] - anslist[t-1] #Xと1つ前の数字との距離
dist2 = anslist[t+1] - anslist[t] #Xと1つ後ろの数字との距離
if dist1 <= dist2:
    print(anslist[t-1])
else:
    print(anslist[t+1])

Submission status: Accepted

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

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

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

if __name__ == "__main__":
    main()

Submission status: Accepted

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

counter = 0

while True:
    if x - counter not in ps:
        ans = x - counter
        break
    elif x + counter not in ps:
        ans = x + counter
        break
    else:
        counter += 1

print(ans)

Submission status: Accepted

Solution code:
import sys

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

p.sort()

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

for i in range(0, 100):
    if (x - i) not in p:
        print(x - i)
        sys.exit()
    if (x + i) not in p:
        print(x + i)
        sys.exit()

Submission status: Accepted

Solution code:
x, n =map(int, input().split())  #複数数値入力
list_p = list(map(int, input().split()))  #リスト入力


if n == 0:
    print(x)
else:
    i = 0
    while True:
        if x - i not in list_p:
            print(x-i)
            break
        elif x + i not in list_p:
            print(x+i)
            break
        else:
            i += 1

Submission status: Accepted

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

dist=1000
ans=1000
for i in range(101,-1,-1):
  if i in p:
    continue
  t_dist=abs(x-i)
  if t_dist<=dist:
    ans=i
    dist=t_dist

print(ans)

Submission status: Accepted

Solution code:
X, N = input().split()
p = input().split()
X = int(X)
N = int(N)
min = 101
ans = -100
for i in range(-101, 102):
    if str(i) in p:
        continue
    a = abs(i - X)
    if a < min:
        min = a
        ans = i
print(ans)

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
pl = list(map(int,input().split()))
if n == 0:
  print(x)
  exit()
for i in range(100):
  if not x-i in pl:
    print(x-i)
    exit()
  if not x+i in pl:
    print(x+i)
    exit()

Submission status: Accepted

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

for i in range(100):
    if (x-i) not in num_list:
        print(x-i)
        exit()

    if (x+i) not in num_list:
        print(x+i)
        exit()

Submission status: Accepted

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

for i in range(101):
    if (x-i) not in num_list:
        print(x-i)
        exit()

    if (x+i) not in num_list:
        print(x+i)
        exit()

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
for j in range(105):
    if (x-j) not in p:
        print(x-j)
        break
    if (x+j) not in p:
        print(x+j)
        break

Submission status: Accepted

Solution code:
# coding: utf-8
# 日本語を入力できるようにするために上記一文が必要


x, y = map(int, input().split() )
num_list = list( map(int, input().split() ) )

try:
        num_list.remove(x)

        for i in range(1,101):
                try:
                        num_list.remove(x - i)
                except ValueError:
                        print(x - i)
                        break

                try:
                        num_list.remove(x + i)
                except ValueError:
                        print(x + i)
                        break

except ValueError:
        print(x)

Submission status: Accepted

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

Q=[0]*102
for i in range(0,102):
    Q[i]=abs(X-i)


for i in  p:
    Q[i]=1000

print(Q.index(min(Q)))

Submission status: Accepted

Solution code:
import sys

X,N = map(int,input().split())
if N != 0:
    P_LIST = list(map(int,input().split()))
else:
    print(X)
    sys.exit()

i = 0
for i in range(100):
    A = X - i
    if A not in P_LIST:
        X_min = A
        for j in range(100):
            B = X + j
            if B not in P_LIST:
                X_max = B
                if X_max - X < X - X_min:
                    print(X_max)
                    sys.exit()
                else:
                    print(X_min)
                    sys.exit()

Submission status: Accepted

Solution code:
import sys

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

if N == 0:
  print(X)
else:
  argv = input().split()
  argv.sort()

  for num in range(100):
    out = 0
    for i in range(N):
      if int(argv[i]) == X - num:
        out = 1
        
    if out == 0:
      print(X - num)
      break;
      
    out = 0
    
    for i in range(N):
      if int(argv[i]) == X + num:
        out = 2
    
    if out == 0:
      print(X + num)
      break;

Submission status: Accepted

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

ans = 0
diff = x
for i in range(1, 102):
  if i in p:
    continue
  tmp = abs(i - x)
  if tmp < diff:
    diff = tmp
    ans = i
print(ans)

Submission status: Accepted

Solution code:
import sys
from collections import Counter
X, N = [int(x) for x in input().split()]
P = []
if N:
    P = [int(x) for x in input().split()]

CP = Counter(P)
if CP[X] == 0:
    print(X)
    sys.exit()

for d in range(1, 1000):
    if CP[X - d] == 0:
        print(X - d)
        break
    elif CP[X + d] == 0:
        print(X + d)
        break

Submission status: Accepted

Solution code:
X, N = [int(x) for x in input().strip().split()]
p = set([int(x) for x in input().strip().split()])
ans = 0
diff = X
for i in range(102):
  if i in p:
    continue
  if abs(X - i) < diff:
    ans = i
    diff = abs(X - i)
print(ans)

Submission status: Accepted

Solution code:
import sys

X,N = map(int,input().split())
P = list(map(int,input().split()))
if X < 1 or 100 < X:
    sys.exit()
if N < 0 or 100 < N:
    sys.exit()
if N == 0:
    print(X)
    sys.exit()

P_number = len(P)
if P_number < 1 or 100 < P_number:
    sys.exit()

res1 = 100
res2 = 100
res0 = 0
i = 0
j = 0
while i <= N:
    if (X - i) not in P:
        res1 = (X - i)
        break
    i += 1
while j <= N:
    if (X + j) not in P:
        res2 = (X + j)
        break
    j += 1
if i > j:
    res0 = res2
elif j > i:
    res0 = res1
elif i == j:
    res0 = res1
print(res0)

Submission status: Accepted

Solution code:
X, N = list(map(int, input().split()))
if N == 0: print(X)
else:
    p = list(map(int, input().split()))
    if not X in p:
        print(X)
    else:
        q = [X-1, X+1]

        while True:

            if not q[0] in p:
                print(q[0])
                break
            elif not q[1] in p:
                print(q[1])
                break
            q = [q[0]-1, q[1]+1]

Submission status: Accepted

Solution code:
X,N = map(int,input().split())
if N == 0:
  print(X)
  
else:
  p = list(map(int,input().split()))
  
  if X not in p:
    print(X)
    
  else:
    n = [x for x in range(102)]

    for i in p:
      n.remove(i)
    ans = 0  
    a = 101
    b = -1
    for j in n:
      b += 1
    
      if abs(j-X) < a:
        a=abs(j-X)
        ans = n[b]
  
    print(ans)

Submission status: Accepted

Solution code:
import sys

X, Y = map(int, input().split())
N_list = list(map(int,input().split()))
N_answer = []

if len(N_list) == 0:
    print(X)
    sys.exit()
for i in range(100):
    if (X + i) not in N_list:
        N_answer.append(X + i)
    if (X - i) not in N_list:
        N_answer.append(X - i)
    
    if len(N_answer) > 0:
        break

print(min(N_answer))

Submission status: Accepted

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

P = list(map(int, input().split()))
t = 100
for i in range(0,102):
  if not i in P:
    if t > abs(i - x):
      t = abs(i - x)
      ans = i

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

import numpy
from bisect import bisect_left

def main():
  x, n = map(int, input().split())
  if n == 0:
    print(x)
    return
  
  lp = sorted(list(map(int, input().split())))
  cands = numpy.array(list(set(range(0, 102)) - set(lp))) - x
  i = bisect_left(cands, 0)
  a, b = cands[:i][::-1][0], cands[i:][0]
  if abs(a) > abs(b):
    print(x+b)
  else:
    print(x+a)

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(101):
  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 = set(map(int, input().split()))

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

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
a = list(map(int, input().split()))
for i in range(105):
    if (x-i) not in a:
        print(x-i)
        exit()
    if (x+i) not in a:
        print(x+i)
        exit()

Submission status: Accepted

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

Submission status: Accepted

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

result = 100

l = list(range(0,102))



if len(p) == 0:
    kotae = x
else:
    for i in range(len(p)):

        l[p[i]] = ""



    for i in reversed(range(len(l))):
     
        if l[i] != "":

            if result >= abs(l[i] - x):
                result = abs(l[i] - x)
               
                kotae = l[i]          
            
print(kotae)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
num = [i for i in range(1, 101) if i not in p]
l = 0
r = 101
for i in num:
    if i <= x:
        l = max(l, i)
    else:
        r = min(r, i)
# print(l, r)
if l+r == 2*x:
    ans = l
elif x-l < r-x:
    ans = l
else:
    ans = r

print(ans)

Submission status: Accepted

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

NL = []
for i in range(102):
    NL.append(i)

for l in L:
    NL.remove(l)

NL.append(X)
NL.sort()

LR = NL.index(X)+1
LL = NL.index(X)-1


if (NL[LR]-X) < (X-NL[LL]):
    print(NL[LR])
else:
    print(NL[LL])

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

z = list(range(-2,105))
x,n = inpl()
a = inpl()
for i in a:
    if i in z:
        z.remove(i)
res = -1
sa = INF
for i in z:
    if abs(x-i) < sa:
        res = i
        sa = abs(x-i)
print(res)

Submission status: Accepted

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

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

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

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

Submission status: Accepted

Solution code:
X,N = map(int,input().split(" "))
if N==0:
  print(X)
else:
  p = list(map(int,input().split(" ")))
  for k in range(200):
    temp = X-k
    if temp not in p:
      print(temp)
      break
    semp = X+k
    if semp not in p:
      print(semp)
      break

Submission status: Accepted

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

Submission status: Accepted

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

try:
    p = list(map(int, input().split()))
except EOFError:
    print(X)
    exit()

i = 0
while True:
    tmp1 = X - i
    tmp2 = X + i

    if tmp1 not in p:
        print(tmp1)
        exit()
    if tmp2 not in p:
        print(tmp2)
        exit()

    i += 1

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# arr=input().strip().split(' ')
def aa():
    x,n=[int(i) for i in input().strip().split(' ')]
    if n==0:
        print(x)
        return 
    arr=[int(i) for i in input().strip().split(' ')]
    # neg,pos=[],[]
    # for i in arr:
    # 	if x-i >0 :
    # 		pos.append(x-i)
    # 	else:
    # 		neg.append(i-x)
    # pos=sorted(pos)
    # neg=sorted(neg)
    
    diff=[]
    for i in arr:

        diff.append(x-i)
    i=-1
    j=0
    while i in diff:
        i=i-1
    while j in diff:
        j=j+1
    if abs(i)<abs(j):
        print(x-i)
    else:
        print(x-j)
    # print(x+)
aa()

Submission status: Accepted

Solution code:
x , n = map(int , input().split())
b = []
if n!=0:
    b = list(map(int,input().split()))
t = 0
ans = 0
while 1:
    if x-t not in b:
        ans = x - t
        break
    if x+t not in b:
        ans = x + t
        break
    t += 1
print(ans)

Submission status: Accepted

Solution code:
def main():
    x,n=map(int,input().split())
    pp=set(map(int,input().split()))
    if x not in pp:
        print(x)
        return
    i=1
    while True:
        if x-i not in pp:
            print(x-i)
            return
        elif x+i not in pp:
            print(x+i)
            return
        i+=1

main()

Submission status: Accepted

Solution code:

def main():
    target, N = map(int, input().split())
    p = list(map(int, input().split()))

    for i in range(101):
        if target - i not in p:
            print(abs(target - i))
            return
        if target + i not in p:
            print(abs(target + i))
            return


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
X, N = map(int,input().split())
answer = 0
if N != 0:
  mapped_list = map(int,input().split())
  list = list(mapped_list)
  for i in range (N):
    if (X-i in list) == False:
      answer = X-i
      break
    elif (X+i in list) == False:
      answer = X+i
      break
else:
  answer =X

print(answer)

Submission status: Accepted

Solution code:

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



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

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

else:
    for i in range(0,101):
        if l.count(int(X))<1:
            print(int(X))
            break 


        elif l.count(int(X-i))<1:
            print(int(X-i))
            break 

    

        if X+i<=101:
            if l.count(int(X+i))<1:
                print(int(X+i))
                break

Submission status: Accepted

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


def main():
    import sys
    input = sys.stdin.readline

    x, n = map(int, input().split())
    p = list(map(int, input().split()))
    candidate = [i for i in range(-100, 200)]

    ans = list()

    for c in candidate:
        if c not in p:
            diff = abs(c - x)

            ans.append((diff, c))

    print(sorted(ans)[0][1])


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(0,101):
  if (X - i) not in p:
    print(X - i)
    break
  elif (X + i) not in p:
    print(X + i)
    break
  else:
    pass

Submission status: Accepted

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

w, cnt = 0, 0
while cnt < 201:
  if x + w not in p:
    print(x + w)
    break

  w += ((-1) ** cnt) * cnt
  cnt += 1

Submission status: Accepted

Solution code:
x,n = map(int, input().split())
p = list(map(int, input().split()))
for i in range(101):
  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:
I = lambda : list(map(int,input().split()))
x,n = I()
l=I()
for i in range(101):
  if (x-i) not in l:
    print(x-i);break
  elif (x+i) not in l:
    print(x+i);break