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.

Solution (Python):
import numpy as np

a = list(map(int, input().split()))
if a[1] == 0:
    print(a[0])
else: 
    b = list(map(int, input().split()))
    c = list(set([i for i in range(200)]) - set(b))
    idx = np.abs(np.asarray(c) - a[0]).argmin()
    print(c[idx])

Solution (Python):
import sys
X,N = map(int,input().split())
if N == 0:
    print(X)
    sys.exit()    
else:
    P = list(map(int,input().split()))
flaga = 0
flagb = 0

for i in range(100):
    a = X - i
    b = X + i
    if (a in P)== 0:
        flaga = 1
    if (b in P)== 0:
        flagb = 1
    if flaga ==1 or flagb ==1:
        break

if flaga ==1 and flagb ==1:
    print(min(a,b))
elif flaga ==1 and flagb ==0:
    print(a)
else:
    print(b)

Solution (Python):
x, n = map(int, input().split())
if n == 0:
    print(x)
else:
    p = [int(x) for x in input().split()]
    for i in range(n + 1):
        if not x - i in p:
            print(x - i)
            break
        elif not x + i in p:
            print(x + i)
            break
        else:
            continue

Solution (Python):
import numpy as np

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

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

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


for i in range(101):
    if sum(P == X - i) == 0:
        print(X - i)
        exit(0)
    if sum(P == X + i) == 0:
        print(X + i)
        exit(0)

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

if n == 0:
    
    print(x)
else:
    l = list(map(int, input().split()))
    l.sort()
    small = x
    large = x
    while small in l and large in l:
        small -= 1
        large += 1
    if small in l:
        print(large)
    elif large in l:
        print(small)
    elif x - small > large - x:
        print(large)
    else:
        print(small)

Solution (Python):
from sys import stdin

A = list(map(int,stdin.readline().split()))
B = list(map(int,stdin.readline().split()))
C = [x for x in range(-10,110)]
C = set(C)
B = set(B)
C = C.difference(B)
C = list(C)
X=A[0]
N=A[1]
record=200
number=1000
K=0

if N==0:
    print(X)
    K=1

for t in C:
    diff=abs(t-X)
    if diff<record:
        record=diff
        number=t
    elif diff==record:
        number=min(number,t)

if K==0:
   print(number)

Solution (Python):
import sys



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


if N ==0:
    print(X)
    sys.exit()
    
if X not in P:
    print(X)
    sys.exit()
cnt= 1
while True:
    
    if (X -cnt) not in P:
        print(X-cnt)
        sys.exit()
    elif (X+cnt) not in P:
        print(X+cnt)
        sys.exit()
    cnt += 1

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

exist = 0
ans = -1

if N == 0:
    ans = X

for i in range(100):
    LX = X - i
    exist = 0
    for j in range(N):
        if LX == p[j]:
             exist = 1
    if exist == 0:
        ans = LX
        break

    HX = X + i
    exist = 0
    for k in range(N):
        if HX == p[k]:
            exist = 1
    if exist == 0:
        ans = HX
        break

print(ans)

Solution (Python):
x,n = map(int,input().split())
 
if n != 0:
    p = list(map(int,input().split()))
 
s = []
 
for i in range(-1,102):
    s.append(i)
    
if n != 0:
    for i in p:
        s.remove(i)
 
if n == 0:
    print(x)
else:
    if x in s:
        print(x)
    elif x<s[0]:
        print(s[0])
    elif x>s[-1]:
        print(s[-1])
    else:
        for i in range(len(s)-1):
            if s[i]<=x<=s[i+1]:
                if abs(x-s[i])<abs(x-s[i+1]):
                    print(s[i])
                elif abs(x-s[i])==abs(x-s[i+1]):
                    print(s[i])
                else:
                    print(s[i+1])
                break

Solution (Python):
X, N = map(int, input().split())
plist = [int(i) for i in input().split()]

x = 0
hx = -1
while True:
    px = x
    nx = -x
    if X + nx not in plist: 
        hx = nx
        break
    if X + px not in plist:
        hx = px
        break
    x += 1
print(X+hx)

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

l.sort()

if x not in l:
    print(x)
    exit()
else:
    a = l.index(x)

if a == n-1:
    if l[a-1] == x-1:
        print(x+1)
        exit()
    else:
        print(x-1)
        exit()
