AtCoder Beginner Contest 170 - Forbidden List

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-----
6 5
4 7 10 6 5

-----Sample Output-----
8

Among the integers not contained in the sequence 4, 7, 10, 6, 5, the one nearest to 6 is 8.

Difficulty: EASY

Starter code:

Solutions:
(X, N) = map(int, input().split())
P = set(map(int, input().split()))
d = 0
while True:
	x = X - d
	if x not in P:
		break
	x = X + d
	if x not in P:
		break
	d += 1
print(x)


import math
from math import gcd, pi, sqrt
INF = float('inf')
MOD = 10 ** 9 + 7
import sys
sys.setrecursionlimit(10 ** 6)
import itertools
import bisect
from collections import Counter, deque

def i_input():
	return int(input())

def i_map():
	return map(int, input().split())

def i_list():
	return list(i_map())

def i_row(N):
	return [i_input() for _ in range(N)]

def i_row_list(N):
	return [i_list() for _ in range(N)]

def s_input():
	return input()

def s_map():
	return input().split()

def s_list():
	return list(s_map())

def s_row(N):
	return [s_input for _ in range(N)]

def s_row_str(N):
	return [s_list() for _ in range(N)]

def s_row_list(N):
	return [list(s_input()) for _ in range(N)]

def main():
	(X, N) = i_map()
	if N == 0:
		print(X)
		return
	P = i_list()
	dis = INF
	ans = 0
	for i in range(105):
		if i not in P and abs(X - i) < dis:
			dis = abs(X - i)
			ans = i
	print(ans)

def __starting_point():
	main()
__starting_point()


(X, N) = map(int, input().split())
P = set(map(int, input().split()))
ans = 1000
for i in range(-100, 1000):
	if abs(X - i) < abs(X - ans) and i not in P:
		ans = i
print(ans)


(x, n) = map(int, input().split())
p = set(map(int, input().split()))
ans = min((abs(x - i) for i in range(102) if i not in p))
print(x + ans if x - ans in p else x - ans)


(m, n) = map(int, input().split())
l = list(map(int, input().split()))
for i in range(101):
	if m - i not in l:
		print(m - i)
		break
	if m + i not in l:
		print(m + i)
		break


(x, n) = list(map(int, input().split()))
p = list(map(int, input().split()))
for i in range(100):
	num = x - i
	if num not in p:
		print(num)
		return
	num = x + i
	if num not in p:
		print(num)
		return


(X, N) = map(int, input().split())
(*P,) = map(int, input().split())
i = 0
while 1:
	if X - i not in P:
		print(X - i)
		break
	if X + i not in P:
		print(X + i)
		break
	i += 1


(X, N) = map(int, input().split())
P = list(map(int, input().split()))
q = [(abs(X - i), i) for i in range(-110, 210) if not i in P]
q.sort()
print(q[0][1])


(x, n) = map(int, input().split())
try:
	p = sorted([*map(int, input().split())])
except:
	print(x)
	exit()
for i in range(x + 1):
	for s in [-1, 1]:
		a = x + i * s
		if p.count(a) == 0:
			print(a)
			exit()


(X, N, *P) = map(int, open(0).read().split())
S = set(P)
print(min(((abs(i - X), i) for i in range(200) if i not in S))[1])


(x, n, *l) = map(int, open(0).read().split())
print(min(((abs(i - x), i) for i in range(102) if i not in l))[1])


(x, n) = map(int, input().split())
p = list(map(int, input().split()))
a = [999] * 102
for i in range(102):
	if i not in p:
		a[i] = abs(x - i)
print(a.index(min(a)))


print(sorted((lambda n, p: [[p.count(i), abs(n[0] - i), i] for i in range(-1, 102)])(list(map(int, input().split())), list(map(int, input().split()))))[0][2])


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


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


(x, n) = [int(s) for s in input().split()]
p_set = set([int(s) for s in input().split()])
a = 0
while True:
	for i in [-1, 1]:
		y = x + i * a
		if y not in p_set:
			print(y)
			return
	a += 1


