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

if n == 0:  
    p = input()
    print(x)
else:
    p = list(map(int, input().split()))
    max_p = max(p)
    ans = 0
    tmp = 1000

    for i in range(111):
        diff = abs(x - i)
        if i not in p and tmp > diff:
            ans = i
            tmp = diff

    print(ans)

Solution (Python):
list1= input().split(" ")
list2= input().split(" ")
X=int(list1[0])
N=int(list1[1])
plus_abs =1000
minus_abs=1000
result=0

for i in range(100):
    plus_abs=X+i
    minus_abs=X-i

    for j in range(N):
        if plus_abs == int(list2[j]):
           plus_abs=1000


    for k in range(N):
        if minus_abs == int(list2[k]):
            minus_abs=1000

    if plus_abs !=1000 or minus_abs!=1000:
        if plus_abs >= minus_abs:
            result = minus_abs
        else:
            result = plus_abs

        print(result)
        break

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

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

p.sort()

for i in range(p[0] - x, p[n - 1] + x):
    if (i not in p) and abs(x - i) < abs(ans - x):
        ans = i

print(ans)

Solution (Python):
X, N = [int(x) for x in input().split()]
l = [int(x) for x in input().split()]
if len(l) == 0:
    print(X)
elif X not in l:
    print(X)
else:
    for i in range(1, 1000):
        if X - i not in l:
            print(X - i)
            break
        elif X + i not in l:
            print(X + i)
            break

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

p = input()
if p:
    p =list(map(int,p.split(" ")))
    result = 1000
    a = 1000
    for i in range(-1, 102):
        if i in p:
            continue
        else:
            tmp = abs(i - x)
            if tmp < result:
                result = tmp
                a = i
            elif tmp == result:
                if i <= a:
                    a = i
    print(a)

else:
    print(x)

Solution (Python):
X = [int(i) for i in input().split()]
if X[1]==0:
    print(X[0])
else:
        
    P = [int(i) for i in input().split()]
    N=sorted(P)
    
    s=0
    flag=0
    
    for i in range(100):
        if (X[0]-i) in N:
            s=1
        else:
            flag=1
            
        if (X[0]+i) in N:
            s=s+1
        else:
            if flag!=1:
                flag=2
        
        if flag==1:
            
            print(X[0]-i)
            break
    
        if flag==2:
            print(X[0]+i)
            break

Solution (Python):
x, n = map(int, input().split())
if n == 0:
    print(x)
else:
    P = set(map(int, input().split()))
    if x not in P:
        print(x)
    else:
        ax = x
        while ax in P:
            ax += 1
        
        mx = x
        while mx in P:
            mx -= 1

        if abs(x-ax) < abs(x-mx):
            print(ax)
        else:
            print(mx)

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):
    if x-i not in p:
      print(x-i)
      break
    elif x+i not 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()))
  q=[i-X for i in p]
  qs=set(q)

  for i in range(N+1):
    if -i not in qs:
      print(X-i)
      break
    elif i not in qs:
      print(X+i)
      break

Solution (Python):

import sys
import bisect


def solve(X: int, N: int, p: "List[int]"):
    sortp = sorted(p)
    if(N == 0):
        print(X)
        exit()

    for i in range(100):
        
        l = X - i
        index = bisect.bisect_left(sortp,l)
        if(index == N or sortp[index] != l):
            print(l)
            exit()

        
        r = X + i
        index = bisect.bisect_left(sortp,r)
        if(index == N or sortp[index] != r):
            print(r)
            exit()


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  
    N = int(next(tokens))  
    p = [int(next(tokens)) for _ in range(N)]  
    solve(X, N, p)

if __name__ == '__main__':
    main()

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

for i in range(100):
    if ans not in p:
        print(ans)
        exit()
    plus += 1
    minus -= 1
    if minus not in p:
        print(minus)
        exit()
    elif plus not in p:
        print(plus)
        exit()

Solution (Python):




def main():
    x, n = map(int, input().split())
    if n >= 1:
        p_set = set(map(int, input().split()))
    else:
        p_set = set()

    print(f(x, p_set))