elif a == 0:
    print(x-1)
    exit()
    
p=a-1
f=a+1
while p >= 0 and f <= n-1:
    if l[p] < x-(a-p):
        print(x-(a-p))
        exit()
    elif l[f] > x+(f-a):
        print(x+(f-a))
        exit()
    p -= 1
    f += 1

if p == -1:
    print(l[0]-1)
elif f == n:
    print(l[-1]+1)

Solution (Python):
X,N = map(int,input().split())
arr = list(map(int,input().split()))
if X not in arr:
    print(X)
    exit()
sx = X+1
mx = X-1
ans = []
while 1:
    if sx not in arr:
        ans.append(sx)
        break
    sx += 1
while 1:
    if mx not in arr:
        ans.append(mx)
        break
    mx -= 1
if abs(ans[0]-X) < abs(ans[1]-X):
    print(ans[0])
elif abs(ans[0]-X) < abs(ans[1]-X):
    print(ans[1])
else:
    print(min(ans))

Solution (Python):

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

import bisect as bis
p.sort()
now = x
k = 1

for i in range(150):
    pm = k * (-1)**k
    index = bis.bisect_left(p, now)
    if index < len(p) and p[index] == now:
        now += pm
        k += 1
    else:
        print(now)
        break

Solution (Python):
x, n = map(int, input().split())
s = list(map(int, input().split()))
for j in range(n):
    s[j] = s[j] - x

i = 0
while True:
    if -i not in s:
        print(x-i)
        exit()
    if i not in s:
        print(x+i)
        exit()
    i += 1

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

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

import sys
if n == 0:
    print(x)
else:
    sa_min = 1000000
    for i in range(-110, 210):
        if i not in p_list:
            if sa_min > abs(i - x):
                sa_min = abs(i - x)
                ans = i
    print(ans)

Solution (Python):
import sys
x,n=map(int,input().split())
if n==0:
  print(x)
  sys.exit()
p=list(map(int,input().split()))
jud=[0 for i in range(102)]
for i in p:
  jud[i]=1
if jud[x]==0:
  print(x)
  sys.exit()
diff=1
while 1:
  if x >= diff and jud[x-diff]==0:
    print(x-diff)
    break
  if x + diff < 102 and jud[x+diff]==0:
    print(x+diff)
    break
  diff+=1

Solution (Python):
def gen(X):
    x = X
    yield x
    d = 1
    while True:
        yield X - d
        yield X + d
        d += 1
def main():
    X, N = map(int, input().split())
    P = set(map(int, input().split()))

    for x in gen(X):
        if x not in P:
            print(x)
            return

if __name__ == '__main__':
    main()

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

li = []


for i in range(-101, 201):
    if not i in p:
        li.append(i)

zzz = float('inf')

for i in li:
    if zzz > abs(x - i):
        zzz = abs(x - i)
        ans = i


print(ans)

Solution (Python):
x, n = map(int, input().split())
p = list(map(int, input().split()))
q = []
cnt = 1000
ans = 0

for i in range(0,102):
    if not i in p:
        q.append(i)
        
for i in q:
    if cnt > abs(x-i):
        ans = i
        cnt = abs(x-i)
print(ans)

Solution (Python):
x,n=map(int,input().split())
p=list(map(int,input().split()))
for i in range(1000):
    if x-i in p:
        pass
    else:
        print(x-i)
        break
    if x+i in p:
        pass
    else:
        print(x+i)
        break

Solution (Python):
import sys
input = sys.stdin.readline

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

for i in range(x+1):
    if i+x not in PS and x-i not in PS:
        print(min(i+x, x-i))
        break
    elif i+x not in PS:
        print(i+x)
        break
    elif x-i not in PS:
        print(x-i)
        break

Solution (Python):
import numpy as np
x,n = map(int, input().split())
if n != 0:
    p = list(map(int, input().split()))
if n == 0:
    print(x)
    exit()
ll = np.ones(1)*(-1)
for i in range(102):
    ll = np.append(ll,int(i))
    
for j in p:
    ll= ll[~(ll == j)]

if len(ll) == 0:
    print(x)
    exit()


a = np.zeros(len(ll))
for i in range(len(ll)):
    a[i]=abs(x-ll[i])

print(int(ll[np.argmin(a)]))

Solution (Python):
x,n=map(int,input().split())
P=list(map(int,input().split()))
Q=P.copy()