(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


(X, N) = map(int, input().split())
p = list(map(int, input().split()))
diff = 0
while True:
	num_p = X + diff
	num_m = X - diff
	if num_m not in p:
		print(num_m)
		break
	elif num_p not in p:
		print(num_p)
		break
	else:
		diff += 1


(x, n) = map(int, input().split())
p = sorted(list(map(int, input().split())))
if x not in p:
	print(x)
else:
	for i in range(1, 100):
		(x_p, x_m) = (x + i, x - i)
		if x_m not in p:
			print(x_m)
			return
		if x_p not in p:
			print(x_p)
			return


(X, N) = map(int, input().split())
ps = list(map(int, input().split()))
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


(x, n) = map(int, input().split())
p = list(map(int, input().split()))
q = x
for i in range(n + 1):
	if not x - i in p:
		q = x - i
		break
	if not x + i in p:
		q = x + i
		break
print(q)


import sys, os.path
sys.setrecursionlimit(10 ** 5)

def mod():
	return 10 ** 9 + 7

def i():
	return sys.stdin.readline().strip()

def ii():
	return int(sys.stdin.readline())

def li():
	return list(sys.stdin.readline().strip())

def mii():
	return map(int, sys.stdin.readline().split())

def lii():
	return list(map(int, sys.stdin.readline().strip().split()))

def solve():
	(a, b) = mii()
	if b == 0:
		print(a)
		return
	c = lii()
	d = 111
	e = 0
	for i in range(max(c) + 2):
		if i not in c:
			if abs(i - a) < d:
				d = abs(i - a)
				e = i
	print(e)
for _ in range(1):
	solve()


(m, n) = map(int, input().split())
p = list(map(int, input().split()))
a = 0
while True:
	if m - a not in p:
		print(m - a)
		break
	elif m + a not in p:
		print(m + a)
		break
	a += 1


(x, n) = map(int, input().split())
p = list(map(int, input().split()))
for i in range(101):
	if x - i not in p:
		print(x - i)
		break
	elif x + i not in p:
		print(x + i)
		break


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


(x, n, *p) = map(int, open(0).read().split())
ex = [0] * 102
for i in p:
	ex[i] = 1
ans = 0
for i in range(102):
	if ex[i] == 0 and abs(x - i) < abs(x - ans):
		ans = i
print(ans)


(X, N) = map(int, input().split())
P = list(map(int, input().split()))
min = 51
for i in range(102):
	if i not in P and abs(X - i) < min:
		min = abs(X - i)
		ans = i
print(ans)


(X, N) = map(int, input().split())
P = [int(_) for _ in input().split()]
for s in range(X + 1):
	for t in [-1, +1]:
		u = X + s * t
		if P.count(u) == 0:
			print(u)
			exit()


(X, N) = map(int, input().split())
A = list(map(int, input().split()))
import sys
for d in range(X + 1):
	for i in [-1, 1]:
		B = X + d * i
		if A.count(B) == 0:
			print(B)
			sys.exit()


(X, N) = map(int, input().split())
P = set(map(int, input().split()))
for i in range(X + 1):
	if X - i not in P:
		print(X - i)
		break
	elif X + i not in P:
		print(X + i)
		break


(x, n, *p) = map(int, open(0).read().split())
print(min({*range(999)} - {*p}, key=lambda y: (abs(y - x), y)))


(x, n) = map(int, input().split())
l = list(map(int, input().split()))
ans = 0
m = abs(ans - x)
for i in range(102):
	if not i in l and m > abs(i - x):
		ans = i
		m = abs(i - x)
print(ans)


(x, n) = map(int, input().split())
L = list(map(int, input().split()))
(l, r) = (x - 1, x + 1)
if n == 0 or x not in L:
	print(x)
	return
while True:
	if l not in L:
		print(l)
		break
	elif r not in L:
		print(r)
		break
	l -= 1
	r += 1


[X, N] = [int(i) for i in input().split()]
if N == 0:
	P = []
else:
	P = [int(i) for i in input().split()]
if P.count(X) == 0:
	print(X)
else:
	for i in range(100):
		if P.count(X - i) == 0:
			print(X - i)
			break
		elif P.count(X + i) == 0:
			print(X + i)
			break


(X, N) = map(int, input().split())
if N == 0:
	print(X)
	exit()
P = list(map(int, input().split()))
ans = -1
for i in range(-1, 102):
	if i not in P:
		if abs(X - i) < abs(X - ans):
			ans = i
print(ans)


(x, n) = map(int, input().split())
p = list(map(int, input().split()))
l = [i for i in range(102)]
for j in p:
	l.remove(j)
m = []
for k in l:
	m.append(abs(k - x))
print(l[m.index(min(m))])


(x, n) = map(int, input().split())
p = set(map(int, input().split()))
differ = 0
while x + differ in p and x - differ in p:
	differ += 1
print(int(x - differ if x - differ not in p else x + differ))


(X, N) = map(int, input().split())
if N == 0:
	P = []
else:
	P = list(map(int, input().split()))
	P = sorted(P)
assert len(P) == N
cands = []
x = X
while True:
	if x not in P:
		cands.append(x)
		break
	x -= 1
x = X
while True:
	if x not in P:
		cands.append(x)
		break
	x += 1
(a, b) = cands
if abs(a - X) > abs(b - X):
	print(b)
else:
	print(a)


(x, n) = list(map(int, input().split()))
p = [int(v) for v in input().split()]
ans = None
if x not in p:
	ans = x
else:
	diff = 101
	for i in range(0, max(p) + 2):
		if abs(x - i) < diff and i not in p:
			ans = i
			diff = abs(x - i)
print(ans)


(X, N) = map(int, input().split())
list1 = list(map(int, input().split()))
k = 100
for i in range(0, 150):
	d = abs(X - i)
	if d < k and i not in list1:
		k = d
		A = i
print(A)


(x, n) = map(int, input().split())
p = list(map(int, input().split()))
ans = 0
for i in range(102):
	if i in p:
		continue
	if abs(i - x) < abs(ans - x):
		ans = i
print(ans)


(x, n) = map(int, input().split())
p = list(map(int, input().split()))
p = set(p)
ans = 0
for i in range(102):
	if i not in p and abs(ans - x) > abs(i - x):
		ans = i
print(ans)


(x, n) = list(map(int, input().split()))
p = list(map(int, input().split()))
gap = x
ans = 0
for y in range(102):
	if y not in p:
		if abs(x - y) < gap:
			gap = abs(x - y)
			ans = y
print(ans)


(x, n) = list(map(int, input().split()))
p = list(map(int, input().split()))
q = set(range(-1, 100 + 2)) - set(p)
f = []
for e in q:
	f.append((abs(e - x), e - x))
print(x + min(f)[1])


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


(X, N) = map(int, input().split())
p = list(map(int, input().split()))
s = list(range(0, 102))
for pi in p:
	s.remove(pi)
y = [(abs(pi - X), pi) for pi in s]
ans = min(y)[1]
print(ans)


(x, n) = map(int, input().split())
p = list(map(int, input().split()))
i = 0
while x + i in p and x - i in p:
	i += 1
if x - i not in p:
	print(x - i)
else:
	print(x + i)


import bisect
(X, N) = map(int, input().split())
if N == 0:
	print(X)
else:
	p = set(map(int, input().split()))
	num_list = set([i for i in range(-1, 102)])
	num_list = sorted(list(num_list ^ p))
	nummin = num_list[bisect.bisect_left(num_list, X)]
	nummax = num_list[bisect.bisect_right(num_list, X)]
	if nummin == nummax:
		nummin = num_list[bisect.bisect_left(num_list, X) - 1]
	if X - nummin <= nummax - X:
		print(nummin)
	else:
		print(nummax)


(X, N) = map(int, input().split())
(*P,) = map(int, input().split())
d = 200
ans = 0
for i in range(102):
	if i in P:
		continue
	if d > abs(X - i):
		d = abs(X - i)
		ans = i
print(ans)


(x, n) = map(int, input().split())
p = list(map(int, input().split()))
s = set(p)
for i in range(200):
	if x - i not in s:
		exit(print(x - i))
	if x + i not in s:
		exit(print(x + i))


(x, n) = map(int, input().split())
if n == 0:
	print(x)
	return
pp = list(map(int, input().split()))
for i in range(52):
	x_p = x + i
	x_m = x - i
	if x_m not in pp:
		print(x_m)
		return
	elif x_p not in pp:
		print(x_p)
		return


(x, n) = map(int, input().split())
b = float('INF')
ans = 0
l = set(map(int, input().split()))
for i in range(-100, 200):
	if i in l:
		continue
	if b > abs(x - i):
		b = abs(x - i)
		ans = i
print(ans)


(x, n) = map(int, input().split())
L = list(map(int, input().split()))
if n == 0 or x not in L:
	print(x)
	return
for i in range(102):
	if x - i not in L:
		print(x - i)
		break
	elif x + i not in L:
		print(x + i)
		break


(x, n, *l) = map(int, open(0).read().split())
l = set(l)
t = 101
for i in range(102):
	if i not in l and abs(i - x) < t:
		(a, t) = (i, abs(i - x))
print(a)


(x, n, *p) = map(int, open(0).read().split())
l = r = x
while 1:
	if l not in p:
		print(l)
		break
	l -= 1
	if r not in p:
		print(r)
		break
	r += 1


(x, n) = map(int, input().split())
p = list(map(int, input().split()))
a = [i for i in range(102)]
b = list(set(a) - set(p))
ans = 100
for i in range(len(b)):
	c = abs(b[i] - x)
	ans = min(ans, c)
up = x + ans
down = x - ans
if up in set(p):
	print(down)
	return
elif down in set(p):
	print(up)
	return
print(min(up, down))


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


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


R = lambda : map(int, input().split())
(x, n) = R()
print(min(((abs(x - y), y) for y in set(range(102)) - set(R())))[1])


(X, N) = map(int, input().split())
p = list(map(int, input().split()))
ans = 0
for i in range(102):
	if i not in p:
		if abs(i - X) < abs(ans - X):
			ans = i
print(ans)


(x, n) = list(map(int, input().split()))
p = list(map(int, input().split()))
pN = [i for i in range(102) if i not in p]
pm = [abs(i - x) for i in pN]
print(pN[pm.index(min(pm))])


(X, N, *P) = map(int, open(0).read().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


(X, N) = map(int, input().split())
P = list(map(int, input().split()))
for i in range(101):
	for x in [X - i, X + i]:
		if x not in P:
			print(x)
			exit()


(x, n) = map(int, input().split())
s = set(map(int, input().split()) if n != 0 else '')
i = 0
while x + i in s:
	if i >= 0:
		i += 1
	i *= -1
print(x + i)


(x, n) = map(int, input().split())
P = list(map(int, input().split()))
P = set(P)
A = []
for i in range(102):
	if i not in P:
		A.append((abs(x - i), i))
A.sort()
print(A[0][1])


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

def ans170(X: int, N: int, p: str):
	p_list = list(map(int, p.split()))
	count = 1
	if len(p) == 0:
		return X
	elif X not in p_list:
		return X
	else:
		while True:
			if X - count not in p_list:
				return X - count
				break
			elif X + count not in p_list:
				return X + count
				break
			else:
				count += 1
print(ans170(X, N, p))


(x, n) = map(int, input().split())
p = []
if n:
	p = list(map(int, input().split()))
ans = None
mi = float('inf')
for i in range(-300, 300):
	if i not in p:
		if mi > abs(x - i):
			mi = abs(x - i)
			ans = i
print(ans)


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

def f():
	for d in range(x + 1):
		for s in [-1, +1]:
			a = d * s + x
			if p.count(a) == 0:
				print(a)
				exit()
f()


(X, N) = map(int, input().split())
A = list(map(int, input().split()))
a = 0
while True:
	if X - a not in A:
		print(X - a)
		break
	if X + a not in A:
		print(X + a)
		break
	a += 1


(x, n) = map(int, input().split())
a = set(map(int, input().split()))
print(min([i for i in range(102) if i not in a], key=lambda y: abs(x - y)))


import sys
from collections import deque, defaultdict, Counter
from itertools import accumulate, product, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush
from math import ceil, floor, sqrt, gcd, inf
from copy import deepcopy
import numpy as np
import scipy as sp
INF = inf
MOD = 1000000007
(x, n) = [int(i) for i in input().split()]
P = [int(i) for i in input().split()]
tmp = 0
res = 0
P = np.array(P) - x
while True:
	if not -res in P:
		res *= -1
		break
	if not res in P:
		break
	res += 1
res += x
print(res)


(x, n) = map(int, input().split())
p = set(map(int, input().split()))
for i in range(101):
	(a, b) = (x - i, x + i)
	if a not in p:
		print(a)
		break
	if b not in p:
		print(b)
		break


(X, N) = map(int, input().split())
li = list(map(int, input().split()))
sa = 101
for i in range(102):
	if sa > abs(X - i) and (not i in li):
		sa = abs(X - i)
		ans = i
print(ans)


(x, n) = map(int, input().split())
p = list(map(int, input().split()))
temp = 100
for i in range(x - 51, x + 51):
	a = abs(x - i)
	if a < temp and i not in p:
		temp = a
		ans = [i]
	if a == temp and i not in p:
		ans += [i]
print(min(ans))


(x, n) = map(int, input().split())
p = sorted([int(x) for x in input().split()])
if n == 0:
	print(x)
	return
ans = idx = 10 ** 9
for i in range(-500, 500):
	for pi in p:
		if p.count(i) == 0:
			if ans > abs(i - x):
				ans = abs(i - x)
				idx = i
print(idx)


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


(x, n) = map(int, input().split())
pl = list(map(int, input().split()))
res = -100
for r in range(-100, 200):
	if r not in pl:
		if abs(x - r) < abs(x - res):
			res = r
print(res)


(X, N) = tuple(map(int, input().split()))
P = list(map(int, input().split()))
for i in range(100):
	for j in [-1, 1]:
		t = X + i * j
		if t not in P:
			print(t)
			exit(0)


(x, n) = map(int, input().split())
l = list(map(int, input().split()))
flag = 0
i = 0
while flag == 0:
	if x - i not in l:
		flag = 1
		ansa = x - i
	i += 1
flag = 0
i = 0
while flag == 0:
	if x + i not in l:
		flag = 1
		ansb = x + i
	i += 1
if abs(ansa - x) <= abs(ansb - x):
	print(ansa)
else:
	print(ansb)


(x, n) = map(int, input().split())
if n != 0:
	p = list(map(int, input().split()))
	sa = 102
	ans = []
	for i in range(x, 102):
		if i not in p:
			if sa > i - x:
				sa = i - x
				ans = i
			elif sa == i - x:
				if ans > i:
					ans = i
	for i in range(x):
		if x - i - 1 not in p:
			if sa > i + 1:
				sa = i + 1
				ans = x - i - 1
			elif sa == i + 1:
				if ans > x - i - 1:
					ans = x - i - 1
	print(ans)
else:
	print(x)


(x, n) = map(int, input().split())
l = list(map(int, input().split()))
i = j = x
while i in l:
	i += 1
while j in l:
	j -= 1
if abs(x - i) < abs(x - j):
	print(i)
else:
	print(j)


(x, n, *P) = map(int, open(0).read().split())
for i in range(51):
	if x - i not in P:
		print(x - i)
		break
	if x + i not in P:
		print(x + i)
		break


(x, n) = list(map(int, input().split()))
p = list(map(int, input().split()))
a = 101
b = 101
for i in range(x, 102):
	if i not in p:
		a = i
		b = i - x
		break
for i in range(x - 1, -101, -1):
	if a == x:
		break
	if i not in p:
		c = x - i
		if c <= b:
			a = i
			break
		else:
			break
print(a)


(x, n) = map(int, input().split())
p = set(map(int, input().split()))
if not x in p:
	print(x)
else:
	a = [abs(x - i) if not i in p else 1000 for i in range(-1, 102)]
	print(a.index(min(a)) - 1)


(X, N) = map(int, input().split())
arr = list(map(int, input().split()))
ans = 0
for i in range(1, 102):
	if abs(X - i) < abs(X - ans) and i not in arr:
		ans = i
print(ans)


(x, n) = list(map(int, input().split()))
p = list(map(int, input().split()))
dif = 0
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


(x, m) = map(int, input().split())
a = list(map(int, input().split()))
for i in range(x + 1):
	for s in [-1, 1]:
		b = x + i * s
		if a.count(b) == 0:
			print(b)
			exit()


import bisect
(X, N) = list(map(int, input().split()))
P = set(map(int, input().split()))
A = {i for i in range(102)}
S = list(A - P)
T = bisect.bisect_left(S, X)
if T == 0:
	print(S[0])
elif X - S[T - 1] > S[T] - X:
	print(S[T])
else:
	print(S[T - 1])


(x, n) = map(int, input().split())
l = list(map(int, input().split()))
a = 0
for i in range(100):
	if x - i not in l:
		ans = x - i
		a = i + 1
		break
for i in range(100):
	if x + i not in l:
		ansb = x + i
		ab = i + 1
		break
if a > ab:
	print(ansb)
else:
	print(ans)


(x, n) = map(int, input().split())
P = list(map(int, input().split()))
koho = [i for i in range(-100, 200) if i not in P]
koho.sort(key=lambda a: (abs(a - x), a))
print(koho[0])


import sys
import math
from functools import reduce
from bisect import bisect_left

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

def readInteger():
	return int(readString())

def readStringSet(n):
	return sys.stdin.readline().split(' ')[:n]

def readIntegerSet(n):
	return list(map(int, readStringSet(n)))

def readIntegerMatrix(n, m):
	return [lambda _: readIntegerSet(m) for _ in range(0, n)]

def main(X, N, P):
	mP = {}
	for p in P:
		mP[p] = p
	if X not in mP:
		return X
	i = 0
	while True:
		if X - i not in mP:
			return X - i
		if X + i not in mP:
			return X + i
		i += 1

def __starting_point():
	(_X, _N) = readIntegerSet(2)
	_P = readIntegerSet(_N)
	print(main(_X, _N, _P))
__starting_point()


(x, n) = map(int, input().split())
p = list(map(int, input().split()))
for i in range(x + 1):
	for s in [-1, 1]:
		a = x + i * s
		if p.count(a) == 0:
			print(a)
			exit(0)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
for i in range(n + 1):
	for x in [-1, +1]:
		y = n + x * i
		if y not in a:
			print(y)
			exit(0)


(X, N) = map(int, input().split())
P = sorted(list(map(int, input().split())))
t = 0
for i in range(0, 102):
	if i not in P:
		if abs(X - t) > abs(X - i):
			t = i
print(t)


(X, N) = map(int, input().split())
P = set(map(int, input().split()))
o = []
for i in range(2 * X + 1):
	if i in P:
		continue
	o.append(abs(i - X) * 10000 + i)
print(min(o) % 10000)


(X, N) = map(int, input().split())
p = list(map(int, input().split()))
diff = 99
for x in range(102):
	if x not in p and abs(X - x) < diff:
		diff = abs(X - x)
		ans = x
print(ans)


(x, n) = map(int, input().split())
p = list(map(int, input().split()))
l = r = x
while 1:
	if l not in p:
		print(l)
		break
	l -= 1
	if r not in p:
		print(r)
		break
	r += 1


(x, n) = map(int, input().split())
p = set(map(int, input().split()))
l = set(range(-100, 201)) - p
ans = 0
tmp = 1000
for i in l:
	if tmp > abs(x - i):
		ans = i
		tmp = abs(x - i)
print(ans)


(x, n) = map(int, input().split())
p = list(map(int, input().split()))
num1 = 0
num2 = 0
if n == 0:
	print(x)
	return
for i in range(100):
	num1 = x - i
	num2 = x + i
	if not num1 in p and (not num2 in p):
		print(num1)
		return
	elif not num2 in p:
		print(num2)
		return
	elif not num1 in p:
		print(num1)
		return


(X, N) = map(int, input().split())
p = list(map(int, input().split()))
ans = -100
for i in range(-10, 110, 1):
	if not i in p:
		if abs(X - ans) > abs(X - i):
			ans = i
print(ans)


(x, n) = list(map(int, input().split()))
p = list(map(int, input().split()))
l = x
r = x
while True:
	if l not in p and r not in p:
		print(l)
		return
	elif l not in p:
		print(l)
		return
	elif r not in p:
		print(r)
		return
	l -= 1
	r += 1


(X, N) = map(int, input().split())
a = list(map(int, input().split()))
s = set(a)
ans = 0
for i in range(-1, 102):
	if i not in s and abs(ans - X) > abs(i - X):
		ans = i
print(ans)


(X, N) = map(int, input().split())
p = list(map(int, input().split()))
for d in range(X + 1):
	for s in [-1, +1]:
		a = X + s * d
		if p.count(a) == 0:
			print(a)
			return


(x, n, *a) = map(int, open(0).read().split())
b = [1] * 103
for i in a:
	b[i] = 0
c = 1000
ans = n
for i in range(102):
	if b[i] and c > abs(x - i):
		c = abs(x - i)
		ans = i
print(ans)


(X, N) = map(int, input().split())
p = list(map(int, input().split()))
for i in range(X + 1):
	for j in [-1, 1]:
		a = X + j * i
		if a not in p:
			print(a)
			exit()


import sys
(x, n) = map(int, input().split())
p = list(map(int, input().split()))
p.sort()
if n == 0:
	print(x)
	return
if x not in p:
	print(x)
	return
q = list((i for i in range(p[0] - 1, p[-1] + 2)))
for i in p:
	q.remove(i)
ans = []
c = x + n
for i in q:
	if c > abs(x - i):
		c = abs(x - i)
		ans.clear()
		ans.append(i)
	if c == abs(x - i):
		ans.append(i)
print(min(ans))


import numpy as np
(x, y) = list(map(int, input().split()))
p = input().split()
pn = [int(tmp) for tmp in p]
if y == 0:
	ans = x
elif not np.where(np.array(pn) == x)[0].size:
	ans = x
else:
	for i in range(1, 100):
		x1 = x + i
		x2 = x - i
		if not np.where(np.array(pn) == x2)[0].size:
			ans = x2
			break
		elif not np.where(np.array(pn) == x1)[0].size:
			ans = x1
			break
		else:
			continue
print(ans)


(x, n) = map(int, input().split())
p = list(map(int, input().split()))
l = list()
k = list()
for i in range(102):
	if i not in p:
		l.append(i)
for i in range(len(l)):
	k.append(abs(x - l[i]))
m = k.index(min(k))
print(l[m])


(x, n) = input().split()
x = int(x)
list = input().split()
diff = 200
for i in range(-1, 102):
	if str(i) not in list and abs(i - x) < diff:
		diff = abs(i - x)
		ans = i
print(ans)


(x, n) = map(int, input().split())
p = list(map(int, input().split()))
for i in range(n):
	if p[i] - x >= 0:
		p[i] = 2 * (p[i] - x)
	else:
		p[i] = (x - p[i]) * 2 - 1
p = sorted(p)
i = 0
while i in p:
	i += 1
if i % 2 == 0:
	j = round(i / 2) + x
else:
	j = x - round((i + 1) / 2)
print(j)


(x, n) = map(int, input().split())
P = list(map(int, input().split()))
notP = list(range(-10, 110))
for p in P:
	notP.remove(p)
ans = min(notP, key=lambda y: abs(x - y))
print(ans)


(X, N) = map(int, input().split())
p = list(map(int, input().split()))
Q = [0] * 102
for i in range(0, 102):
	Q[i] = abs(X - i)
for i in p:
	Q[i] = 1000
print(Q.index(min(Q)))


(X, N) = map(int, input().split())
p = list(map(int, input().split()))
q = [(abs(X - i), i) for i in range(0, 102) if not i in p]
q.sort()
print(q[0][1])


(x, n) = map(int, input().split())
if n == 0:
	print(x)
	return
p = [int(y) for y in input().split()]
a = 0
for i in range(101):
	if x - a not in p:
		print(x - a)
		break
	elif x + a not in p:
		print(x + a)
		break
	a += 1


(x, n) = list(map(int, input().split()))
p = list(map(int, input().split()))
ans = 0
d_ans = 101
for i in range(-1, 102):
	for j in p:
		if i == j:
			break
	else:
		d = abs(x - i)
		if d_ans > d:
			ans = i
			d_ans = d
		elif d_ans == d and ans > i:
			ans = i
print(ans)


import math
(X, N) = map(int, input().split())
P = list(map(int, input().split()))
ans_1 = X
ans_2 = X
while True:
	if ans_1 not in P:
		print(ans_1)
		return
	ans_1 -= 1
	if ans_2 not in P:
		print(ans_2)
		return
	ans_2 += 1


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, bisect
import sys
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
mod = 10 ** 9 + 7
stdin = sys.stdin
ni = lambda : int(ns())
nf = lambda : float(ns())
na = lambda : list(map(int, stdin.readline().split()))
nb = lambda : list(map(float, stdin.readline().split()))
ns = lambda : stdin.readline().rstrip()
(X, N) = na()
p = na()
kouho = []
for i in range(-100, 200):
	if i in p:
		continue
	kouho.append((abs(X - i), i))
print(min(kouho)[1])


(x, n, *p) = map(int, open(0).read().split())
for i in range(101):
	if x - i not in p:
		print(x - i)
		exit()
	elif x + i not in p:
		print(x + i)
		exit()


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


(x, n) = map(int, input().split())
p = list(map(int, input().split()))
cnt = 0
while 1:
	key = x + (-1) ** cnt * ((cnt + 1) // 2)
	if key not in p:
		print(key)
		break
	cnt += 1


(x, n, *p) = map(int, open(0).read().split())
a = [[i, abs(x - i)] for i in range(0, 102) if i not in p]
a.sort(key=lambda x: x[1])
print(a[0][0])


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)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
for i in range(100):
	if n - i not in a:
		print(n - i)
		break
	elif n + i not in a:
		print(n + i)
		break


def ri():
	return int(input())

def rii():
	return [int(v) for v in input().split()]

def solve():
	(X, N) = rii()
	P = set(rii())
	n = m = float('inf')
	if not P:
		print(X)
		return
	for i in range(min(P) - 1, max(P) + 2):
		if i not in P:
			d = abs(i - X)
			if d == m:
				n = min(n, i)
			elif d < m:
				m = d
				n = i
	print(n)

def __starting_point():
	solve()
__starting_point()


(X, N) = (int(x) for x in input().split())
p = sorted(list((int(x) for x in input().split())))
if N == 0:
	print(X)
elif N == 1:
	if p[0] == X:
		print(X - 1)
	else:
		print(X)
else:
	ans = float('inf')
	for z in range(0, p[0]):
		if (ans - X) ** 2 > (z - X) ** 2:
			ans = z
	for i in range(N - 1):
		for z in range(p[i] + 1, p[i + 1]):
			if (ans - X) ** 2 > (z - X) ** 2:
				ans = z
	for z in range(p[-1] + 1, 102):
		if (ans - X) ** 2 > (z - X) ** 2:
			ans = z
	print(ans)


(x, n, *P) = map(int, open(0).read().split())
P = set(P)
for i in range(51):
	Q = {x - i, x + i} - P
	if Q:
		print(min(Q))
		break


(X, N) = map(int, input().split())
P = list(map(int, input().split()))
res = 10 ** 15
for i in range(-120, 120):
	if i in P:
		continue
	if abs(i - X) < abs(res - X):
		res = i
print(res)


(x, n) = map(int, input().split())
p = list(map(int, input().split()))
for i in range(x + 1):
	for j in [-1, +1]:
		a = x + i * j
		if a not in p:
			print(a)
			exit()


(x, n) = [int(s) for s in input().split()]
p_set = set([int(s) for s in input().split()])
a = 0
while True:
	if x - a not in p_set:
		print(x - a)
		break
	if x + a not in p_set:
		print(x + a)
		break
	a += 1


(x, n) = map(int, input().split())
p = list(map(int, input().split()))
ans = 101
for i in range(103):
	if 101 - i not in p:
		if abs(x - (101 - i)) <= abs(x - ans):
			ans = 101 - i
print(ans)


(X, N) = list(map(int, input().split()))
p = list(map(int, input().split()))
k = 0
if N != 0:
	while X - k in p and X + k in p:
		k += 1
	if X - k not in p:
		print(X - k)
	else:
		print(X + k)
else:
	print(X)


(x, n) = map(int, input().split())
p = list(map(int, input().split()))
p.sort()
res = 0
for i in range(102):
	if i not in p:
		if abs(x - res) > abs(x - i):
			res = i
print(res)


(X, N) = map(int, input().split())
P = list(map(int, input().split()))
Q = [q for q in range(-1, 102) if q not in P]
ans = min(Q, key=lambda q: (abs(q - X), q))
print(ans)


(x, n) = map(int, input().split())
p = list(map(int, input().split()))
m = 100
a = x
for i in range(-101, 201):
	if i not in p:
		z = abs(i - x)
		if m > z:
			m = z
			a = i
print(a)


(X, N) = map(int, input().split())
p = list(map(int, input().split()))
print(min([i for i in range(0, 102) if i not in p], key=lambda i: (abs(X - i), i)))


(X, N) = map(int, input().split())
P = set(map(int, input().split()))
l = [0] + [(1 + i // 2) * (-1 if i % 2 == 0 else 1) for i in range(101)]
for i in l:
	if X + i not in P:
		print(X + i)
		break


(x, n) = list(map(int, input().split()))
p = list(map(int, input().split()))
y = x
z = x
if x not in p:
	print(x)
	return
for i in range(2 * len(p)):
	y -= 1
	z += 1
	if y not in p:
		print(y)
		return
	if z not in p:
		print(z)
		return


import sys
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
from math import floor, sqrt, factorial, hypot, log
from heapq import heappop, heappush, heappushpop
from collections import Counter, defaultdict, deque
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint

def ceil(a, b):
	return (a + b - 1) // b
inf = float('inf')
mod = 10 ** 9 + 7

def pprint(*A):
	for a in A:
		print(*a, sep='\n')

def INT_(n):
	return int(n) - 1

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

def MF():
	return map(float, input().split())

def MI_():
	return map(INT_, input().split())

def LI():
	return list(MI())

def LI_():
	return [int(x) - 1 for x in input().split()]

def LF():
	return list(MF())

def LIN(n: int):
	return [I() for _ in range(n)]

def LLIN(n: int):
	return [LI() for _ in range(n)]

def LLIN_(n: int):
	return [LI_() for _ in range(n)]

def LLI():
	return [list(map(int, l.split())) for l in input()]

def I():
	return int(input())

def F():
	return float(input())

def ST():
	return input().replace('\n', '')

def main():
	(X, N) = MI()
	P = set(LI())
	for i in range(N + 1):
		if X - i not in P:
			print(X - i)
			return
		if X + i not in P:
			print(X + i)
			return

def __starting_point():
	main()
__starting_point()


(X, N) = map(int, input().split())
ps = list(map(int, input().split()))
s = set(range(0, 101 + 1)) - set(ps)
m = min([abs(p - X) for p in s])
if X - m in s:
	r = X - m
else:
	r = X + m
print(r)


(X, N) = map(int, input().split())
P = list(map(int, input().split()))
for n in range(100):
	if X - n not in P:
		print(X - n)
		break
	if X + n not in P:
		print(X + n)
		break


(x, n) = map(int, input().split())
l = list(map(int, input().split()))
y = x
while True:
	if x not in l:
		print(x)
		break
	if y not in l:
		print(y)
		break
	x -= 1
	y += 1


(x, n) = list(map(int, input().split()))
p = list(map(int, input().split()))
if n:
	l = [0 for _ in range(102)]
	for i in p:
		l[i] = 1
	for i in range(101):
		if l[x - i] == 0:
			ans = x - i
			break
		if l[x + i] == 0:
			ans = x + i
			break
	print(ans)
else:
	print(x)


(X, N) = map(int, input().split())
if N:
	P = set(map(int, input().split()))
else:
	P = set()
c = []
for i in range(102):
	if i not in P:
		c.append((abs(i - X), i))
print(min(c)[1])


(X, N) = map(int, input().split())
if N == 0:
	print(X)
	exit()
p = [int(i) for i in input().split()]
q = set(range(102)) - set(p)
r = sorted(q, key=lambda x: (abs(x - X), x))
print(r[0])


(X, N) = list(map(int, input().split()))
p = list(map(int, input().split()))
ans = None
diff = 1000
if X not in p:
	ans = X
else:
	for i in range(-1, max(max(p), X) + 2):
		if i in p:
			continue
		if abs(X - i) < diff:
			diff = abs(X - i)
			ans = i
print(ans)


(X, N) = map(int, input().split())
p = set(map(int, input().split()))
t = 200
a = 1000
for i in range(101, -1, -1):
	if i not in p:
		if abs(i - X) <= t:
			a = i
			t = abs(i - X)
print(a)


(X, N) = map(int, input().split())
ps = list(map(int, input().split()))
(bgr, smr) = (X, X)
while bgr <= 100:
	if bgr not in ps:
		break
	bgr += 1
while smr >= 1:
	if smr not in ps:
		break
	smr -= 1
print(bgr) if bgr - X < X - smr else print(smr)


(X, N) = list(map(int, input().split()))
flg = False
i = 1
if N == 0:
	Ans = X
else:
	S = list(map(int, input().split()))
	if X not in S:
		Ans = X
		flg = True
	while not flg:
		if X - i not in S:
			Ans = X - i
			flg = True
			break
		elif X + i not in S:
			Ans = X + i
			flg = True
			break
		else:
			i += 1
print(Ans)


(x, n) = map(int, input().split())
p = list(map(int, input().split()))
for i in range(101):
	if x - i not in p:
		print(x - i)
		exit(0)
	if x + i not in p:
		print(x + i)
		exit(0)


I = lambda : list(map(int, input().split()))
(x, n) = I()
l = I()
for i in range(101):
	if x - i not in l:
		print(x - i)
		break
	elif x + i not in l:
		print(x + i)
		break


(x, n) = map(int, input().split())
p = list(map(int, input().split()))
ans = x
for i in range(300):
	if ans in p:
		ans += (-1) ** (i + 1) * (i + 1)
	else:
		print(ans)
		break


(x, n, *lst) = map(int, open(0).read().split())
for i in range(x + 1):
	if x - i not in lst:
		print(x - i)
		quit()
	if x + i not in lst:
		print(x + i)
		quit()


(X, N) = map(int, input().split())
p = sorted([int(i) for i in input().split()])
a = X
b = X
for i in range(100):
	if a not in p:
		print(a)
		return
	elif b not in p:
		print(b)
		return
	else:
		a -= 1
		b += 1


(x, n) = map(int, input().split())
n = sorted(map(int, input().split()))
for i in range(101):
	if not x - i in n:
		print(x - i)
		exit()
	if not x + i in n:
		print(x + i)
		exit()


(X, N, *P) = map(int, open(0).read().split())
cand = []
P = set(P)
for i in range(0, 102):
	if i in P:
		continue
	cand.append((abs(X - i), i))
cand.sort()
print(cand[0][1])


(X, N) = list(map(int, input().split()))
P = list(map(int, input().split()))
l = [i for i in range(102)]
l = list(set(l) - set(P))
print(min(l, key=lambda n: abs(X - n)))


(X, N) = map(int, input().split())
P = list(map(int, input().split()))
ans = 0
for a in range(X + 1):
	for s in [-1, +1]:
		ans = X + s * a
		if P.count(ans) == 0:
			print(ans)
			return


(x, n) = list(map(int, input().split()))
p = sorted(list(map(int, input().split())))
a = 100
b = 0
for i in range(0, 102):
	if i not in p and abs(x - i) < a:
		a = abs(x - i)
		b = i
print(b)


(x, n) = list(map(int, input().split()))
p = list(map(int, input().split()))
for i in range(x + 1):
	for j in [-1, 1]:
		ans = x + i * j
		if not p.count(ans):
			print(ans)
			return


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


(X, N) = map(int, input().split())
num = list(map(int, input().split()))
a = X
b = X
while a in num and b in num:
	a += 1
	b -= 1
if b not in num:
	print(b)
elif a not in num:
	print(a)


import sys
input = iter(sys.stdin.read().splitlines()).__next__
sys.setrecursionlimit(10000)
(X, N) = list(map(int, input().split()))
S = set(map(int, input().split()))
bestr = 0
for r in range(0, 102):
	if r not in S:
		if abs(r - X) < abs(bestr - X):
			bestr = r
print(bestr)


(x, n) = map(int, input().split())
p = list(map(int, input().split()))
(w, cnt) = (0, 0)
while cnt < 201:
	if x + w not in p:
		print(x + w)
		break
	w += (-1) ** cnt * cnt
	cnt += 1


def main(X, N, P):
	ans = None
	min_dis = 100000000.0
	for i in range(102):
		if i in P:
			continue
		if abs(X - i) < min_dis:
			ans = i
			min_dis = abs(X - i)
	return ans

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


from typing import List

def answer(x: int, n: int, p: List[int]) -> int:
	not_included = set(range(0, 102)).difference(p)
	return sorted(not_included, key=lambda i: abs(i - x))[0]

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

def __starting_point():
	main()
__starting_point()


(x, n) = map(int, input().split())
p = [int(s) for s in input().split()]
for i in range(x + 1):
	for j in range(-1, +2):
		a = x + i * j
		if p.count(a) == 0:
			print(a)
			return


(x, n) = map(int, input().split())
p = [int(x) for x in input().split()]
for i in range(102):
	if x - i not in p:
		print(x - i)
		exit()
	if x + i not in p:
		print(x + i)
		exit()


(X, N) = map(int, input().split())
(*P,) = map(int, input().split())
cand = set(range(-50, 151)) - set(P)
cand = sorted([c for c in cand], key=lambda x: (abs(X - x), x))
print(cand[0])


(X, N) = map(int, input().split())
p = list(map(int, input().split()))
S = []
for i in range(110):
	if i in p:
		S.append(100)
	else:
		S.append(abs(i - X))
print(S.index(min(S)))


(x, n) = map(int, input().split())
p = [int(s) for s in input().split()]
min_val = 101
for i in range(102):
	if i not in p:
		if abs(i - x) < min_val:
			min_val = abs(i - x)
			ans = i
print(ans)


(x, n) = list(map(int, input().split()))
if n == 0:
	print(x)
	return
nums = list(map(int, input().split()))
cnt = 0
while True:
	if x - cnt not in nums:
		print(x - cnt)
		break
	if x + cnt not in nums:
		print(x + cnt)
		break
	cnt += 1


(X, N) = list(map(int, input().split()))
if N == 0:
	print(X)
	return
p = list(map(int, input().split()))
p = sorted(p)
flag = 0
x = 0
while flag == 0:
	n = X - x
	if n in p:
		n = X + x
		if n in p:
			x += 1
		else:
			flag = 1
	else:
		flag = 1
print(n)


(X, N) = map(int, input().split())
(*P,) = map(int, input().split())
print(min([i for i in range(102) if (i in P) ^ 1], key=lambda i: abs(i - X)))


(X, N) = map(int, input().split())
p = list(map(int, input().split()))
m = 100
for i in range(102):
	diff = abs(X - i)
	if i not in p and diff < m:
		ans = i
		m = diff
print(ans)


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


(a, b) = map(int, input().split())
s = list(map(int, input().split()))
num1 = 0
num2 = 0
if b == 0:
	print(a)
	return
for i in range(100):
	num1 = a - i
	num2 = a + i
	if not num1 in s and (not num2 in s):
		print(num1)
		return
	if not num1 in s:
		print(num1)
		return
	if not num2 in s:
		print(num2)
		return


(X, N) = map(int, input().split())
if N == 0:
	print(X)
else:
	p = set(map(int, input().split()))
	i = -1
	for j in range(102):
		if abs(X - j) < abs(X - i) and (not j in p):
			i = j
	print(i)


import math

def i_input():
	return int(input())

def i_map():
	return list(map(int, input().split()))

def i_list():
	return list(map(int, input().split()))

def i_row(N):
	return [int(input()) for _ in range(N)]

def i_row_list(N):
	return [list(map(int, input().split())) for _ in range(N)]
(x, n) = i_map()
pp = i_list()
nums = list(range(1000))
nums.append(-1)
for p in pp:
	nums[p] = 10 ** 3
ans = 10 ** 18
ch = 10 ** 18
for num in nums:
	if ch > abs(x - num):
		ch = abs(x - num)
		ans = num
print(ans)


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

def ok(n):
	if not n in a:
		print(n)
		exit()
for i in range(1000):
	ok(x - i)
	ok(x + i)


(x, n) = map(int, input().split())
p = list(map(int, input().split()))
m = 102
j = 0
for i in range(0, 102):
	if abs(x - i) < m and i not in p:
		m = abs(x - i)
		j = i
print(j)


(x, n) = map(int, input().split())
p = list(map(int, input().split()))
a = 101
m = 101 - x
for i in range(102):
	i = 100 - i
	if i in p:
		continue
	M = abs(i - x)
	if M <= m:
		m = M
		a = i
print(a)


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

def main():
	if len(p) == 0:
		print(X)
		return
	if X < p[0] and p[-1] < X:
		print(X)
	keep = True
	i = 0
	while keep:
		left_found = X - i not in p
		right_found = X + i not in p
		if left_found and right_found:
			print(X - i)
			keep = False
		elif left_found:
			print(X - i)
			keep = False
		elif right_found:
			print(X + i)
			keep = False
		i += 1

def __starting_point():
	main()
__starting_point()


(x, n) = map(int, input().split())
li_p = list(map(int, input().split()))
li_p.sort()
i = 0
while True:
	a = x - i
	b = x + i
	if not a in li_p:
		print(a)
		break
	elif a in li_p and (not b in li_p):
		print(b)
		break
	elif a in li_p and b in li_p:
		i += 1


(x, n) = map(int, input().split())
y = list(map(int, input().split()))
a = x
for i in range(100):
	if x - i not in y:
		a = x - i
		break
	if x + i not in y:
		a = x + i
		break
print(a)


(X, N) = map(int, input().split())
p = list(map(int, input().split()))
ans = 0
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)


(x, n) = map(int, input().split())
S = map(int, input().split())
K = list(range(0, 102))
for i in S:
	K.remove(i)
L = []
for i in K:
	L.append(abs(x - i))
m = min(L)
ind_m = L.index(m)
print(K[ind_m])


(X, N) = map(int, input().split())
p = list(map(int, input().split()))
if not X in p:
	print(X)
	return
left = -200
for a in range(X - 1, -1, -1):
	if not a in p:
		left = a
		break
right = 200
for a in range(X + 1, 102):
	if not a in p:
		right = a
		break
if X - left > right - X:
	print(right)
else:
	print(left)


import sys
(X, N) = map(int, input().split())
p = input().split()
for i in range(100):
	if not str(X - i) in p:
		print(X - i)
		sys.exit()
	if not str(X + i) in p:
		print(X + i)
		sys.exit()


from bisect import bisect
(x, n) = map(int, input().split())
p = list(map(int, input().split()))
for i in range(100):
	if not x - i in p:
		print(x - i)
		break
	if not x + i in p:
		print(x + i)
		break


(x, n, *p) = map(int, open(0).read().split())
p.sort()
d = 0
while 1:
	if not x - d in p:
		print(x - d)
		break
	elif not x + d in p:
		print(x + d)
		break
	d += 1


(X, N, *p) = map(int, open(0).read().split())
dif = 100
ans = -1
for i in range(102):
	a = abs(X - i)
	if i in p:
		continue
	if a < dif:
		dif = a
		ans = i
print(ans)


(x, n) = map(int, input().split())
ppp = []
if n != 0:
	ppp = list(map(int, input().split()))
ans = 0
for i in range(101):
	if x - i not in ppp:
		ans = x - i
		break
	if x + i not in ppp:
		ans = x + i
		break
print(ans)


(X, n) = map(int, input().split())
print(min(set(range(0, 102)) - set(map(int, input().split())), key=lambda x: abs(x - X)))


(x, n) = map(int, input().split())
l = list(map(int, input().split()))
ans = 200
for i in range(-200, 200):
	if i not in l and abs(x - i) < abs(x - ans):
		ans = i
print(ans)


(x, n) = map(int, input().split())
g = set(map(int, input().split()))
l = r = x
while 1:
	if l in g:
		l -= 1
	else:
		print(l)
		break
	if r in g:
		r += 1
	else:
		print(r)
		break


(x, n) = map(int, input().split())
p = set(map(int, input().split()))
ans = 0
a = 1000000
for i in range(-1000, 1000):
	if abs(x - i) < a and (not i in p):
		ans = i
		a = abs(x - i)
print(ans)


(s, n) = input().split(' ')
min = 100
if int(n) != 0:
	num = input().split(' ')
else:
	num = []
for i in range(-102, 102):
	if str(i) not in num:
		cal = abs(int(s) - int(i))
	if min > cal:
		min = cal
		ans = int(i)
print(ans)


(X, N) = list(map(int, input().split()))
if N == 0:
	print(X)
	return
poe = list(map(int, input().split()))
for i in range(101):
	if X - i not in poe:
		print(X - i)
		return
	elif X + i not in poe:
		print(X + i)
		return


(x, n) = map(int, input().split())
p = set(map(int, input().split()))
l = set((i for i in range(102)))
ans = 0
for i in l - p:
	ans = min((abs(x - ans), ans), (abs(x - i), i))[1]
print(ans)


y = [int(i) for i in input().split()]
N = y[0]
Q = y[1]
if Q == 0:
	print(N)
	return
y = [int(i) for i in input().split()]
ans = []
for i in range(102):
	if i in y:
		continue
	ans.append(i)
for i in range(0, -102, -1):
	if i in y:
		continue
	ans.append(i)
t = abs(N - ans[0])
anss = 0
for i in ans:
	if abs(N - i) < t:
		anss = i
		t = abs(i - N)
print(anss)


(x, n) = list(map(int, input().split()))
ppp = []
if n != 0:
	ppp = list(map(int, input().split()))
plus_x = x
minus_x = x
ans = 0
if x not in ppp:
	ans = x
else:
	while minus_x + 100 > x or plus_x + 100 > x:
		minus_x -= 1
		if minus_x not in ppp:
			ans = minus_x
			break
		plus_x += 1
		if plus_x not in ppp:
			ans = plus_x
			break
print(ans)


(X, N) = map(int, input().split())
arr = list(map(int, input().split()))
ans = 10000
for i in range(0, 110):
	if i not in arr:
		if abs(X - i) < abs(X - ans):
			ans = i
print(ans)


(x, n, *p) = map(int, open(0).read().split())
i = 0
while x in p:
	x += (-1) ** i * i
	i += 1
print(x)


print(sorted((lambda n, p: [[p.count(i), abs(n[0] - i), i] for i in range(-100, 200)])(list(map(int, input().split())), list(map(int, input().split()))))[0][2])


(X, N) = map(int, input().split())
A = [int(i) for i in input().split()]
ans = 0
for i in range(1, 102):
	if i in A:
		pass
	elif abs(ans - X) > abs(i - X):
		ans = i
print(ans)


(x, n) = map(int, input().split())
p = list(map(int, input().split()))
p.sort()
ans = 300
for i in range(-100, 200):
	if p.count(i) == 0:
		if abs(ans - x) > abs(i - x):
			ans = i
print(ans)


(X, N) = map(int, input().split())
A = set(map(int, input().split()))
i = 0
while True:
	if not X - i in A:
		print(X - i)
		break
	if not X + i in A:
		print(X + i)
		break
	i += 1


(X, N) = map(int, input().split())
p = list(map(int, input().split()))
mini = 100000
for i in range(X + 200):
	if i in p:
		continue
	if abs(i - X) < mini:
		mini = abs(i - X)
		ans = i
print(ans)


(x, n) = map(int, input().split())
p = list(map(int, input().split()))
min = 0
dev = 200
for i in range(0, 102):
	if i in p or abs(x - i) >= dev:
		continue
	dev = abs(x - i)
	min = i
print(min)


(X, N) = list(map(int, input().split()))
p = list(map(int, input().split()))
count = 0
flg = False
lis = []
result = 0
while True:
	up = X + count
	down = X - count
	if p.count(down) == 0:
		lis.append(down)
		flg = True
	if p.count(up) == 0:
		lis.append(up)
		flg = True
	if flg == True:
		break
	else:
		count += 1
lis.sort()
print(lis[0])


(x, n) = map(int, input().split())
r = [i - x for i in map(int, input().split())]
for i in range(n + 1):
	if not -i in r:
		print(x - i)
		break
	elif not i in r:
		print(x + i)
		break


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


(X, N) = map(int, input().split())
p = list(map(int, input().split()))
count = -1
while True:
	count += 1
	if X - count not in p:
		print(X - count)
		break
	elif X + count not in p:
		print(X + count)
		break


(x, n, *p) = map(int, open(0).read().split())
r = [i for i in range(102) if i not in p]
print(sorted(r, key=lambda y: abs(x - y))[0])


(x, n) = map(int, input().split())
(*p,) = map(int, input().split())
p = set(p)
ans = 1000
for i in range(x + 100):
	if i not in p:
		if abs(ans - x) > abs(i - x):
			ans = i
print(ans)


(x, n) = map(int, input().split())
if n == 0:
	print(x)
else:
	a = list(map(int, input().split()))
	ans = -1
	for i in range(0, 102):
		if i not in a and abs(i - x) < abs(ans - x):
			ans = i
	print(ans)


(x, n) = map(int, input().split())
p = list(map(int, input().split()))
s = x
d = 1
while s in p:
	s = s - d
	d = int((abs(d) + 1) * d / abs(d) * -1)
print(s)


(x, n) = map(int, input().split())
a = list(map(int, input().split()))
for y in range(x + 1):
	for b in [-1, 1]:
		c = x + y * b
		if a.count(c) == 0:
			print(c)
			exit(0)


(x, n) = list(map(int, input().split()))
l = list(map(int, input().split()))
l.sort()
result = x
for i in range(100):
	if x in l:
		pass
	else:
		result = x
		break
	if x - i in l:
		pass
	elif x - i >= 0:
		result = x - i
		break
	if x + i in l:
		pass
	elif x + i <= 101:
		result = x + i
		break
print(result)


(X, N) = map(int, input().split())
p = sorted(list(map(int, input().split())))
sa_min = 100
for i in range(102):
	if sa_min > abs(i - X) and (not i in p):
		sa_min = abs(i - X)
		ans = i
if N == 0:
	ans = X
print(ans)


import bisect
(X, N) = map(int, input().split())
if N == 0:
	print(X)
	return
p = sorted(list(map(int, input().split())))
m = min(p) - 1
M = max(p) + 1
m = X
i = 0
for i in range(m, min(p) - 2, -1):
	if i not in p:
		break
M = X
j = 0
for j in range(M, max(p) + 2):
	if j not in p:
		break
if abs(i - X) == abs(j - X):
	print(min(i, j))
elif abs(i - X) < abs(j - X):
	print(i)
else:
	print(j)


(x, n) = map(int, input().split())
p = set(map(int, input().split()))
ans = -200000
for i in range(-200, 200):
	if not i in p:
		if abs(x - ans) > abs(x - i):
			ans = i
print(ans)


(x, n) = map(int, input().split())
P = list(map(int, input().split()))
xm = x
xM = x
for i in range(0, 100):
	if n == 0:
		print(x)
		break
	xm = x - i
	xM = x + i
	mcounter = 0
	Mcounter = 0
	for j in range(len(P)):
		if xm == P[j]:
			mcounter += 1000
		if xM == P[j]:
			Mcounter += 1000
	if mcounter < 1000:
		print(xm)
		break
	if Mcounter < 1000:
		print(xM)
		break


(X, N) = list(map(int, input().split()))
pi = list(map(int, input().split()))
mind = 10 ** 10
ans = -102
for i in range(-101, 102):
	dist = abs(X - i)
	if mind > dist:
		if i not in pi:
			ans = i
			mind = dist
print(ans)


(x, N) = list(map(int, input().split()))
p = list(map(int, input().split()))
min = 10000
temp = 0
num = 10000
for i in range(-1000, 1000):
	temp = abs(x - i)
	if temp < min and i not in p:
		min = temp
		num = i
print(num)


(x, n) = map(int, input().split())
p = set(map(int, input().split()))
for i in range(100):
	lr = [x - i, x + i]
	for y in lr:
		if y not in p:
			print(y)
			exit()


(x, n) = map(int, input().split())
a = set(map(int, input().split()))
(l, r) = (x, x)
while l in a:
	l -= 1
while r in a:
	r += 1
if x - l <= r - x:
	print(l)
else:
	print(r)


(x, n) = map(int, input().split())
p = list(map(int, input().split()))
p = set(p)
res = 0
for i in range(0, 120):
	if not i in p and abs(x - i) < abs(x - res):
		res = i
print(res)


(X, N) = map(int, input().split())
p = list(map(int, input().split()))
if N == 0 or X < min(p) or X > max(p):
	print(X)
else:
	for n in range(N + 1):
		if not X - n in p:
			print(X - n)
			break
		elif not X + n in p:
			print(X + n)
			break


(x, n) = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]
np = [i for i in range(0, 200) if not i in p]
r = 0
for i in np:
	if abs(x - i) < abs(x - r):
		r = i
print(r)


(x, n) = map(int, input().split())
p = set(map(int, input().split()))
s = set()
for i in range(-100, 201):
	s.add(i)
s = list(s - p)
a = [abs(x - i) for i in s]
print(s[a.index(min(a))])


(x, n) = map(int, input().split())
a = list(map(int, input().split()))
m = 1000
idx = x
for i in range(x - 100, x + 101):
	k = abs(x - i)
	if i not in a:
		if m > k:
			m = k
			idx = i
print(idx)


(x, _, *l) = map(int, open(0).read().split())
print(min(((abs(i - x), i) for i in {*range(102)} - {*l}))[1])


(X, N) = map(int, input().split())
P = list(map(int, input().split()))
for i in range(X + 1):
	for j in [-1, 1]:
		a = X + j * i
		if P.count(a) == 0:
			print(a)
			exit(0)


(x, _) = list(map(int, input().split()))
p = list(map(int, input().split()))
x_l = x
x_u = x
while True:
	if not x_l in p:
		print(x_l)
		break
	if not x_u in p:
		print(x_u)
		break
	x_l -= 1
	x_u += 1