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 = input().split()

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

def check(x,n):
    # そもそも配列の数が0の場合は中断
    if int(n) == 0:
        print(x)
        return

    # 与えられた変数の配列
    p_list = input().split()

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

        # 片方
        if min_x not in p_list or max_x not in p_list:
            if min_x not in p_list:
                print(min_x)
                return
            
            if max_x not in p_list:
                print(max_x)
                return
        
        # 両方
        if min_x not in p_list and max_x not in p_list:
            print(min_x)
check(x,n)

Submission status: Accepted

Solution code:
X,N=map(int,input().split())
if N==0:
  print(X)
else:
  p=input().split()
  for i in range(N):
    p[i]=int(p[i])
    p[i]=X-p[i]
  i=0
  if i in p:
    while True:
      i+=1
      if i in p:
        if -i in p:
          pass
        else:
          print(X+i)
          break
      else:
        print(X-i)
        break
  else:
    print(X)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
ps = sorted(list(map(int, input().split())))
if x not in ps:
    print(x)
else:
    not_ps = [i for i in range(ps[0]-1, ps[-1]+2) if i not in ps]
    ans_min = 1000
    for not_p in not_ps:
        if abs(not_p-x) < ans_min:
            ans = not_p
            ans_min = abs(not_p-x)
    print(ans)

Submission status: Accepted

Solution code:
x,n= map(int, input().split())
if n!=0:
    p = list(map(int, input().split()))
else:
    p=[]
def func(x,n,p):
    if n==0:
        print(x)
        return
    if x not in p:
        print(x)
        return
    current = x
    for d in range(1,101,1):
        if current-d not in p:
            print(current-d)
            return
        elif current+d not in p:
            print(current+d)
            return
    print(x-101)
    return
func(x,n,p)

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


ans1=ans2=101
flag=0


for i in range(1,len(p)+1):


    if x+i not in p:
        ans1=x+i
        flag=1
    if x-i not in p:
        ans2=x-i
        flag=1
    if flag==1:
        break


# print(ans1,ans2)
print(min(ans1,ans2))

Submission status: Accepted

Solution code:
l = [int(i) for i in input().split()]
n = [int(i) for i in input().split()]
a = 0

while True:
  b = l[0] - a
  c = l[0] + a
  if b not in n:
    print(b)
    break
  elif c not in n:
    print(c)
    break
  else:
    a += 1

Submission status: Accepted

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

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()))
P.sort()
score = P[0]-1
for n in range(P[0]-1,P[N-1]+2):
  flag = True
  for m in range(N):
    if P[m]==n:
      flag = False
  if flag and abs(X-n)<abs(X-score):
    score = n
print(score)

Submission status: Accepted

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

# print(x,n)
# print(p)
flag = 0
temp = x
while(flag == 0):
    if x in p:
        x +=1        
    else:
        ans_p = x
        flag =1

x = temp
flag = 0

while(flag == 0):
    if x in p:
        x -=1        
    else:
        ans_n = x
        flag =1
# print(ans_p, ans_n)
abso_p = abs(ans_p-temp)
abso_n = abs(ans_n-temp)
if abso_p >= abso_n:
    print(ans_n)
elif abso_p < abso_n:
    print(ans_p)

Submission status: Accepted

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

    if y == 0:
        print(x)
        exit()
    nums = list(map(int, input().split()))
    ans = 0
    for i in range(1, 200):
        if i not in nums:
            ans = ans if abs(ans-x) <= abs(i-x) else i
    print(ans)



if __name__ == '__main__':
    main()

Submission status: Accepted

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

ab = 100
num = []
for i in range(102):
    if p.count(i)>0:
        continue
    abst = abs(i-x)
    if abst < ab:
        ab = abst
        num = [i]
    elif abst == ab:
        ab = abst
        num += [i]
print(min(num))

Submission status: Accepted

Solution code:
import math
import sys

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

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

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

p.sort()
# closest
ans = min(p, key=lambda y:abs(y-x))
idx = p.index(min(p, key=lambda y:abs(y-x)))

