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):
x,n = map(int, input().split())
l = list(map(int, input().split()))
l_dis = [num - x for num in l]

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

Solution (Python):

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

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

if __name__ == "__main__":
    resolve()

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

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

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

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

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

Solution (Python):
import bisect as bs

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


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

nums = list(map(int,input().split()))
nums2 = [False]*101

for p in nums:
    nums2[p] = True

for i in range(102):
    
    if x - i < 1:
        print(0)
        exit(0)
    elif x + i > 100 and nums2[x-i]==True:
        print(101)
        exit(0)
    elif nums2[x-i]==False:
        print(x-i)
        exit(0)
    elif nums2[x+i]==False:
        print(x+i)
        exit(0)

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

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

a = x
b = x

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

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

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

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

print(check())

Solution (Python):
import numpy as np

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

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

        cnt += 1   


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

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

    min = 1000

    for i in range(-50, 150):

        if i in p:
            continue

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

    print(result)


if __name__ == "__main__":
    main()

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

diff = [200, 0]


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

print(diff[1])

Solution (Python):
x,n=map(int,input().split())
l=list(map(int,input().split()))
loop = True
j = 0
while loop:
    if x-j not in l:
        loop = False
        print(x-j)
        break
    elif x+j not in l:
        loop = False
        print(x+j)
    j+=1

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

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

if p is None or not x in p:
  print(x)
else:
  for i in range(1, n + 1):
    if not (x - i) in p:
      print(x - i)
      break
    elif not (x + i) in p:
      print(x + i)
      break

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

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

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

	if n==0:
		print(x)
		return

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


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

	res = -300

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


if __name__ == "__main__":
	solve()

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

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

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

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

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

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


sub = pn - x

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

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

print(res)

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

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

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

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

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

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

Solution (Python):
import sys

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

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

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

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

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

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

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

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

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

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

    for diff in range(X):
        X_plus = X + diff
        X_minus = X - diff
        
        
        if (X_minus in given_list) == False:
            ans = X_minus
            break
        elif (X_plus in given_list) == False:
            ans = X_plus
            break
    print(ans)

Solution (Python):

import sys






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

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


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


print(r)

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

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

Solution (Python):
import sys
input = sys.stdin.readline
from collections import deque
def main():
    X, N =  map(int, input().split())
    p = list(map(int, input().split()))
    if N > 0:
        P = deque(sorted(p))
        L = P.popleft()
    else:
        print(X)
        return
    diff = 101
    ans = 101

    for i in range(-102,102):
        if i == L:
            if len(P) > 0:
                L = P.popleft()
            else:
                L = 200
        else:
            diff = abs(X-i)
        if diff < ans:
            ans = min(diff, ans)
    if X-ans in p:
        print(X+ans)
    else:
        print(X-ans)

if __name__ == '__main__':
    main()

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

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

a = X
b = X

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

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

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

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

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

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

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

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

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

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


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


print(ans())

Solution (Python):
import sys

input = sys.stdin.readline


def main():
    X, N = list(map(int, input().split(" ")))
    if N == 0:
        print(X)
        exit(0)
    arr = list(map(int, input().split(" ")))
    if X not in arr:
        print(X)
        exit(0)

    arr.sort()
    for i in range(len(arr)):
        if arr[i] >= X:
            diff = 1
            while True:
                if X - diff not in arr:
                    print(X - diff)
                    exit(0)
                if X + diff not in arr:
                    print(X + diff)
                    exit(0)
                diff += 1


if __name__ == '__main__':
    main()

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

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

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

flag=True
k = 0

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

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

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

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

Solution (Python):
import numpy as np
import itertools

x,n = map(int,input().split())
li = list(map(int,input().split()))
li.sort()
if x in li:
    idx = li.index(x)
    i = 0
    while(1):
        i = i+1
        if(idx-i<0):
            print(x-i)
            break
        if(li[idx-i]!=x-i):
            print(x-i)
            break
        if(idx+i>=len(li)):
            print(x+i)
            break
        if(li[idx+i]!=x+i):
            print(x+i)
            break
else:
    print(x)

Solution (Python):
X,N=map(int,input().split())
a_list=list(map(int,input().split()))
if N==0:
    print(X)