for i in range(n):
    P[i]=abs(P[i]-x)
P.sort()
count = -1
for i in range(n):
    if (i+1)//2 == P[i]:
        continue
    else:
        count=(i+1)//2
        break

if n%2==0 and count==-1:
    count=n//2
elif n%2==1 and count==-1:
    count=(n+1)//2

if n==0:
    print(x)
elif x-count in Q:
    print(x+count)
else:
    print(x-count)

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

    check = [True]*10001

    for i in p:
        check[i] = False

    mini = 100000
    index = 1

    for i in range(0,1001):
        if check[i]:
            if mini > abs(x-i):
                
                mini = abs(x-i)
                index = i

    
    for i in range(1,1001):
        if mini >= abs(x+i):
            
            mini = abs(x+i)
            index = -i

    print(index)

Solution (Python):
import math
x, n = map(int, input().split())
if n == 0:
    print(x)
else:
    pn = list(map(int, input().split()))
    flag = 0
    if x not in pn:
        print(x)
    else:
        a,b = x-1, x+1
        while flag == 0:
            if a not in pn:
                print(a)
                flag = 1
            elif b not in pn:
                print(b)
                flag = 1
            else:
                a -= 1
                b += 1

Solution (Python):
X,N=map(int,input().split())
p=set(map(int,input().split()))
if X not in p:
	print(X)
else:
	x=X-1
	while x in p:
		x-=1
	y=X+1
	while y in p:
		y+=1
	a,b=X-x,y-X
	if a==b:
		if x<y:
			print(x)
		else:
			print(y)
	elif a<b:
		print(x)
	else:
		print(y)

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

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

p.sort()
tmp = [i for i in range(-111, 111)]
for i in p:
        tmp.remove(i)

ans_num = float("Inf")
ans_i = 0
for i in range(len(tmp)):
        if abs(X - tmp[i]) < ans_num:
                ans_num = abs(X - tmp[i])
                ans_i = i


print(tmp[ans_i])

Solution (Python):
import sys
input = sys.stdin.readline
x, n = map(int, input().split())
p = [int(s) for s in input().split()]
p_abs = [abs(s-x) for s in p]
if 0 not in p_abs:
  print(x)
  sys.exit()
for j in range(1, 101):
  ans = [i for i, x in enumerate(p_abs) if x == j]
  
  if len(ans)==1:
    print(x + (x - p[ans[0]]))
    sys.exit()
  if len(ans)==0:
    print(x-j)
    sys.exit()

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

tmp = 1000
result = []
result2 = []
for i in range(0, 102):
    if i in A:
        continue

    hoge = abs(X - i)
    if hoge <= tmp:
        tmp = hoge
        result2.append(tmp)
        result.append(i)

result3 = []
for i, v in enumerate(result2):
    if v == min(result2):
        result3.append(result[i])

print(min(result3))

Solution (Python):
x,n = map(int,input().split())
p = list(map(int,input().split()))
min_num = 1000
num = x
for i in range(1000):
    if i not in p:
        if abs(x-i) < min_num:
            min_num = abs(x-i)
            num = i
print(num)

Solution (Python):
x, n = map(int, input().split())
try:
  p = list(map(int,input().split()))
except EOFError:
  p = [0]

ans = 0
i = 0
flag = 1

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

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

Ps = list(map(int,input().split()))
A_small=0
A_big=0


for i in range(101):
    A_small=X-i
    if A_small in Ps:
        continue
    else:
        break
for i in range(101):
    A_big=X+i
    if A_big in Ps:
        continue
    else:
        break
if A_big-X >= X-A_small:
    print(A_small)
else:
    print(A_big)

Solution (Python):
X,N = map(int,input().split())
P = list(map(int,input().split()))
for i in range(N):
    if not (X-i in P):
        print(X-i)
        exit()
    elif not (X+i in P):
        print(X+i)
        exit()
if N == 0:
    print(X)
else:
    print(0)

Solution (Python):

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


if N == 0:
    print(X)
else:
    P.sort()

    idx = N-1
    num = P[-1]
    for i in range(N):
        if X <= P[i]:
            idx = i
            num = P[idx]
            break

    for i in range(idx, -1, -1):
        if i == 0:
            low = P[i]-1
            break
        
        if P[i]-1 != P[i-1]:
            low = P[i]-1
            break

    for i in range(idx, N):
        if i == N-1:
            high = P[i]+1
            break
        
        if P[i]+1 != P[i+1]:
            high = P[i]+1
            break

    
    print(low if X-low <= high-X else high)