def f(x, p_set):
    for i in range(101):
        if (x - i) not in p_set:
            return x - i
        elif (x + i) not in p_set:
            return x + i


if __name__ == '__main__':
    main()

Solution (Python):


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

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

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

current_small = current_big = X

while True:
    if current_small not in P:
        print(current_small)
        break

    if current_big not in P:
        print(current_big)
        break

    current_small -= 1
    current_big += 1

Solution (Python):



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

l = [0] * 100

for p in P:
    l[p-1] = 1
    
i = 0
while 1:
    if X-i-1 < 0:
        print(0)
        exit()
    elif l[X-i-1] == 0:
        print(X-i)
        exit()
    elif X+i-1 >= 100:
        print(101)
        exit()
    elif l[X+i-1] == 0:
        print(X+i)
        exit()
    i+=1

Solution (Python):



def main():
    x,n = map(int,input().split())
    p = list(map(int,input().split()))
    a = x
    b = x
    if p == None:
        print(x)
    else:
        while a in p:
            a += 1
        while b in p:
            b -= 1
        if a - x < x - b:
            print(a)
        else:
            print(b)


if __name__ == '__main__':
    main()

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

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

for i in range(1, 101):
    if (x+i not in p_list) and (x-i not in p_list):
        print(x-i)
        exit()
    elif x-i not in p_list:
        print(x-i)
        exit()
    elif x+i not in p_list:
        print(x+i)
        exit()
    else:
        continue

Solution (Python):
import sys

input = sys.stdin.readline

def main():
    x, n = map(int, input().rstrip().split())
    if n == 0:
        print(x)
        sys.exit()
    else:
        p = list(map(int, input().rstrip().split()))
        if x > max(p):
            print(x)
            sys.exit()
        else:
            p_x = set(range(102))
            p_temp = set(p)
            p_diff = p_x - p_temp
            p_temp = list(p_diff)
            p_temp = sorted(p_temp)
            p_dir = []

        for i in range(len(p_temp)):
            p_dir.append(abs(p_temp[i] - x))
        print(p_temp[p_dir.index(min(p_dir))])
  
if __name__ == "__main__":
    main()

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

ans=1000

for i in range(1,101):
    if abs(x-ans)>abs(x-i) and i not in p:
        ans=i

if x<=abs(x-ans):
    if x<=101-x:
        print(0)
    else:
        print(101)
else:
    if abs(x-ans)<=101-x:
        print(ans)
    else:
        print(101)

Solution (Python):
X, N = list(map(int,input().split()))
if N !=0:
  P = list(map(int,input().split()))
  ab = 100
  for i in range(-100,200):
    if i not in P:
      if abs(X-i)<ab:
        ab = abs(X-i)
        ans = i
  print(ans)
else:
  print(X)

Solution (Python):
def resolve():
    X, N = map(int, input().split())
    if N != 0:
        P = list(map(int, input().split()))
        S = []
        for _ in range(0, 102):
            if _ in P:
                continue
            else:
                S.append(_)
        if X in S:
            print(X)
        else:
            for i in range(1, 102):
                if X-i in S:
                    print(X-i)
                    exit()
                elif X+i in S:
                    print(X+i)
                    exit()
    else:
        print(X)
resolve()

Solution (Python):
import sys

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

p=sorted(p)
for i in range(100):
    flag1=0
    flag2=0
    for j in range(len(p)):
        if p[j]==X-i:
            flag1=1
        if p[j]==X+i:
            flag2=1
    if flag1==0:
        print(X-i)
        sys.exit()
    if flag2==0:
        print(X+i)
        sys.exit()

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

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

ans = 0

if N != 0 :
    for i in range(105):
        if p.count(i)==0 :
            if abs(X-i) < abs(X-ans) :
                ans = i
    print(ans)
else :
    print(X)

Solution (Python):
from sys import exit

def downsearch(X,list):
    if X not in list:
        return X
    else:
        return downsearch(X-1,list)

def upsearch(X,list):
    if X not in list:
        return X
    else:
        return upsearch(X+1,list)


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

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

plist = [int(x) for x in input().split()]