else:
    if X in a_list:
        for i in range(N//2+2):
            
            if X-i in a_list:
                
                if X+i in a_list:
                    a=1
                else:
                    print(X+i)
                    break
            else:
                print(X-i)    
                break        
    else:
        print(X)

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

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

if X not in p:
    print(X)    
else:
    i = 1
    while p[p.index(X)] + i in p:
        i += 1
    up = p[p.index(X)] + i
    
    i = 1
    while p[p.index(X)] - i in p:
        i += 1
    down = p[p.index(X)] - i

    if abs(down-X) <= abs(up-X):
        print(down)
    else:
        print(up)

Solution (Python):
x,n=map(int,input().split())
if n!=0:
    p=list(map(int,input().split()))
    k=[i for i in range(0,102)]
    kset=set(k)
    pset=set(p)
    ansbook=kset-pset
    ansbook=list(ansbook)
    ansbook=ansbook[::-1]
    ans1=100000
    ans=0
    for i in ansbook:
        if abs(i-x)<=ans1:
            ans1=abs(i-x)
            ans=i
    print(ans)
else:
    print(x)

Solution (Python):
from bisect import bisect_left as bl
x,n = map(int, input().split())
p = list(map(int, input().split()))
if n == 0:
    print(x)
else:
    i = 0
    p.sort()
    a = bl(p, x)
    if a == n:
        print(x)
    elif p[a] != x:
        print(x)
    else:
        while(True):
            i += 1
            if p[bl(p, x-i)] != x-i:
                print(x-i)
                break
            else:
                a = bl(p, x+i)
                if a == n:
                    print(x+i)
                    break
                elif p[a] != x+i:
                    print(x+i)
                    break

Solution (Python):
X,N =map(int,input().split())
pb = list(map(int,input().split()))
p =[]
for i in range(0,102):
    p.append(i)
An = []
ab =[]
Answer =[]
for i in range(1,N+1):
    p.remove(pb[i-1])
for j in range(len(p)):
    An.append(p[j])
    ab.append(abs(p[j]-X))
abmi = ab[0]
for i in range(len(p)):
    if abmi > ab[i]:
        Answer = []
        Answer.append(An[i])
        abmi = ab[i]
    if abmi == ab[i]:
        Answer.append(An[i])
print(min(Answer))

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

best = 100000000
ret = x

if n:
	mn = min(ps)
	mx = max(ps)
	s = set(ps)
	for i in range(mn, mx+1):
		if i not in s:
			d = abs(x-i)
			if d < best:
				best = d
				ret = i
	if ret == x:
		up = abs(mx + 1 - x)
		down = abs(mn - 1 - x)
		ret = mn-1 if down <= up else mx+1
	if x not in s:
		ret = x

print(ret)

Solution (Python):
x, n = map(int, input().split())
a = list(map(int, input().split()))
o = [0] * 102
for i in a:
    o[i] = 1

ans = 1000
dis = 1000
for i in range(0, len(o)):
    if o[i] == 0:
        if dis > abs(x - i):
            ans = i
            dis = abs(x-i)

print(ans)

Solution (Python):
import sys
x,n = map(int, sys.stdin.readline().rstrip("\n").split())
p = [int(s) for s in sys.stdin.readline().rstrip("\n").split()]
num = [i for i in range(-200,200)]
for i in range(n):
    num.remove(p[i])
if not num:
    pass
elif x in num:
    print(x)
else:
    d = 1
    while True:
        if x-d in num:
            print(x-d)
            break
        elif x+d in num:
            print(x+d)
            break
        else:
            d += 1

Solution (Python):
X, N = map(int, input().split())
P =  set(map(int, input().split()))
Nums = set(range(-100, 200))
Nums = Nums - P
sorted(Nums)


minNum = 99999
minIndex = 0
for n in Nums:
    if minNum == abs(X-n):
        break
    if abs(X - n)< minNum:
        minNum = abs(X-n)
        minIndex = n

print(minIndex)

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

Solution (Python):
from sys import stdin

x, n = [int(x) for x in stdin.readline().rstrip().split()]
if n > 0:
    P = [int(x) for x in stdin.readline().rstrip().split()]

    memos = [False] * 102

    for p in P:
        memos[p] = True

    tgt = x
    offset = 1
    look_down = True
    while True:

        if memos[tgt] == False:
            break
        if look_down:
            look_down = False
            tgt = x-offset
        else:
            look_down = True
            tgt = tgt + offset + offset
            offset += 1

    print(tgt)
else:
    print(x)

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

int_set = set(list(range(-1,102)))

for x in input().split():
    int_set.remove(int(x))

for i in range(200):
    if X - i in int_set:
        print(X - i)
        break
    elif X + i in int_set:
        print(X + i)
        break

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

def search(x, li):
  for i in range(int(len(li)/2)+2):
    if x-i not in li:
      print(x-i)
      return
    if x+i not in li:
      print(x+i)
      return
  return

search(x, p)

Solution (Python):
target,n = map(int,input().split())
if n == 0:
  	print(target)
else:
    ary = list(map(int,input().split()))
    count = 0
    while True:
        if target - count not in ary:
            print(target - count)
            break
        elif target + count not in ary:
            print(target + count)
            break
        else:
            count += 1

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

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

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





l = sorted(l)

l_min = min(l)
l_max = max(l)

x = [i for i in range(l_min, l_max+1)]

x = [l_min-1] + x + [l_max+1]


y = []
for j in x:
    if j not in l:
        y.append(j)


ans = 0
tmp = 1000
for k in y:
    if tmp > abs(k - X):
        tmp = abs(k - X)
        ans = k

print(ans)

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

ans = 200
abs_ans = 200
for i in range(102):
    if i in P:
        continue
    if abs(x-i) < abs_ans:
        ans = i
        abs_ans = abs(x-i)
print(ans)

Solution (Python):
import numpy as np
X, N = list(map(int, input().split()))
p = list(map(int, input().split()))
set_p = set(p)

if X not in set_p:
    print(X)
else:
    tmp = set(range(0, 102))
    notinp = np.array(list(tmp - set_p))
    t = np.abs(np.array(notinp) - X)
    argmin = t.argmin()
    print(notinp[notinp == notinp[argmin]].min())

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

i = 0
ans = None if p else x

while(ans is None):
    xu, xd = x+i, x-i
    if xu not in p:
        ans = xu
    if xd not in p:
        ans = xd
    i=i+1

print(ans)

Solution (Python):
X,N = map(int,input().split())
if N>0:
  p=list(map(int,input().split()))
  for d in range(0,101):
    if (X-d) not in p:
      print(X-d)
      break
    elif (X+d) not in p:
      print(X+d)
      break
else:print(X)

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

for i in range(100):
    if p.count(x+i) == 0:
        a = x+i
        break

for i in range(100):
    if p.count(x-i) == 0:
        b = x-i
        break

if abs(a-x) < abs(b-x):
    print(a)
else:
    print(b)

Solution (Python):
X, N = map(int,input().split())
if N > 0:
  P = set([int(_) for _ in input().split()])
else:
  P = set()

l_cand = None
r_cand = None
i = 0
while (l_cand is None) and (r_cand is None):
  if X - i not in P and l_cand is None:
    l_cand = X - i
  if X + i not in P and r_cand is None:
    r_cand = X + i
  i += 1
  
if l_cand is not None:
  print(l_cand)
else:
  print(r_cand)

Solution (Python):
import numpy as np

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


possible=[]

for i in range(min(Pn)-1,max(Pn)+2) if N!=0 else [X]:
    if i not in Pn:
        possible.append(i)

idx = np.abs(np.asarray(possible) - X).argmin()

print(possible[idx])

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

allowed = []
for i in range(102):
    if i not in ps:
        allowed.append(i)

for j in range(len(allowed)-1):
    if x-allowed[j+1] == 0:
        print(x)
        exit()
    elif (x-allowed[j]) * (x-allowed[j+1]) > 0:
        continue
    else:
        if x-allowed[j] <= allowed[j+1] - x:
            print(allowed[j])
        else:
            print(allowed[j+1])

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

Solution (Python):
x,n = map(int,input().split())
p = list(map(int,input().split()))
if n == 0:
    print(x)
    exit()
if x not in p:
    print(x)
    exit()
dif = 2**60
ans = 2**60
for u in range(201):
    if u in p:
        continue
    else:
        tmp = abs(x-u)
        if tmp < dif:
            dif = tmp
            ans = u
for a in range(1,201):
    if a+x == dif:
        ans = -a
        break
print(ans)

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

p = [int(x) for x in input().split()]
ans = 10**9

if x not in p:
    ans = x
else:
    for i in range(1, 101):
        minus = x-i
        plus = x+i
        if minus not in p:
            ans = minus
            break
        elif plus not in p:
            ans = plus
            break
print(ans)

Solution (Python):
import sys

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

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

tmp = []
for i in range(x-60,x+60):
    tmp.append(i)

ans = []
for j in tmp:
    if j not in l:
        ans.append(j)

tmp1 = 100
for k in ans:
    tmp2 = abs(x-k)
    if tmp2 != 0:
        if tmp1 >= tmp2:
            tmp1 = tmp2

ans2 = []
for m in ans:
    a = abs(m-x)
    if a == tmp1:
        ans2.append(m)

print(min(ans2))

Solution (Python):
x,n=map(int,input().split())
if n==0:
  anss=x
else:
  p=list(map(int,input().split()))
  pp=list(set(list(range(-100,105)))-set(p))
  ans=1000
  anss=1000
  for j in range(len(pp)):
    if abs(pp[j]-x)<ans:
      ans=abs(pp[j]-x)
      anss=pp[j]
    elif abs(pp[j]-x)==ans and pp[j]<anss:
      ans=abs(pp[j]-x)
      anss=pp[j]
print(anss)

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

px=[]
for i in range(n):
    
    px.append(p[i]-x)
k=0
cnt=0
while cnt<n:
    px.append(k)
    if px.index(k) == n:
        print(x+k)
        break
    else:
        px.pop(n)
        cnt+=1
        if k>=0:
            k=-1*(k+1)
        else:
            k*=-1
        if cnt==n:
            print(x+k)

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

X, N = map(int, input().split())
plist = list(map(int, input().split()))
diff = []
for i in range(0, 102):
    if i not in plist:
        diff.append(i)

diff.sort()
diff = [(item, abs(item - X)) for item in diff]

nearest = -1
min_v = 1000
for idx, item in diff:
    if item < min_v:
        min_v = item
        nearest = idx

print(nearest)

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

num_set = set(range(-201, 201))

ans_list = list(num_set - p)
min_diff = None
min_ans = None
for ans in reversed(ans_list):
    diff = abs(ans - X)
    if min_diff is None or diff <= min_diff:
        min_diff = diff
        min_ans = ans

print(min_ans)

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

if p.count(x)==0:
  print(x)
else:
  a = 1
  while True:
    x1,x2 = x-a,x+a
    if p.count(x1)==0:
      print(x1)
      break
    elif p.count(x2)==0:
      print(x2)
      break
    else:
      a += 1

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

ans_1=X
ans_2=X


for j in range(100):
    for i in range(N):
        if ans_1 in p:
            ans_1+=1
        else:
            break


for j in range(100):
    for i in range(N):
        if ans_2 in p:
            ans_2-=1
        else:
            break



if abs(ans_2-X)-abs(ans_1-X)>0:
    print(ans_1)
else:
    print(ans_2)

Solution (Python):
X,N=map(int, input().split())
a=list(map(int, input().split()))
d=0
u=0
i=1
if(N==0):
    print(X)
else:
    if X in a:
        while(d==0) and (u==0):
            if X-i in a:
                if X+i in a:
                    i +=1
                else:
                    u +=1
            else:
                d +=1
        if(d==1):
            print(X-i)
        elif(u==1):
            print(X+i)
    else:
        print(X)

Solution (Python):
X , N  =  map ( int , input().strip().split(" ") ) ;
s = input().strip() ;

if len(s) == 0 :
	set1 = set() ;
else :
	L   =  list ( map ( int , s.split(" ") ) ) ;
	set1 = set ( L ) ;

v1 = None ;
while v1 is None :
	for x in range ( 0 , 101 ) :
		if X + x in set1 : continue ;
		v1 = x; 
		break ;
v2 = None ;
while v2 is None :
	for x in range ( 0 , 101 ) :
		if X-x  in set1 : continue ;
		v2 = x; 
		break ;
if v1 < v2 :
	print ( X + v1 ) ;
else :
	print ( X - v2 ) ;

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

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

s=p.index(x)
for i in range(1,n+1):
  if p[s-i]!=x-i:
    print(x-i)
    exit()
  elif s+i>n-1:
    print(p[-1]+1)
    exit()
  elif s+i<=n-1:
    if p[s+i]!=x+i:
      print(x+i)
      exit()

Solution (Python):
X, N = map(int, input().split())
if N > 0:
    p = list(map(int, input().split()))
elif N == 0:
    print(X)
    exit()
else :
    p = [int(input())]
if N == 100:
    if X <= 50:
        print(0)
    else:
        print(101)
    exit()

for i in range(X+1):
    if not i in p:
        x = i

for i in range(X,101):
    if not i in p:
        y = i
        break
    elif i == 100:
        y = 101

if (X-x) == (y-X):
    print(x)
elif (X-x) > (y-X):
    print(y)
else:
    print(x)

Solution (Python):
x,n=map(int,input().split())
lis = []
if(n!=0):
    lis = list(map(int,input().split()))
ans = 0
msf = 1000
for i in range(101):
    tmp1 = x-i
    if tmp1 not in lis:
        print(x-i)
        exit()
    tmp2 = x+i
    if tmp2 not in lis:
        print(x+i)
        exit()