# print(p)
# print(ans, idx)

if x != ans:
    print(x)
    sys.exit()


cnt = idx
larger_near = p[cnt]
smaller_near = p[cnt]

while cnt < n:
    tmp = p[cnt]
    cnt += 1
    if cnt == n:
        larger_near = tmp + 1
        break
    elif p[cnt] != tmp + 1:
        larger_near = tmp + 1
        break

cnt = idx
while cnt >= 0:
    tmp = p[cnt]
    cnt -= 1
    if p[cnt] != tmp - 1:
        smaller_near = tmp - 1
        break

if abs(smaller_near - x) <= abs(larger_near - x):
    ans = smaller_near
else:
    ans = larger_near
print(ans)

Submission status: Accepted

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; 
        if arr[mid] == x: 
            return mid 
        elif arr[mid] < x: 
            l = mid + 1
        else: 
            r = mid - 1
    return -1


def main():
    a,b = cin()
    if b==0:
        c = cino(True)
        print(a)
    else:
        arr = cina()
        arr.sort()
        init = 1
        if bs(arr,0,b-1,a)==-1:
            print(a)
        else:
            o,t = bs(arr,0,b-1,a-init),bs(arr,0,b-1,a+init)
            while o>=0 and t>=0:
                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: Accepted

Solution code:
import sys
x,n=map(int,input().split())
q=list(map(int,input().split()))
q=q+[100000000]
p=list(map(lambda i:abs(x-i),q))

p.sort()
if n==0:
  print(x)
  sys.exit()
for i in range(len(p)):
  if p[i]!=(i+1)//2:
    if i==0:
      print(x)
      sys.exit()
    elif i==1:
      print(x-1)
      sys.exit()
    elif p[i-1]==p[i-2]:
      print(x-p[i-1]-1)
      sys.exit()
    else:
      if x-p[i-1] in q:
        print(x+p[i-1])
      else:
        print(x-p[i-1])
      sys.exit()

Submission status: Accepted

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

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

P.sort()
for i in range(N):
	if P[i] > X:
		print(X)
		break
	elif P[i] == X:
		#下に
		under = X
		underflag = False
		upper = X
		upperflag = False
		for j in range(i):
			if P[i - j - 1] != X - j - 1:
				under = X - j - 1
				underflag = True
				break
		if underflag == False:
			under = P[0] - 1

		for j in range(N - i - 1):
			if P[i + j + 1] != X + j + 1:
				upper = X + j + 1
				upperflag = True
				break
		if upperflag == False:
			upper = P[N - 1] + 1
		print(under if abs(X - under) <= abs(X - upper) else upper)
		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={}
  for i in p:
    d=abs(i-x)
    if d in dic:
      dic[d].append(i)
    else:
      dic[d]=[i]
  sortdic = sorted(dic.items(), key=lambda x:x[0])
  chk=0
  ans=-1
  for k,v in sortdic:
    if chk==k:
      if chk!=0 and len(v)!=2:
        if v[0]>x:
          ans=x-k
        else:
          ans=x+k
        break
    else:
      ans=x-chk
      break
    chk+=1
  if ans==-1:
    ans=x-chk
  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()))
    mylist = list(range(0,10000))


    for i in range(N):
        if (p[i] in mylist)==True:
            mylist.remove(p[i])

    mylist2 = list(map(lambda a: abs(a - X), mylist))

    
    p=mylist2.index(min(mylist2))

    print(mylist[p])

Submission status: Accepted

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

num_list = list(range(-200,201))
y = (num_list + p)

counter = Counter(y)
result =  [elem for elem in y if counter[elem] < 2]


ans = 10 *100000000000

for i in result:
    temp = abs(i - x)
    if ans > temp:
        ans = temp
        res = i
print(res)

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 x not in p:
        print(x)
    else:
        for i in range(200):
            if x-i not in p:
                print(x-i)
                break
            if x+i not in p:
                print(x+i)
                break