d = downsearch(X,plist)
u = upsearch(X,plist)

if abs(X-d) <= abs(X-u):
    print(d)
else:
    print(u)

Solution (Python):
X,N = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]
nlist = [0 for i in range(105)] 
for i in p:
    nlist[i]=1
for i in range(max(X+1,100-X+1)):
    
    if X-i>=0:
        if nlist[X-i] == 0:
            result = X-i
            break
    if X+i<=101:
        if nlist[X+i] == 0:
            result = X+i
            break
print(result)

Solution (Python):
x,n=map(int,input().split())
if(n==0):
  print(x)
else:
  l=list(map(int,input().split()))
  d=100
  for i in range(102):
      if(i not in l and (abs(i-x)<d)):
          d=abs(x-i)
          m=i
  print(m)

Solution (Python):
x,n=map(int,input().split())
p=list(map(int,input().split()))
ans=1e9
for i in range(x+1000):
  if i in p:
    continue
  ans=min(ans,abs(x-i))

if x-ans in p:
  print(x+ans)
else:
  print(x-ans)

Solution (Python):


X,N = map(int, input().split())
if N==0:
    print(X)
    quit()
PList=list(map(int, input().split()))
List=[]
for k in range(102):
    List.append(k)

i=0
while i<N:
    if PList[i] in List:
        List[List.index(PList[i])]=100000
    i+=1




ANS=1000
j=0
KOTAE=1000
while j<102:
    if List[j]!=100000:
        SA=abs(X-List[j])
        if SA<ANS:
            ANS=SA
            
            KOTAE=List[j]
            
        
    j+=1
print(KOTAE)

Solution (Python):
X, N = list(map(int, input().split()))
if(N == 0):
  print(X)
  exit()
p = list(map(int, input().split()))
a = [num for num in range(-1001, 1001)]
diff = list(set(a) - set(p))
diff.sort(reverse=True)
ans = 10**10
for i in diff:
  if(abs(ans - X) >= abs(i - X)):
    ans = i
print(ans)

Solution (Python):
def main():
    import sys
    def input():
        return sys.stdin.readline()[:-1]
    A=list(map(int,input().split()))
    p=list(map(int,input().split()))
    if A[1]==0:
        print(A[0])
        sys.exit()
    X=A[0]
    N=A[1]
    for i in range(N+100):
        X1=X-i
        X2=X+i
        if X1 not in p:
            print(X1)
            sys.exit()
        if X2 not in p:
            print(X2)
            sys.exit()
    

    
if __name__ == '__main__':
    main()

Solution (Python):
import sys
x,n = map(int,input().split())
if(n == 0):
  print(x)
  sys.exit()
l = [int(v) for v in input().split()]
fl2 = False
for k in range(n):
  if(l[k] == x):
    fl2 = True
if (fl2 == False):
  print(x)
  sys.exit()
x1 = x
x2 = x
for i in range(n):
  flg1 = True
  flg2 = True
  ans1 = x1 - 1
  ans2 = x2 + 1
  for m in range(n):
    if(l[m] == ans1):
      x1 = x1 - 1
      flg1 = False
  if (flg1 == True):
    print(ans1)
    sys.exit()
  for o in range(n):
    if(l[o] == ans2):
      x2 = x2 + 1
      flg2 = False
  if (flg2 == True):
    print(ans2)
    sys.exit()

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

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

for i in range(150):
  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())
if n != 0:
    p = list(map(int, input().split()))
    if x in p:
        for i in range(-1000, 1001):
            if i == -1000:
                mini = i
            if i in p:
                pass
            else:
                if abs(x - mini) > abs(x - i):
                    mini = i
                elif abs(x - mini) == abs(x - i):
                    mini = min(mini, i)
        else:
            print(mini)
    else:
        print(x)
else:
    print(x)

Solution (Python):
import math
x,n=map(int,input().split())
if n==0:
  p=[]
else:
  p=list(map(int,input().split()))
p_sort=sorted(p)
result={}
for i in range(100+2):
  if not i in p_sort:
    result[i]=abs(x-i)