Solution (Python):
l=[]
for i in range(-100,201):
    l.append(i)
x,n=map(int,input().split())
p=list(map(int,input().split()))
flag=False
if p.count(x)==0:
    print(x)
    flag=True
for i in range(n):
    if p[i]!=x:
        l.remove(p[i])
a=l.index(x)
if not flag:
    if abs(x-l[a-1])<=abs(x-l[a+1]):
        print(l[a-1])
    else:
        print(l[a+1])

Solution (Python):
x,n = map(int,input().split())
p = [int(x) for x in input().split()]
all = list(range(102))
p_set = set(p)
p_all = set(all)
p_nokori = p_all - p_set
nokori = list(p_nokori)
import bisect
n = bisect.bisect_left(nokori,x)

left = x - nokori[n-1]
right = nokori[n] -x

if left <= right:
    print(nokori[n-1])
else:
    print(nokori[n])

Solution (Python):
if __name__ == '__main__':
	x,n = map(int,input().split())
	p = [int(a) for a in input().split()]
	p.sort()
	if x in p:
		m = 100
		ans = 0
		for i in range(-10,200):
			if not i in p:
				v = abs(i-x)
				if m > v:
					m = v
					ans = i
		print(ans)
	else:
		print(x)

Solution (Python):
x,n = map(int,input().split())
if n==0: exit(print(x))
p = list(map(int,input().split()))
p.sort()
if x not in p: exit(print(x))
h=101
l=0
for i in range(x,101):
    if i not in p:
        h = i
        break
for i in range(x,0,-1):
    if i not in p:
        l = i
        break
if abs(x-h)>=abs(x-l): print(l)
if abs(x-l)>abs(x-h): print(h)

Solution (Python):
import sys
x,n=map(int,input().split())
if n==0:
  print(x)
  sys.exit()
p=list(map(int,input().split()))
p.sort()
if p[n-1]<x or x<p[0]:
  print(x)
  sys.exit()
lst=[]
for i in range(n-1):
  if p[i+1]-p[i]>1:
    for j in range(p[i+1]-p[i]-1):
      lst.append(p[i]+j+1)
if len(lst)==0:
  if abs(p[0]-1-x)<=abs(p[n-1]+1-x):
    print(p[0]-1)
    sys.exit()
  else:
    print(p[n-1]+1)
    sys.exit()
if abs(p[0]-1-x)<=abs(p[n-1]+1-x):
  d=abs(p[0]-1-x)
  idx=-2
else:
  d=abs(p[n-1]+1-x)
  idx=-1
for i in range(len(lst)):
  if d>abs(lst[i]-x):
    d=abs(lst[i]-x)
    idx=i
  elif d==abs(lst[i]-x):
    if idx==-1:
      idx=i
if idx==-2:
  print(p[0]-1)
if idx==-1:
  print(p[n-1]+1)
else:
  print(lst[idx])

Solution (Python):
import numpy as np

def getNearestValue(list, num):
    
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]

x, n = map(int, input().split())
p = list(map(int, input().split()))
if n == 0:
  print(x)
else:
  l = list(range(102))
  for i in p:
    l.remove(i)
  print(getNearestValue(l, x))

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

if N == 0:
    print(X)
else:
    for i in range(100):
        
        left = X - i
        right = X + i

        if left not in p:
            print(left)
            break
        if right not in p:
            print(right)
            break

Solution (Python):
intX, length = map(int, input().split())
intList = input().split()
intList = [int(x) for x in intList]

for i in range(intX + 1):
    if intX - i not in intList:
        print(intX - i)
        break
    elif intX + i not in intList:
        print(intX + i)
        break

Solution (Python):
def solve():
    X, N = [int(x) for x in input().split()]
    if N > 0:
        pn = [int(x) for x in input().split()]
    else:
        pn = []
    pn = set(pn)
    ans = X
    if N == 0 or X not in pn:
        return ans
    left = 0
    right = 0
    while True:
        left += 1
        if (X - left) not in pn:
            return X - left
        right += 1
        if (X + right) not in pn:
            return X + right


if __name__ == '__main__':
    print(solve())

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