Submission status: Accepted

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

  
s1=1000
s2=1000
i=0

for ii in range(n+1):
  #print((x+i),(x-i))
  if (x+i) not in p:
    s1 = (x+i)
  if (x-i) not in p:
    s2= (x-i)
  i+=1
  #print(i)
  if s1 != 1000 or s2 != 1000:
    break

if s1 > s2:
  if s2 != 1000:
    print(s2)
  else:
    print(s1)
else:
  if s1 != 1000:
    print(s1)
  else:
    print(s2)

Submission status: Accepted

Solution code:
x,n = map(int, input().split())
if n ==0:
  num =[0]
else:
  num = input().split()
num = [int(x) for x in num]
min_num = min(num)
max_num = max(num)
num_list = list(range(min_num-1, max_num+2))
for de in range (len(num)):
  num_list.remove(num[de])
num_list.append(x)
num_list.sort()
tar = num_list.index(x)
if tar == 0:
  li = x
else:
  li = num_list[tar-1]
if tar == (len(num_list)-1):
  bi = x
else:
  bi = num_list[tar+1]
if x-li ==  bi - x:
  print(li)
elif x-li > bi-x:
  print(bi)
else:
  print(li)

Submission status: Accepted

Solution code:
from bisect import bisect_left,bisect

x,N,*p = map(int,open(0).read().split())
dif = 300
near = 300
all_ = set(range(0,102))

for i in p:
    d = abs(i - x)
    if dif > d:
        dif = d
        near = i
left = list(all_ - set(p))        

dif2 = 300
near = 300
for i in left:
    d = abs(x-i)
    if d < near:
        near = d
        dif2 = i
print(dif2)

Submission status: Accepted

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

def solve():
    X, N = list(map(int, input().split()))
    Ps = list(map(int, input().split()))

    if N == 0:
        print(X)
        return

    setP = set(Ps)

    ans = float("inf")
    for x in range(0, 102):
        if not x in setP:
            if abs(X-ans) > abs(X-x):
                ans = x

    print(ans)


if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
x, n = map(int,input().split())
lis = list(map(int,input().split()))
lis.sort()
if n == 0:
    print(x)
else:
    for i in range(lis[n-1]+2):
        
        if i < x and i not in lis:
            a = i
        if i >= x and i not in lis:
            b = i
            if abs(a-x) <= abs(b-x):
                print(a)
            else:
                print(b)
            break

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**20
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()

def resolve():
    X, N = LI()
    if N == 0:
        print(X)
        return

    p = LI()

    p_max = max(p)
    p_min = min(p)

    if X < p_min or p_max < X:
        print(X)
        return
    else:
        d = [abs(i-X) for i in range(0, 102) if i not in p]
        d_min = min(d)
        for i in range(0, 102):
            if i not in p:
                if abs(i-X)==d_min:
                    print(i)
                    return

if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
X,N=map(int,input().split())
P=list(int(x) for x in input().split())
if X not in P:
	print(X)
	exit()
i=0
while True:
	i+=1
	j=X-i*1
	k=X+i*1
	if j not in P:
		print(j)
		exit()
	elif k not in P:
		print(k)
		exit()

Submission status: Accepted

Solution code:
s = input().split()

x = int(s[0])
n = int(s[1])

s = {i for i in range(-1,102)}

p1 = input().split()

p = set()

for i in p1:
    p.add(int(i))

t = s - p

answer = 20000

for i in t:
    if (abs(x - int(i)) < abs(x - answer)) or (abs(x - int(i)) == abs(x - answer)) and i < answer:
        answer = int(i)

print(answer)

Submission status: Accepted

Solution code:
x , n =  map(int, input().split())
P = [int(i) for i in input().split()]
test = [int(i) for i in range(0,102)]
a = []
for i in range(n):
    test.remove(P[i])
for j in test:
    a.append( abs(x-j) )
ind = a.index(min(a))
print(test[ind])

Submission status: Accepted