print(min(result, key=result.get))

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

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

    arr.sort()
    mn = arr[0]
    mx = arr[-1]
    if x > mx :
        print(x)
    elif x  <mn  :
        print(x)
    else:
        c = 1e5
        d = {}
        res = 0 
        for i in range(n) :
            d[arr[i]]= 1
        for i in range(mn-1 , mx+2):
            if not d.get(i , 0 ) :
                if abs(i - x)  <c :
                    res  = i
                    c = abs(i -x)

        print(res)

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

ans = 0

big_x = x
sml_x = x

for i in range(100):
    
    if sml_x not in p_lst:
        ans = sml_x
        
        break
    elif big_x not in p_lst:
        ans = big_x
        
        break
    
    
    big_x += 1
    sml_x -= 1
print(ans)

Solution (Python):
x,n = map(int,input().split())
p = list(map(int,input().split()))
sa = []
num = []
for i in range(-110,110):
    if i in p:
        continue
    sa.append(abs(x-i))
    num.append(i)

print(num[sa.index(min(sa))])

Solution (Python):
import sys


def int1(x): return int(x) - 1
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def mi1(): return map(int1, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def lli(rows_number): return [li() for _ in range(rows_number)]


if __name__ == "__main__":
    x, n = mi()
    if n == 0:
        print(x)
        exit()
    p_l = li()
    a = list(range(0, 1000))
    for p in p_l:
        a.remove(p)
    ans = 0
    min_dif = 10000
    for i in a:
        dif = abs(i-x)
        if dif < min_dif:
            min_dif = dif
            ans = i
    print(ans)

Solution (Python):
def i():
	return int(input())
def i2():
	return map(int,input().split())
def s():
	return str(input())
def l():
	return list(input())
def intl():
	return list(int(k) for k in input().split())

x,n = i2()
p = intl()

m = 100
ls = [int(i) for i in range(-200,200)]
for i in range(n):
	ls.remove(p[i])
for j in range(len(ls)):
	if abs(x - ls[j]) < m :
		m = abs(x - ls[j])
		ans = ls[j]
print(ans)

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

if N == 0 or not X in p_list:
    print(X)
else:
    for i in range(1,100):
        if not X-i in p_list:
            print(X-i)
            break
        elif not X+i in p_list:
            print(X+i)
            break

Solution (Python):
d = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]

int_x = int(d[0])
int_n = int(d[1])




ans = 100000
tmp = abs(int_x - ans)
for i in range(102):
  if tmp > abs(int_x - i):
    if not i in p:
      ans = i
      tmp = abs(int_x - ans)
  




print(ans)

Solution (Python):
x,n=map(int,input().split())
p=list(map(int,input().split()))
mins=103
ans=0
for i in range(102):
    d=0
    c=abs(x-i)
    for j in range(n):
        if p[j]==i:
            d=1
        else:
            op=0
    if d==0:
        if c<mins:
            mins=c
            ans=i
        else:
            op=0
print(ans)

Solution (Python):
X, N = map(int, input().split())
if (N == 0):
  print(X)
else:
  nums = list(map(int, input().split()))
    
  nums.sort()
  low = nums[0]
  high = nums[-1]
  minDiff = 100000000
  minNum = -1
  for i in range(-10, 110):
    if i in nums:
      continue
    else:
      Dif = abs(X-i)
    if (Dif < minDiff):
      minDiff = Dif
      minNum=i
  print(minNum)

Solution (Python):
import sys

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

if (X in p) == False:
    print(X)
    sys.exit()

for i in range(N+1):
    if (X - i in p) == False:
        print(X - i)
        sys.exit()
    elif (X + i in p) == False:
        print(X+i)
        sys.exit()

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

i = 0
j = 0
flag = 0
while True:
    if(X - i in p):
        i += 1
    else:
        flag = 1
        break
    if(X + j in p):
        j += 1
    else:
        flag = 2
        break
if(flag == 1):
    print(X - i)
elif(flag == 2):
    print(X + j)

Solution (Python):
x, n = map(int, input().split())
num_list = list(map(int, input().split()))
dif = 100000
o_list = []

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