for i in range(200):
    ans1 = x - i
    ans2 = x + i
    if ans1 not in p:
        print(ans1)
        break
    if ans2 not in p:
        print(ans2)
        break

Solution (Python):
X, N = map(int, input().split())
if N == 0:
    print(X)
else:
    p = sorted(map(int, input().split()))
    nums = [num for num in range(102) if not num in p]
    A = [abs(num - X) for num in nums]
    print(nums[A.index(min(A))])

Solution (Python):
X, N = map(int, input().split())
p = []
if N != 0:
  p = list(map(int, input().split()))
d = 0
f = 0
while 1:
  if (X - d) not in p:
    print(X - d)
    break
  elif (X + d) not in p:
    print(X + d)
    break
  d += 1

Solution (Python):
X, N = [int(i) for i in input().split()]
if N == 0:
    print(X)
else:
    P = [int(i) for i in input().split()]
    ans = 0
    for i in range(100):
        if X - i < 1 or X - i not in P:
            ans = X - i
            break
        elif X + i > 100 or X + i not in P:
            ans = X + i
            break
    print(ans)

Solution (Python):
x, n = map(int, input().split())
p = list(map(int, input().split()))
r = 10**9 + 7

primeset = list(range(-1, 2*x))
trial = list(range(-1, 2*x))
for i in range(len(trial)):
    if trial[i] in p:
        trial[i] = r
    else:
        trial[i] = abs(x - trial[i])

ans = r + 100
trynow = r
for i in range(len(trial)):
    if trial[i] < trynow:
        trynow = trial[i]
        ans = primeset[i]

print(ans)

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

p.sort()

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

array = [0]*100
for i in range(N):
    array[p[i]-1] = 1

ans_smaller_x = 0
ans_bigger_x = 101

for i in range(X-2,-1,-1):
    if array[i] == 0:
        ans_smaller_x = i+1
        break

for i in range(X,100,1):
    if array[i] == 0:
        ans_bigger_x = i+1
        break

if abs(X - ans_smaller_x) == abs(X - ans_bigger_x):
    print(ans_smaller_x)
else:
    if abs(X - ans_smaller_x) > abs(X - ans_bigger_x):
        print(ans_bigger_x)
    else:
        print(ans_smaller_x)

Solution (Python):
X,N=map(int,input().split())
P=list(map(int,input().split()))
hako=set(P)

ans=[]
P.sort()
kari=[]
for i in range(102):
    if i not in hako:
        kari.append(i)
for i in range(len(kari)):
    ans.append([abs(X-kari[i]),kari[i]])
ans.sort()
print(ans[0][1])

Solution (Python):
from typing import List


def main(x: int, n: int, p: List[int]):
    if x not in p:
        print(x)
        return

    for i in range(1, max(p) + 1):
        if (x - i) not in p:
            print(x - i)
            return

        if (x + i) not in p:
            print(x + i)
            return


if __name__ == "__main__":
    x, n = map(int, input().split())
    p = list(map(int, input().split()))

    main(x, n, p)

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

if N == 0:
  print(X)
else:
  p = list(map(int,input().split()))
  for i in range(100):
    a = X + i
    b = X - i
    if b not in p:
      print(b)
      break
    if a not in p:
      print(a)
      break

Solution (Python):
X, N = map(int, input().split())
plis = list(map(int, input().split()))
lis = [i for i in range(102)]
for p in plis:
    lis.remove(p)
ans = float('inf')
for i in lis:
    if abs(i - X) < abs(ans-X):
        ans = i
print(ans)

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

	for i in range(0, 101):
		a = x-i
		b = x+i
		if a not in line:
			print(a)
			exit()
		if b not in line:
			print(b)
			exit()

Solution (Python):
inpt = input()
x = int(inpt.split()[0])
n = int(inpt.split()[1])
all = set(range(-1, 102))
ipt = set()
inpt = input().split()
for i in inpt:
    ipt.add(int(i))

sub = all - ipt
if len(sub) > 0:
    sub = list(sub)
    sub.sort()
now = int(100)
for i in sub:
    if (abs(x-i) < now):
        now = min(abs(x-i), now)
        ans = i


print(ans)

Solution (Python):
from collections import deque

X, N = [int(i) for i in input().split()]

nums = [int(i) for i in input().split()]

candidates = deque([X])
output = []

