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 math
from collections import deque
from collections import defaultdict
import itertools as it


def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def combmod(n,r,mod):
	return (fact(n)/fact(n-r)*pow(fact(r),mod-2,mod))%mod
def printQueue(q):
	r=copyQueue(q)
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.parents = [-1]*n

	def find(self, x): 
		if self.parents[x]<0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]

	def union(self,x,y):
		x = self.find(x)
		y = self.find(y)

		if x==y:
			return

		if self.parents[x]>self.parents[y]:
			x,y = y,x

		self.parents[x]+=self.parents[y]
		self.parents[y]=x

	def size(self,x):
		return -1*self.parents[self.find(x)]

	def same(self,x,y):
		return self.find(x)==self.find(y)

	def members(self,x): 
		root = self.find(x)
		return [i for i in range(self.n) if self.find(i)==root]

	def roots(self):
		return [i for i,x in enumerate(self.parents) if x<0]

	def group_count(self):
		return len(self.roots())

	def all_group_members(self):
		return {r: self.members(r) for r in self.roots()} 
def bitArr(n):
	x = 1
	zero = "0"*n
	ans = []
	ans.append([0]*n)
	for i in range(2**n-1):
		ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
		x+=1
	return ans;
def arrsSum(a1,a2):
	for i in range(len(a1)):
		a1[i]+=a2[i]
	return a1