for i in range(-1000, 1000):
    if i not in num_list:
        o_list.append(i)

o_list.sort(reverse=True)

for num in o_list:
    if abs(x - num) <= dif:
        
        dif = abs(x -num)
        ans = num

print(ans)

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

	diff_1 = abs(X-p[-1])
	diff_2 = abs(X-p[0])
	diff = max(diff_1,diff_2)


	for x in range(diff+2):
		if X-x not in p:
			print(X-x)
			break
		if X+x not in p:
			print(X+x)
			break

Solution (Python):
import numpy as np
import sys
x,N = map(int, input().split())

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

abs_list = []

for p in P:
  abs_list.append(np.abs(x-p))
  
if len(abs_list) == 0:
  print(x)
  sys.exit()
   
abs_max = max(abs_list)
for i in range(100):
  if abs_list.count(i) == 0:
    print(x-i)
    sys.exit()
  elif abs_list.count(i) == 1 and x+i in P and i !=0:
    print(x-i)
    sys.exit()
  elif abs_list.count(i) == 1 and x-i in P and i != 0:
    print(x+i)
    sys.exit()

Solution (Python):
from sys import stdin
X, N = [int(x) for x in stdin.readline().rstrip().split()]
p = [int(x) for x in stdin.readline().rstrip().split()]

ans = 10000
ans_diff = 10000

list_100 = [0] * 100
for i in range(100):
  list_100[i] = i+1
  
list_100.append(0)
list_100.append(-1)
list_100.append(101)
  
live_list = list(set(list_100) - set(p))

for i in live_list:
  diff = abs(X - i)
  if diff < ans_diff:
    ans = i
    ans_diff = diff
  if diff == ans_diff:
    ans = min(ans, i)
 
print(ans)

Solution (Python):
xn = list(map(int, input().split()))
x = xn[0]
n = xn[1]
can = True
try:
    p = list(map(int, input().split()))
except:
    can = False

if can:
    num = []
    for i in range(0, 102): 
        cnt1 = 0
        cnt2 = 0
        for j in range(n): 
            if x-i==p[j]:
                cnt1 += 1
            else:
                pass

            if x+i==p[j]:
                cnt2 += 1
            else:
                pass

        if cnt1==0 and cnt2==0:
            num.append(x-i)
        elif cnt1==0:
            num.append(x-i)
        elif cnt2==0:
            num.append(x+i)
        else:
            pass

    min_abs = []
    for i in range(len(num)):
        min_abs.append([abs(x-num[i]), num[i]])

    min_abs.sort(key=lambda x: x[0])
    print(min_abs[0][1])
else:
    print(x)

Solution (Python):
def main():
    x, n = [int(v) for v in input().split(' ')]
    if n == 0:
        print(int(x))
        return

    lst_p = [int(v) for v in input().split(' ')]
    lst_p.sort()

    if lst_p[-1] < x:
        print(int(0))
        return

    
    lst_p.append(lst_p[-1] + 2)

    d = x
    ans = 0
    continueous_n = 1
    for p in lst_p:
        if p == continueous_n:
            continueous_n = p + 1
            continue
        for i in range(p - continueous_n):
            tmp = abs(x - (continueous_n + i))
            if tmp < d:
                d = tmp
                ans = continueous_n + i
            else:
                print(int(ans))
                return
        continueous_n = p + 1
    print(int(ans))


if __name__ == '__main__':
    main()

Solution (Python):
def find_num(lst, value):
    return [i for i, x in enumerate(lst) if x == value]

def resolve():
    X,N = map(int,input().split())
    if N == 0:
        print(X)
    else:
        p = list(map(int,input().split()))
        p.sort()
        idx = find_num(p,X)
        if idx == []:
            print(X)
        else:
            for i in range(1,100):
                if p[idx[0] - i ] != X - i or idx[0] - i == -1:
                    print(X-i)
                    break
                if idx[0] + i == N:
                    print(X+i)
                    break
                elif p[idx[0] + i ] != X + i:
                    print(X+i)
                    break
resolve()