Solution code:
li = []
for i in range(102):
    li.append(i)
lis = set(li)
x,n = map(int,input().split())
if n == 0:
    print(x)
    exit()
lia = list(map(int,input().split()))
lias = set(lia)
seta = lis - lias
li = list(seta)
li.reverse()
a = 1000
for i in range(102-n):
    if abs(li[i]-x) <= a:
        a = abs(li[i]-x)
        b = li[i]
print(b)

Submission status: Accepted

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

result = 0
if N == 0:
    result = X
else:
    list = [i for i in range(201)]
    for i in P:
        list.remove(i)
    if len(list) == 0:
        result = 0
    else:
        min = 100
        for i in list:
            if min > abs(X-i):
                min = abs(X - i)
                result = i
print(result)

Submission status: Accepted

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

p1 = [abs(i-x) for i in p]

p = set(p)
p1.sort()
if len(p1) ==0:
    print(x)
else:
    if p1[0] != 0:
        print(x)
    else:
        cnt = 1
        while(cnt < len(p1)):
            #print("------")
            #print(cnt)
            #print(p1[cnt])
            if p1[cnt] != int((cnt+1)/2):
                break
            else:
                cnt +=1
        #import pdb;pdb.set_trace()
        if x-int((cnt+1)/2) in p:
            print(x+int((cnt+1)/2))
        else:
            print(x-int((cnt+1)/2))

Submission status: Accepted

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

if x in listp:
    for i in range(1,101):
        a = x + i
        b = x - i
        if a in listp and b in listp:
            continue
        else:
            if not a in listp:
                ans.append(a)
            
            if not b in listp:
                ans.append(b)

            if len(ans) > 0:
                break
else:
    print(x)
    exit()

print(min(ans))

Submission status: Accepted

Solution code:
a,b=map(int,input().split())
if b==0:
  print(a)
  exit()
s=list(map(int,input().split()))

lst=[i for i in range(0,202)]
for j in range(b):
  lst.remove(s[j])


n=100
for k in lst:
  m=abs(a-k)
  n=min(n,m)

if (a-n) in lst:
  print(a-n)
  exit()
else:
  print(a+n)

Submission status: Accepted

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

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

P = [int(i) for i in input().split()]
mn = 1000
for i in reversed(range(102)):
	if i in P:
		continue
	if mn >= abs(X-i):
		ans = i
		mn = min(mn,abs(X-i))

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect
X,N=map(int,input().split())
if N==0:
    print(X)
    exit()
P=sorted(list(map(int, input().split())))
key=bisect.bisect_right(P,X)
small=101
large=0

for i in range(N):
    if P[key-1]-i not in P:
        small=P[key-1]-i
        break
for i in range(N):
    if P[key-1]+i not in P:
        large=P[key-1]+i
        break
print(small if abs(X-small)<=abs(X-large) else large)

Submission status: Accepted

Solution code:
def main():
    import sys
    X, N = map(int, sys.stdin.readline().split())
    P = list(map(int, sys.stdin.readline().split()))
    
    i = 0
    while True:
        if X-i in P:
            pass
        else:
            print(X-i)
            break
        if X +i in P:
            pass
        else:
            print(X+i)
            break
        i+=1
    


if __name__=='__main__':
    main()

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(101):
    p = X - i not in P
    p1 = X + i not in P
    if p1 or p:
        if p:
            print(X - i)
            exit()
        print(X + i)
        exit()

Submission status: Accepted

Solution code:
X,N=list(map(int,input().split()))
src=list(map(int,input().split()))
all_diff_src = [X-n for n in range(0,102) if n not in src]
ans = 101
for s in all_diff_src:
  if ans > abs(s):
    ans = s
print(X-ans)

Submission status: Accepted

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

px = x + 1
mx = x - 1
if n == 0:
    print(x)
    exit()
elif x not in p:
    print(x)
    exit()

while True:
    if mx not in p:
        print(mx)
        exit()
    elif px not in p:
        print(px)
        exit()
    px += 1
    mx -= 1