while True:
    c1 = candidates[0]
    c2 = candidates[-1]
    for c in [c1,c2]:
        if c not in nums:
            output.append(c)
    if len(output) > 0:
        break
    candidates.appendleft(candidates[0]-1)
    candidates.append(candidates[-1]+1)
    
print(min(output))

Solution (Python):
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))



def read_a_int(): return int(read())


def read_ints(): return list(map(int, read().split()))


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) 
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_tuple(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_matrix(H):
    '''H is number of rows'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    


MOD = 10**9 + 7
INF = 2**31  

from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  

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

P = read_ints()
for i in range(101):
    b = X + i
    a = X - i
    if a not in P:
        print(a)
        exit()
    if b not in P:
        print(b)
        exit()

Solution (Python):
X,N = map(int, input().split())
if N == 0:
    print(X)
else:
    p = list(map(int,input().split()))
    K = X
    L = 0
    for i in range(X,103):
        if i in p:
            continue
        else:
            K = i-X
            L = i
            break
    if L == X:
        print(X)
    else:
        for i in range(X-K,X):
            if i in p:
             continue
            else:
             L = i
        print(L)

Solution (Python):
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()
for i in range(1,100000000000):
  p_=x-i
  q=x+i
  if p_ not in p:
    print(p_)
    exit()
  if q not in p:
    print(q)
    exit()

Solution (Python):
abs, N = map(int,input().split())
if N:
    s = list(map(int,input().split()))
    flag = 1
else:
    flag = 0
cnt = 0
while flag:
    if not(abs - cnt) in s:
        result = abs - cnt
        break
    if not(abs + cnt) in s:
        result = abs + cnt
        break
    cnt += 1
if flag:
    print(result)
else:
    print(abs)

Solution (Python):
X, N = map(int, input().split())
if N == 0:
    Ps = {}
    print(X)
    exit()
else:
    Ps = set(list(map(int, input().split())))

all_numbers = set(list(range(0, 102)))

search_numbers = list(all_numbers - Ps)

absolute_value = 1000
out = X
for i in search_numbers:
    if abs(i - X) < absolute_value:
        absolute_value = abs(i - X)
        out = i

print(out)

Solution (Python):
import sys
from bisect import bisect_left

def main():
    X,N=map(int,input().split())
    P=list(map(int,input().split()))

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

    P.sort()

    ind=bisect_left(P,X)

    if (P[ind]!=X):
        print(X)
    else:
        left=ind-1
        right=ind+1
        leftX=X-1
        rightX=X+1

        flag=0
        while left>=0 or right<=N-1:
            if left>=0:
                if P[left]!=leftX:
                    print(leftX)
                    flag=1
                    break
            if right<=N-1:
                if P[right]!=rightX:
                    print(rightX)
                    flag=1
                    break

            left-=1
            right+=1
            leftX-=1
            rightX+=1

        if flag==0:
            left=ind+1
            right=(N-1)-ind+1
            if left<=right:
                print(X-left)
            else:
                print(X+right)


if __name__=="__main__":
    main()

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

if not x in p:
    print(x)
    exit()
up = x + 1
down = x - 1
while True:
    if not down in p:
        print(down)
        exit()
    elif not up in p:
        print(up)
        exit()
    up += 1
    down -= 1

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

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

a = False
x1 = x
while a == False:
    if x1 not in p:
        a = True
        break
    elif x1 in p:
        x1 -= 1

b = False
x2 = x
while b == False:
    if x2 not in p:
        a = True
        break
    elif x2 in p:
        x2 += 1

if abs(x - x1) > abs(x - x2):
    print(x2)
elif abs(x - x1) < abs(x - x2):
    print(x1)
elif abs(x - x1) == abs(x - x2):
    print(x1)

Solution (Python):
x,n = map(int, input().split())
p =list(map(int, input().split()))
m = 10**10
ans = 10**10
if n == 0:
    print(x)
    exit()
for i in range(1000):
    if i in p:
        continue
    if m > abs(i-x):
        m = abs(i-x)
        ans = i
    elif m==abs(i-x):
        ans = min(ans,i)
print(ans)

Solution (Python):
x, n = map(int, input().split(" "))
p = input()
if p == "":
    print(x)
    exit(0)
p = list(map(int, p.split(" ")))
answer = 0
for i in range(1, 102):
    if i not in p:
        if abs(x - answer) > abs(i - x):
            answer = i
print(answer)

Solution (Python):
x,n = map(int,input().split())
p = list(map(int,input().split()))
ans = float("inf")
for i in range(-101,201):
    if i not in p:
        ans = min(ans,abs(x-i))
if x - ans not in p:
    print(x-ans)
else:
    print(x+ans)

Solution (Python):
import bisect
import sys
x,n = map(int,input().split())
if n==0:
    print(x)
    sys.exit()
l = list(map(int,input().split()))
l.sort()
index = bisect.bisect_left(l,x)
lis=[]
if l[index]==x:
    for i in l:
        lis.append(abs(i-x))
    lis.sort()
    key=0
    for i in range(1,100):
        a=lis.count(i)
        if a!=2:
            key=i
            break
    ans=x-key
    if ans not in l:
        print(ans)
        sys.exit()
    else:
        print(x+key)
        sys.exit()
else:
    print(x)

Solution (Python):
import sys
read = sys.stdin.buffer.read
input = sys.stdin.readline
input = sys.stdin.buffer.readline





def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))



def main():
	x,n=MI()
	p=[]
	if n!=0:
		p=LI()
	p.sort()

	diff=105
	ans=105

	for i in range(105,-1,-1):
		if i in p:
			continue
		else:
			if abs(i-x)<=diff:
				ans=i
				diff=abs(i-x)

	print(ans)













if __name__ == "__main__":
	main()

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

nums = [i for i in range(102)]

for i in p:
    nums.remove(i)

ans = []
for i in reversed(nums):
    if i <= x:
        sx = x - i
        ans.append(i)
        break

for i in nums:
    if i >= x:
        lx = i - x
        ans.append(i)
        break

if sx <= lx:
    print(ans[0])
else:
    print(ans[1])

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

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

p = set(p)
now = 0
diff = 101
indx = 0

while True:
    if now not in p:
        now_diff = abs(now - x)
        if diff > now_diff:
            diff = now_diff
            indx = now
        else:
            break
    now += 1

print(indx)

Solution (Python):
x,n = map(int,input().split())
P = set(map(int,input().split()))
Z = {_ for _ in range(-1,102)}
Z = Z-P
d = 101
ans = 101
for s in Z:
    y = abs(x-s)
    if y<d:
        d = y
        ans = s
print(ans)

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

for i in range(n):
    if x-i not in a:
        print(x-i)
        exit()
    elif x+i not in a:
        print(x+i)
        exit()
print(x-(n//2)-1)

Solution (Python):
from heapq import heapify, heappush, heappop

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

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

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

nums = []

heapify(nums)

for i in range(0, 102):
    if i not in P:
        heappush(nums, (abs(i - X), i))

print(heappop(nums)[1])

Solution (Python):
x, n = map(int, input().split())
q = [i for i in range(-110, 210)]
if n != 0:
  p = list(map(int, input().split()))
  for i in p:
    q[i+110] = -500

if x in q:
  print(x)
  exit()

l = []

for i in range(100):
  if x+i in q:
    l.append(x+i)
    break
for j in range(100):
  if x-j in q:
    l.append(x-j)
    break

if abs(l[0]-x) < abs(l[1]-x):
  print(l[0])
elif abs(l[0]-x) > abs(l[1]-x):
  print(l[1])
else:
  print(l[1])

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

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

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

def check(num):
  if num not in p:
    print(num)
    exit()

for i in range(101):
  check(x-i)
  check(x+i)

Solution (Python):



def foo(x, list):
    i = 1
    if list.count(str(x)) == 0:
        return (x)
    while True:
        if list.count(str(x-i)) == 0:
            return (x-i)
        if list.count(str(x+i)) == 0:
            return (x+i)
        i = i+1
        

x, n = input().split(" ")
if int(n) != 0:
    p = input().split(" ")
    print(foo(int(x), p))
else:
    print(x)

Solution (Python):
x, n = map(int, input().split())
p = list(map(int, input().split()))
ll = [i for i in range(300)]

if x not in p:
    print(x)
else:
    for num in p:
        ll.remove(num)
    l2 = []
    ans = float('inf')
    for i in ll:
        if abs(i-x) < abs(x-ans):
            ans = i
        if abs(i-x) == abs(ans-x):
            ans = min(i, ans)

    print(ans)