Solution (Python):
x, n = map(int, input().split())
p = list(map(int, input().split()))
result = x
for i in range(10000):
    a, b = x + i, x - i
    if b not in p:
        result = b
        break
    if a not in p:
        result = a
        break
print(result)

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

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

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

small = [i for i in range(-101, X)]
big = [i for i in range(X+1, 102)]
small.reverse()
for i in range(max(len(big),len(small))):
    if not small[i] in p:
        print(small[i])
        exit()
    elif not big[i] in p:
        print(big[i])
        exit()

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

def abs(a,b):
    if(a>b):
        ans=a-b
    else:
        ans=b-a

    return ans
h=100
for i in range(102):
    if(i not in P):
        if(h>abs(X,i)):
            h=abs(X,i)
            ans=i
            
            
print(ans)

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



dif = 1000
ans = 1000
for i in range(-101, 110):
    if not(i in p):
        if abs(i-x) < dif:
            dif = abs(i-x)
            ans = i
        elif abs(i-x) == dif:
            if ans > i:
                ans = i

print(ans)

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

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

p = list(map(int,input().split()))
q = [i for i in range(-1000,1000)]
li = set(p) ^ set(q)
tmp = 0
ans = 0
while(1):
    if X-tmp in li:
        ans = X-tmp
        break
    elif X+tmp in li:
        ans = X+tmp
        break
    tmp += 1
print(ans)

Solution (Python):
x, n = (int(each) for each in input().split())
if n == 0:
    print(x)
else:
    p = [int(each) for each in input().split()]
    candidate = 0
    for i in range(210):
        j = i - 105
        if j not in p and abs(j-x) < abs(candidate-x):
            candidate = j
            
    print(candidate)

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

if(N == 0): 
  print(X)
else:
  j = 0
  
  min = abs(X)
  ans = 0
  for i in range(1,101):
    if(i != s[j]):
      if(abs(X-i) < min):
        min = abs(X-i)
        ans = i
    else:
      j += 1
    if(j >= len(s)):j=len(s)-1
      
  if(abs(X-101) < min):
    ans = 101
  print(ans)

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

pp=x
pm=x
while (pp in l) and (pm in l):
    pp=pp+1
    pm=pm-1

if (not pp in l) and (not pm in l):
    print(min(pp, pm))
elif pp in l:
    print(pm)
else:
    print(pp)

Solution (Python):
x,n = map(int, input().split())
if n ==0:
    print(x)
else:
    l = list(map(int, input().split())) 
    for i in range(0,52):
        if x-i not in l:
            print(x-i)
            break
        elif x+i not in l:
            print(x+i)
            break

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

L = list(range(0,102))
if y != 0:
    L2 = list(map(int,input().split()))
    
    
    for i in range(len(L2)):
        L.remove(L2[i])
        





t = len(L)//2

for j in range(len(L)):

    if L[t] >= x:

        if t == 0:
            print(L[t])
            break
        elif L[t-1] <= x:
            if abs(L[t]-x) < abs(L[t-1]-x):
                print(L[t])
                break
            else:
                print(L[t-1])
                break
        
        t = t//2
    else:
        if t == y-1:
            print(L[t])
            break
        elif L[t+1] >= x:
            if abs(L[t]-x) > abs(L[t+1]-x):
                print(L[t+1])
                break
            else:
                print(L[t])
                break
        t = t + (len(L)-t)//2

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()
Y=X
Z=X
s=0
t=0
while s==0:
    Y+=1
    if Y not in p:
        break
while t==0:
    Z-=1
    if Z not in p:
        break
if abs(X-Y)<abs(X-Z):
    print(Y)
elif abs(X-Y)>abs(X-Z):
    print(Z)    
else:
    print(Z)

Solution (Python):
X, N = map(int, input().split())
p = list(map(int, input().split()))
p.sort()
ans = X
for i in range(100):
    if X-i not in p:
        ans = X-i
        break
    elif X+i not in p:
        ans = X+i
        break
    
    
print(ans)

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


tar1 = x
tar2 = x
ff1 = True
ff2 = True