Submission status: Accepted

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

INF = 999
x_flg = True
x_plus = []
x_minus = []
for i in range(0, n):
    x_plus.append(x+i+1)
    x_minus.append(x-(i+1))

for p_num in p:
    if p_num == x:
        x_flg = False

    if p_num in x_plus:
        x_plus.remove(p_num)

    if p_num in x_minus:
        x_minus.remove(p_num)

if x_flg:
    print(x)
else:
    x_plus_min = min(x_plus) if len(x_plus) > 0 else INF
    x_minus_max = max(x_minus) if len(x_minus) > 0 else INF
    xp = abs(x-x_plus_min)
    xm = abs(x-x_minus_max)
    if xp < xm:
        print(x_plus_min)
    elif xp >= xm:
        print(x_minus_max)

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
nump = list(map(int,input().split()))
nump.sort()
x_ind = -1
nump_io = [0]*103
for i in range(n):
    nump_io[nump[i]-1] = 1
    if(nump[i]==x):
        x_ind = i
if(x_ind == -1):
    print(x)
else:            
    for i in range(1,51):
        if(nump_io[(x-1)-i] == 0):
            print(x-i)
            break
        if(nump_io[(x-1)+i] == 0):
            print(x+i)
            break
# print(nump_io)

Submission status: Accepted

Solution code:
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
import math
from copy import deepcopy
import queue
import numpy as np
# sympy as syp(素因数分解とか)
Mod = 1000000007
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1] 
for i in range(2, 10**5 + 1):
    fact.append((fact[-1] * i) % Mod)
    inv.append((-inv[Mod % i] * (Mod // i)) % Mod)
    factinv.append((factinv[-1] * inv[-1]) % Mod)
    
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n - r] % p
    
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[y] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)

def main():  #startline-------------------------------------------
    x, n = map(int, input().split())
    numlist = [i for i in range(102)]
    p = list(map(int, input().split()))
    for i in range(101):
        if numlist[i] in p:
            numlist[i] = -1
    ans = float("inf")
    memo = 101
    for i in range(102):
        if numlist[i] == -1: continue
        if ans > abs(numlist[i] - x):
            ans = abs(numlist[i] - x)
            memo = i
    print(memo)
if __name__ == "__main__":
    main() #endline===============================================

Submission status: Accepted

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

for i in range(1000):
    if X-i not in p:
        print(X-i)
        break
    if X+i not in p:
        print(X+i)
        break

Submission status: Accepted

Solution code:
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def main():
	#a = int(input())
	x, n = tin()
	#s = input()
	al = set(lin())
	mm=5000
	mv=-1000
	for i in range(-100,200):
		if abs(i-x) < mm and i not in al:
			mm = abs(i-x)
			mv = i
	print(mv)
	
	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Accepted

Solution code:
X, N = map(int,input().split())
P = list(map(int,input().split()))
ans = 0
def f(X,N,P):
  if(N==0):
    ans = X
    return ans
  else:
    for i in range(N+1):
      if(not (X-i in P)):
        ans = X-i
        return ans
      elif(not (X+i in P)):
        ans = X+i
        return ans
print(f(X,N,P))

Submission status: Accepted

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

cnt=0

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
x, n = map(int, input().split())

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

    ans = 0
    
    for i in range(100):
        numm = x - i
        nump = x + i

        if not(numm in arg):
            ans = numm
            break
        
        elif not (nump in arg):
            ans = nump
            break

    print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8

############################

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

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

z=101
p_list = list(map(int,input().split()))
pp_list = [i for i in range(102)]

for j in p_list:
    pp_list.remove(j)

for k in pp_list:
    zettaiti = abs(x-k)

    if z > zettaiti:
        z = zettaiti
        ans = k

print(ans)

Submission status: Accepted

Solution code:
# coding:utf-8
x, n = map(int, input().split())
p = list(map(int, input().split()))


if n == 0:
    print(x)
else:
    ps = sorted(p)
    tmp = list(range(-201, 200))
    ans_list = list(set(tmp) ^ set(ps))
    ans_list = sorted(ans_list)
    # print(tmp, ans_list)
    diff = []

    for i in ans_list:
        diff.append(abs(i - x))

    print(ans_list[diff.index(min(diff))])

Submission status: Accepted

Solution code:
def main():
  X, N = map(int, input().split())
  if N == 0:
    return X
  
  P = list(map(int, input().split()))
  
  delta = []
  for n in range(-1, 102):
    if n in P:
      delta.append(float('inf'))
    else:
      delta.append(abs(X - n))
      
  minD = min(delta)
  for i, d in enumerate(delta):
    if d == minD:
      return i - 1


print(main())

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()
  q=list(range(-5,102))

  for i in p:
    q.remove(i)

  Z=1000
  for i in q:
    if( abs(X-i)<Z):
      Z=abs(X-i)
      ans=i
  
  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()))
  flag = True
  i = 0
  ans_min = 2**8
  while flag:
    cand = X - i
    if not cand in p:
      ans_min = cand
      flag = False
    cand = X + i
    if not cand in p:
      ans_max = cand
      flag = False
    i += 1
    
  if ans_min != 2**8:
    print(ans_min)
  else:
    print(ans_max)