def maxValue(a,b,v):
	v2 = v
	for i in range(v2,-1,-1):
		for j in range(v2//a+1): 
			k = i-a*j
			if k%b==0:
				return i
	return -1
def copyQueue(q):
	nq = queue.Queue()
	n = q.qsize()
	for i in range(n):
		x = q.get()
		q.put(x)
		nq.put(x)
	return nq
def get_sieve_of_eratosthenes(n):
	
	data = [0,0,0]
	for i in range(3,n+1,2):
		data.append(i)
		data.append(0)
	for i in range(len(data)):
		interval = data[i]
		if interval!=0:
			for j in range(i+interval,n-1,interval):
				data[j] = 0
	
	ans = data[:]
	return ans

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

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

for i in range(1,101):
	l = x-i
	r = x+i
	if l not in p:
		print(x-i)
		exit()
	if r not in p:
		print(x+i)
		exit()

Solution (Python):
x, n = map(int,input().split())
if n==0:
  print(x)
else:
  a = input().split(" ")
  lista = [int(n) for n in a]
  for i in range (200):
    for j in range(100):
      if x-j not in lista:
        print(x-j)
        exit()
      if x+j not in lista:
        print(x+j)
        exit()

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

mass = []

if(y > 0):
    mass = list(map(lambda x: int(x), input().split(' ')))

d = 1000
j = -1

for i in range(0, 102):
    if(not i in mass):
        if(abs(x - i) < d):
            d = abs(x - i)
            j = i

print(j)

Solution (Python):
X,N = map(int,input().split())
p = list(map(int,input().split()))
if p == []:
    print(X)
    exit()
for i in range(100):
    if not X-i in p:
        print(X-i)
        exit()
    if not X+i in p:
        print(X+i)
        exit()

Solution (Python):


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

P2 = []

for i in range(-100, 201):
    if i in P:
        continue
    P2.append(i)
sa = 10**9
ret = -1
for p in P2:
    if abs(X-p) < sa:
        sa = abs(X-p)
        ret = p

print(ret)

Solution (Python):
x,n=map(int,input().split())
if n!=0:
  pp=list(map(int,input().split()))
else:
  pp=[]
q=True
r=True
i=0
a=0
b=0
while q:
  if x+i not in pp:
    a=x+i
    q=False
  else:
    i+=1
i=0
while r:
  if x-i not in pp:
    b=x-i
    r=False
  else:
    i+=1  

if a-x==x-b:
  print(b)
elif a-x<x-b:
  print(a)
else:
  print(b)

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

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

_,res = min((abs(X-y),y) for y in range(-1,102) if y not in P)
print(res)

Solution (Python):
X,N=map(int,input().split())
p=[int(i) for i in input().split()]
for i in range(200):
    if i%2==0:
        X+=i
    else:
        X-=i
    if X not in p:
        break
    else:
        continue
print(X)

Solution (Python):


x, n = map(int, input().split())
p_list = list(map(int, input().split()))
for i in range(0, n // 2 + 2):
    if x - i not in p_list:
        print(x - i)
        break
    if x + i not in p_list:
        print(x + i)
        break

Solution (Python):
X,N=list(map(int, input().split(' ')))
if N>0:
    p=list(map(int, input().split(' ')))
else:
    p=[]
A=0
A2=400
A3=0
for i in range(0,200):
    if i in p:
        v=0
    else:
        A=abs(i-X)
        if A<A2:
            A2=A
            A3=i
        else:
            print(A3)
            exit()

Solution (Python):
X, N = list(map(int, input().split()))
p = set(map(int, input().split()))
d = 0
while True:
    x_n = X - d
    x_p = X + d
    if x_n not in p:
        print(x_n)
        break
    elif x_p not in p:
        print(x_p)
        break
    d += 1

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

d = {i : abs(X - i) * 1000 + i for i in range(-110, 110, 1)}

for p in P:
  if p in d:
    d[p] = 10000000

d = sorted(d.keys(), key=lambda x: d[x])

print(d[0])

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

ans = None
for r in range(100):
    for i in [-r, r]:
        if (X + i) not in p:
            ans = X+i
            break

    if ans is not None:
        break

print(ans)

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

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

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

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

Solution (Python):
X,N = map(int,input().split())
import sys
p = list(map(int,input().split()))
if N == 0:
    print(X)
    sys.exit()
    
for i in range(101):  
    tmp_r = 10**9+7
    tmp_l = 10**9+7
    r_flag = 0
    l_flag = 0
    
    if X+i not in p:
        tmp_r = X+i
        r_flag = 1
    if X-i not in p:
        tmp_l = X-i
        l_flag = 1
        
    if r_flag == 1 or l_flag == 1:
        print(min(tmp_r,tmp_l))
        sys.exit()

Solution (Python):
x,n = map(int, input().split(" "))
if n == 0:
  print(x)
else:  
  plist = list(map(int, input().split(" ")))
  s = 0
  while x+s in plist and x-s in plist:
    s += 1
  if x-s in plist:
    print(x+s)
  else:
    print(x-s)

Solution (Python):

X, N = map(int, input().split())
p = list(map(int, input().split()))
p.sort()
resultPlus = X
resultMinus = X
flag = True
if(N == 0):
    print(X)
else:
    if X in p:
        while flag == True:
            resultMinus -= 1
            resultPlus += 1
            if resultMinus not in p:
                flag = False
                print(resultMinus)
                break
            if resultPlus not in p:
                flag = False
                print(resultPlus)
                break
    else:
        print(X)

Solution (Python):
data = input().rstrip().split(" ")
X = int(data[0])
N = int(data[1])
if N != 0:
    num = input().rstrip().split(" ")
    number = []
    for i in num:
        number.append(int(i))

    k = 0
    while True:
        if not X-k in number:
            ans = X-k
            break
        else:
            if not X+k in number:
                ans = X+k
                break
        k +=1
else:
    ans = X        
print(ans)

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

P = set(P)
ans = 0
tmp = 1000000
setlist = range(-1,102)
for ele in setlist:
    if ele in P:
        continue
    if abs(ele-X) < tmp:
        ans = ele
        tmp = abs(ele-X)
    

print(ans)

Solution (Python):
x, n = map(int, input().split())
p = list(map(int, input().split()))
s = []
for i in range(202):
    s.append(i)
for i in range(n):
    s.remove(p[i])

for i in range(202):
    if (x-i) in s:
        print(x-i)
        break
    elif (x+i) in s:
        print(x+i)
        break

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

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

Solution (Python):
X, N = map(int,input().split())
if N == 0:
  print(X)
else:
  q = list(map(int,input().split()))
  q = list(set(q))
  p = [i for i in range(-2 , 102)]
  for i in range(len(q)):
    p.remove(q[i])

  S = 103
  for i in range(len(p)):
    if abs(X - p[i]) < S :
      ans = p[i]
      S = X - ans
    elif abs(X - p[i]) == S :
      if p[i] < ans :
        ans = p[i]
  print(ans)

Solution (Python):

import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

x,n = MI()
mylist = tuple(MI())

num = 0
while True:
    if not(x - num in mylist):
        print(x- num)
        sys.exit()
    if not(x + num in mylist):
        print(x+ num)
        sys.exit()
    num += 1

Solution (Python):
x,n=map(int,input().split())
a=[int(i) for i in input().split()]
ans=float("inf")
anss=0
for i in range(-200,200):
    if i not in a:
        if abs(x-i)<ans:
            ans=abs(x-i)
            anss=i
print(anss)

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

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

mae = x-1
ushiro = x+1
for i in range(n):
    if mae not in p:
        print(mae)
        exit()
    elif ushiro not in p:
        print(ushiro)
        exit()
    mae = mae -1
    ushiro = ushiro +1

Solution (Python):
from collections import deque

X, N = map(int, input().split())
p = list(map(int, input().split()))
ans = X
queue = deque()
queue.append(X)
done_list = []
ans = []
while queue:
    var = queue.popleft()
    if var in p:
        done_list.append(var)
        if var - 1 not in done_list:
            queue.append(var-1)
        if var + 1 not in done_list:
            queue.append(var+1)
        continue
    else:
        ans = var
        break
print(ans)

Solution (Python):
input = raw_input

exists = [False] * 203

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

inputs = input()
try:
    mid = 101
    ps = map(int, inputs.split(" "))
    for p in ps: 
        if abs(x-p) <= 100:
            diff = p - x
        
        exists[mid+diff] = True


    
    for i in range(0, 102):
        if not exists[mid-i]:
            out = x -i 
            break
        if not exists[mid+i]:
            out = x +i 
            break
except:
    out = x


print(out)

Solution (Python):
import numpy as np

X, N = map(int, input().split())
P = set(map(int, input().split()))
Q = set(range(102))
P = np.array(list(Q - P))
Q = np.abs(P - X)
Q = np.where(Q == Q.min())

print(P[Q].min())

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

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

aln = list(map(lambda y: abs(y-x),al))

if 0 in aln:
    pass
else:
    print(x)
    exit()

for i in range(1,300):
    if aln.count(i) ==2:
        pass
    else:
        if x-i in al:
            print(x+i)
            exit()
        else:
            print(x-i)
            exit()

Solution (Python):
x,n = map(int,input().split())
L = list(map(int,input().split()))
ans = 10**10
li = []
for i in range(-200,201):
    if i not in L:
        ans = min(ans,abs(x-i))
        li.append((ans,i))
li.sort()
print(li[0][1])

Solution (Python):
x, n = map(int, input().split())
if n == 0:
    print(x)
else:
    p = list(map(int, input().split()))
    p.sort()
    mi = 101
    chk = [1 for i in range(0, 102)]
    for i in range(n):
        chk[p[i]] = 0

    for i in range(0, 102):
        if chk[i] == 1:
            if abs(i - x) < mi:
                mi = abs(i - x)
                ans = i
    print(ans)

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

ans = 0

if N == 0:
  ans = X
else:
  p = list(map(int, input().split()))
  for i in range(1, 102):
    if p.count(i)==0 and abs(ans-X) > abs(i-X):
      ans = i
print(ans)

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

N_set = set(p)
flag = True
i = 1

if X not in N_set:
    print(X)
    flag = False
while flag:
    if X-i not in N_set:
        print(X-i)
        break
    if X+i not in N_set:
        print(X+i)
        break
    i += 1

Solution (Python):
x, n = map(int, input().split())
p = list(map(int, input().split()))
y = None
if x in p:
    for i in range(102):
        if i in p:
            continue
        if y is None or abs(x - i) < y:
            y = abs(x - i)
            ans = i
else:
    ans = x
print(ans)

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

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

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

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

res = 1000
for i in range(-1, 102):
    if i not in p:
        res = min(res, abs(x - i))

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

Solution (Python):
import sys
import math
import heapq
import bisect
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res

X,N=LI()
L=LI()
L.sort()



for i in range(1000):
    ip=bisect.bisect_left(L, X+i)
    im=bisect.bisect_left(L, X-i)
    

    res = None
    if ip >= 0 and ip < N:
        if L[ip] != X+i:
            res = X+i
    else:
        res = X+i

    if im >= 0 and im < N:
        if L[im] != X-i:
            res = X-i
    else:
        res = X-i

    if res != None:
        print(res)
        exit()

Solution (Python):

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

    ax, px = x, x
    for i in range(100):
        ax = x + i
        px = x - i
        if px not in p:
            print(px)
            exit(0)
        if ax not in p:
            print(ax)
            exit(0)


if __name__ == "__main__":
    main()

Solution (Python):
A, B = map(int, input().split())
if B != 0:
    li = list(map(int, input().split()))

if B == 0:
    print(A)
else:
    count = 0
    while(1):
        if A - count  not in li:
            print(A-count)
            break
        if A + count not in li:
            print(A + count)
            break
        count += 1

Solution (Python):
X ,N= map(int,input().split())
p=[]
if N!=0:
    p = list(map(int, input().split()))
    p = set(p)
for i in range(101):
    if  not((X-i)in p):
        d = -i
        break
    if not ((X+i)in p):
        d = i
        break
    

print(X+d)

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

not_p = set(range(102)) - set(P)

min_value = 200
min_list = []

for v in not_p:
    dist = abs(X-v)

    if dist < min_value:
        min_value = dist
        min_list = [v]

    if dist == min_value:
        min_list.append(v)

print(min(min_list))

Solution (Python):

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

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

Sa=[]

for i in range(100):
    ma=X+i
    mi=X-i
    if mi not in P:
        print(mi)
        sys.exit()
    elif ma not in P:
        print(ma)
        sys.exit()

Solution (Python):
x, n = map(int, input().split())
ls = list(map(int, input().split()))
if n == 0:
    print(x)
else:
    i, j = 0, 0
    while True:
        if x + i not in ls:
            num1 = x + i
            break
        else:
            i += 1

    while True:
        if x - j not in ls:
            num2 = x - j
            break
        else:
            j += 1

    if abs(x - num1) > abs(x - num2):
        print(num2)
    elif abs(x - num1) < abs(x - num2):
        print(num1)
    else:
        print(min(num1, num2))

Solution (Python):
import sys
x,n=map(int,input().split())
p=set(list(map(int,input().split())))
for i in range(100):
    if x-i in p:
        if x+i in p:

            continue
        else:
            print(x+i)
            sys.exit()
    else:
        print(x-i)
        sys.exit()

Solution (Python):
x,n=map(int,input().split())
if n!=0:
    p=list(map(int,input().split()))
    dif=1000
    ans=-1
    for i in range(0,102):
        if i not in p:
            if abs(x-i)<dif:
                ans=i
                dif=abs(x-i)
    print(ans)
else:
    print(x)

Solution (Python):
x, n = map(int, input().split())
p = list(map(int, input().split()))
ans = float("inf")
for i in range(1000):
    if not x - i in p:
        a = x - i
        break
    elif not x + i in p:
        a = x + i
        break
print(a)

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

a = [i for i in range(1, 1000)]
b = [-i for i in range(1, 1000)]
c = []
for idx in range(len(a)):
    c.append(a[idx])
    c.append(b[idx])
c.append(0)
c.sort()

tmp = []
for i in c:
    if not i in p:
        tmp.append([abs(X-i), i])
tmp2 = [10000000000, -1]
for i in tmp:
    if tmp2[0] > i[0]:
        tmp2[0] = i[0]
        tmp2[1] = i[1]

print(tmp2[1])

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




'''
a=[]
b=[]
for i in range():
    A, B = map(int, input().split())
    a.append(A)
    b.append(B)'''

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

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

for i in range(1,1000-x):
    if x-i not in p:
        print(x-i)
        sys.exit()

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

Solution (Python):
import bisect

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

p.sort()

temp = 100
temp2 = 0

if(n == 0):
    print(x)
else:
    for i in range(102):
        temp3 = abs(x-i)
        if(temp3 < temp):
            flag = 1
            for j in p:
                if(i == j):
                    flag = 0
            if(flag == 1):
                temp2 = i
                temp = temp3
    print(temp2)

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

def func1():
    
    if p.count(x)==0:
        print(x)
        return

    for i in range(100):
        if p.count(x-i)==0:
            print(x-i)
            return
        if p.count(x+i)==0:
            print(x+i)
            return
func1()

Solution (Python):

import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

x, n =na()
p = na()

ans = x
for i in range(100):
    temp = x - i
    if not temp in p:
        print(temp)
        quit()
    temp = x + i
    if not temp in p:
        print(temp)
        quit()

Solution (Python):
def main():
  x,n = map(int,input().split())
  if(n==0):
    print(x)
    return 0
  p = list(map(int,input().split()))
  if(not x in p):
    print(x)
    return 0
  d=1
  while(True):
    if(not x-d in p):
      print(x-d)
      return 0
    elif(not x+d in p):
      print(x+d)
      return 0
    d+=1

main()

Solution (Python):




from __future__ import division, print_function 

import sys
import os
from collections import Counter, deque, defaultdict
import itertools
import math
import io


"""Uncomment modules according to your need"""













if sys.version_info[0] < 3:
    input = raw_input
    range = xrange

    filter = itertools.ifilter
    map = itertools.imap
    zip = itertools.izip



"""value of mod"""
MOD = 998244353
mod = 10**9 + 7

"""Uncomment next 4 lines if doing huge recursion"""




def prepare_factorial(mod=mod):
    """ returns two lists, factorial and inverse factorial modulo argument by default 10**9 +7 """
    
    fact = [1]
    for i in range(1, 200005):
        fact.append((fact[-1] * i) % mod)

    ifact = [0] * 200005
    ifact[200004] = pow(fact[200004], mod - 2, mod)
    for i in range(200004, 0, -1):
        ifact[i - 1] = (i * ifact[i]) % mod

    return fact, ifact

def modinv(n, p):
    """ returns N inverse modulo p """
    return pow(n, p - 2, p)

def ncr(n, r,  fact, ifact):
    """ takes 4 arguments: n , r and factorial and inverse factorial lists"""
    t = (fact[n] * (ifact[r]*ifact[n-r]) % MOD)% MOD
    return t


def get_n(Sum):    
    """this function returns the maximum n for which Summation(n) <= Sum"""
    ans = (-1 + sqrt(1 + 8*Sum))//2
    return ans

def sieve(n):
    """ returns a list of prime numbers till n """
    if n < 2: return list()
    prime = [True for _ in range(n + 1)]
    p = 3
    while p * p <= n:
        if prime[p]:
            for i in range(p * 2, n + 1, p):
                prime[i] = False
        p += 2
    r = [2]
    for p in range(3, n + 1, 2):
        if prime[p]:
            r.append(p)
    return r



def divs(n, start=1):
    """ returns a list of all divisors till n """
    divisors = []
    for i in range(start, int(math.sqrt(n) + 1)):
        if n % i == 0:
            if n / i == i:
                divisors.append(i)
            else:
                divisors.extend([i, n // i])
    return divisors



def divn(n, primes):
    """ returns the number of divisors, two arguments n and the sieve till n """
    divs_number = 1
    for i in primes:
        if n == 1:
            return divs_number
        t = 1
        while n % i == 0:
            t += 1
            n //= i
        divs_number *= t



def lrfind(d, x, default=-1):
    """ Takes 2 arguments an iterable and an element. returns a tuple (firstoccurence,lastoccurence) -1 if not found """
    left = right = -1
    for i in range(len(d)):
        if d[i] == x:
            if left == -1: left = i
            right = i
    if left == -1:
        return default, default
    else:
        return left, right

def gcd(x, y): 
    """ returns greatest common divisor of x and y """
    while y:
        x, y = y, x % y
    return x

def check_sorted(a):
    ''' returns True/False '''
    for i in range(len(a)-1):
        if a[i]>a[i+1]:
            return False
    return True
def ceil(n, k=1): return n // k + (n % k != 0) 
def input(): return sys.stdin.readline().strip()
def ii(): return int(input()) 
def mi(): return map(int, input().split()) 
def li(): return list(map(int, input().split())) 
def lw(): return input().split() 
def lcm(a, b): return abs(a * b) // gcd(a, b) 
def prr(a, sep=' ', end='\n'): print(sep.join(map(str, a)), end=end) 
def dd(): return defaultdict(int) 
def ddl(): return defaultdict(list) 
def write(s): return sys.stdout.write(s)













def main():
    
    x,n=mi()
    p=li()
    s=set(p)
    for i in range(x,102):
        if i not in s:
            c1=i
            break
    for i in range(x,-2,-1):
        if i not in s:
            c2=i
            break
    if(abs(c1-x)<abs(c2-x)):
        print(c1)
    else:
        print(c2)

        











































""" -------- Python 2 and 3 footer by Pajenegod and c1729 ---------"""

py2 = round(0.5)
if py2:
    from future_builtins import ascii, filter, hex, map, oct, zip
    range = xrange

import os, sys
from io import IOBase, BytesIO

BUFSIZE = 8192

class FastIO(BytesIO):
    newlines = 0

    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.writable = "x" in file.mode or "w" in file.mode
        self.write = super(FastIO, self).write if self.writable else None

    def _fill(self):
        s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
        self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
        return s

    def read(self):
        while self._fill(): pass
        return super(FastIO, self).read()

    def readline(self):
        while self.newlines == 0:
            s = self._fill();
            self.newlines = s.count(b"\n") + (not s)
        self.newlines -= 1
        return super(FastIO, self).readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.getvalue())
            self.truncate(0), self.seek(0)


class IOWrapper(IOBase):

    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        if py2:
            self.write = self.buffer.write
            self.read = self.buffer.read
            self.readline = self.buffer.readline
        else:
            self.write = lambda s: self.buffer.write(s.encode('ascii'))
            self.read = lambda: self.buffer.read().decode('ascii')
            self.readline = lambda: self.buffer.readline().decode('ascii')


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip('\r\n')



""" main function"""

if __name__ == '__main__':
    main()

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

ans = float('inf')
cnt = 0
while ans == float('inf'):
  ans_plus = X + cnt
  ans_minus = X - cnt
  if not ans_plus in P:
    ans = ans_plus
  if not ans_minus in P:
    ans = min(ans, ans_minus)
  cnt += 1

print(ans)

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

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

ans = [x]
if x in p:
    ans.remove(x)
    i = x
    while i in p:
        i -= 1
    ans.append(i)
    i = x
    while i in p:
        i += 1
    ans.append(i)
    if abs(ans[0] - x) > abs(ans[1] - x):
        ans = [ans[1]]
    else:
        ans = [ans[0]]

print(ans[0])

Solution (Python):
x, n = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]
a = []
for i in range(-2,102):
    if i not in p:
        a.append(i)

m = []
for i in range(len(a)):
    m.append(abs(a[i] - x))

miner = min(m)
res = []
for i in a:
    if abs(x - i) == miner:
        res.append(i)

print(min(res))

Solution (Python):
import sys

readline = sys.stdin.readline

x, n = map(int, readline().split())
if n == 0:
    ans = x
else:
    p = list(map(int, readline().split()))
    for i in range(100):
        if (x - i not in p):
            ans = x-i
            break
        if (x + i not in p):
            ans = x+i
            break
print(ans)

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

ans = X
for i in range(100):
    flag1 = -i in p
    if flag1 == False:
        ans = X - i
        break
    flag2 = i in p
    if flag2 == False:
        ans = X + i
        break

print(ans)

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

tmp = 10**9
ans = 10**9

if P:
    for p in range(-20, 110):
        if p in P:
            continue
        abs_PX = abs(X-p)
        if abs_PX < tmp:
            ans = p
            tmp = abs_PX
else:
    ans = X

print(ans)

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

    num = list(range(0, 102))

    ans = [0] * len(num)
    inf = 1000
    for i, n in enumerate(num):
        if n in p:
            ans[i] = inf
        else:
            ans[i] = abs(n-X)

    print(ans.index(min(ans)))


if __name__ == "__main__":
    main()

Solution (Python):
x,n = map(int,input().split())
if n==0:
  print(x)
else:
  p = list(map(int,input().split()))
  numberset = set()
  for i in range(0,102):
    numberset.add(i)
  for s in p:
    numberset.remove(s)
  diff = 100
  mindifint = 101
  for s in numberset:
    if abs(s-x)<diff:
      diff = abs(s-x)
      mindifint = s
    elif abs(s-x)==diff:
      mindifint = min(mindifint,s)
  print(mindifint)

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

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

if n != 0:
    P = list(map(int, input().split()))

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

bl = False
i = 1
while not bl:
    if (x - i) not in P:
        print(x - i)
        exit()
    if (x + i) not in P:
        print(x + i)
        exit()
    i += 1

Solution (Python):
x, n = map(int, input().split())
if n == 0:
    print(x)
else:
    p = set(list(map(int, input().split())))
    
    i = 0
    while(True):
        cand1 = x - i
        cand2 = x + i
        if cand1 not in p:
            print(cand1)
            break
        elif cand2 not in p:
            print(cand2)
            break
        i += 1

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

X,N=(int(x) for x in input().rstrip('\n').split())
ps=[int(x) for x in input().rstrip('\n').split()]
if N==0:
  print(X)
else:
  for i in range(100):
    if X-i not in ps:
      print(X-i)
      break
    elif X+i not in ps:
      print(X+i)
      break

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

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