while True:
    if (ff1 is True):
        tar1 -= 1
        if (tar1 not in a):
            print(tar1)
            exit()

    if (ff2 is True):
        tar2 += 1
        if (tar2 not in a):
            print(tar2)
            exit()
 

    if ((ff1 is False) and (ff2 is False)):
        break

Solution (Python):
import numpy as np

X, N = (int(x) for x in input().split())
if N == 0:
    print(X)
else:
    p = np.array([int(x) for x in input().split()])
    x_arange = set(np.arange(-100, 101))
    p_x = set(np.array(p - X))
    sub_list = list(x_arange - p_x)
    sub_abs_list = np.abs(np.array(sub_list))

    min_sub = min(sub_abs_list)
    if (X - min_sub) not in p:
        print(X - min_sub)
    else:
        print(X + min_sub)

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

a = X
j = 0
for i in range(200):
    if P.count(a) == 0:
        print(a)
        break
    else:
        j += 1
        a = a - j
        if P.count(a) == 0:
            print(a)
            break
        else:
            j += 1
            a = a + j
            if P.count(a) == 0:
                print(a)
                break

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

X_max = X
X_min = X

while True:
    if N == 0 or (X in p) == False:
        print(X)
        break
        break
    X_max += 1
    X_min -= 1
    if (X_min in p) == False:
        print(X_min)
        break
        break
    if (X_max in p) == False:
        print(X_max)
        break
        break

Solution (Python):
X,N=map(int,input().split())
L=list(map(int,input().split()))
ans=10000
for i in range(100):
    if X-i in L:
        pass
    else:
        ans=X-i
        break
    if X+i in L:
        pass
    else:
        ans=X+i
        break

print(ans)

Solution (Python):

MOD=10**9+7
INT_MAX=10**20+7
def INPUT():return list(int(i) for i in input().split())
def LIST_1D_ARRAY(n):return [0 for _ in range(n)]
def LIST_2D_ARRAY(m,n):return [[0 for _ in range(n)]for _ in range(m)]

x,n=INPUT()
A=INPUT()
if x not in A:
    print(x)
else:
    for d in range(1,102):
        if x-d not in A:
            print(x-d)
            break
        elif x+d not in A:
            print(x+d)
            break

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

diff = 1000
for i in range(-100, 110):
    if i in p:
        continue
    if abs(i - x) < diff:
        diff = abs(i - x)
        ans = i

print(ans)

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

for i in range(100):
    if not str(x-i) in n_list:
        print(x-i)
        break
    elif not str(x+i) in n_list:
        print(x+i)
        break

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

P = list(map(int, input().split()))
if N==1:
    if X!=P[0]:
        print(X)
        sys.exit()
    if X==P[0]:
        print(X-1)
        sys.exit()
PP=sorted(P, reverse=True)
sab=abs(X-P[0])

for i in range(N):
    if PP.count(X-i)==0 :
        print(X-i)
        sys.exit()
    if PP.count(X+i)==0:
        
        print(X+i)
        sys.exit()

Solution (Python):
X,N = map(int,input().split())
P = list(map(int,input().split()))
num = sorted([[abs(X - i),i] for i in range(-200,200) if i not in P],key = lambda x: x[0])

inf = 10 ** 3
inf2 = 10 ** 3 * -1

for i in range(X,inf):
  if i in P:
    continue
  plus = abs(X - i)
  break

for j in range(X,inf * -1,-1):
  if j in P:
    continue
  minus = abs(X - j)
  break

if plus < minus:
  print(i)

else:
  print(j)

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

u = [i for i in p if i >= x]
if len(u) == 0:
    u = [x]

l = [i for i in p if i <= x]
if len(l) == 0:
    l = [x]

if len(p)==0:
    print(x)
else:
    for i in range(x,max(u)+2):
        if i not in u:
            um = i
            break
        else:
            continue       
    for i in range(x,min(l)-2,-1):
        if i not in l:
            lm = i
            break
        else:
            continue   
    if abs(x-um) == abs(x-lm):
        print(lm)
    else:
        uu = abs(um - x)
        ll = abs(lm - x)
        if uu > ll:
            print(lm)
        else:
            print(um)