Submission status: Accepted

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

if X not in p:
    print(X)


else:
    c = list(set([i for i in range(102)]) ^ set(p))
    c_x = [abs(c_-X) for c_ in c]
    print(c[c_x.index(min(c_x))])

Submission status: Accepted

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

for i in range(101):
    a = int(x - i)
    b = int(x + i)
    if a not in p:
        print(a)
        exit()
    elif b not in p:
        print(b)
        exit()

Submission status: Accepted

Solution code:
def main():
    X,N = map(int, input().split())
    if N ==0:
        print(X)
        return 0
    p = list(map(int, input().split()))
    for i in range(51):
        if not (X-i) in p:
            print(X-i)
            return 0
        elif not (X+i) in p:
            print(X+i)
            return 0
          
main()

Submission status: Accepted

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

def calc():
    x, n = [int(x) for x in input().split()]

    if n == 0:
        q = [x for x in range(102)]
    else:
        p = [int(x) for x in input().split()]
        q = [x for x in range(102) if x not in p]
    diffs = [abs(x - qk) for qk in q]
    mindiff = min(diffs)
    idx = diffs.index(mindiff)
    print(q[idx])

calc()

Submission status: Accepted

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

Submission status: Accepted

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

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

for i in range(100):
  pl = x+i
  mn = x-i
  if x-i not in p:
    print(x-i)
    break
  if x+i not in p:
    print(x+i)
    break

Submission status: Accepted

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

import sys


def input():
    return sys.stdin.readline()


def resolve():
    x, n = map(int, input().split())

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

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

    max_p = 100
    not_p_list = []


    flag = False
    for j in range(-max_p-1, max_p):
        j1 = j+1
        if j1 in p_list:
            pass
        else:
            not_p_list.append(j1)
    not_p_list.append(101)
    #print(not_p_list)

    min_num = 999
    ans = 0

    for i in not_p_list:

        m = abs(x - i)
        if min_num >= m:
            if min_num == m:
                continue
            min_num = m
            ans = i

    print(ans)

if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
def main():
	x, n = map(int, input().split())
	P = list(map(int, input().split()))
	if n == 0:
		print(x)
		return
	ans = 0
	min_dis = 1000
	for item in range(102):
		if item in P:
			continue
		dis = abs(item - x)
		if min_dis > dis:
			min_dis = dis
			ans = item
	print(ans)
	return

if __name__ == "__main__":
	main()

Submission status: Accepted

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

m_diff = 0
b_diff = 0

m = x
while m in ps:
    m_diff += 1
    m -= 1

b = x
while b in ps:
    b_diff += 1
    b += 1

if (m_diff > b_diff):
    print(b)
else:
    print(m)

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