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

Solutions:
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())
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, *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, *p) = map(int, open(0).read().split())
print(min({*range(999)} - {*p}, key=lambda y: (abs(y - x), y)))


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


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())
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, *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, *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())
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 = []
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())
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, *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, *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())
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


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, *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])


(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())
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()))
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, *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, *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()))
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) = 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())
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)


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


(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) = 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, *p) = map(int, open(0).read().split())
i = 0
while x in p:
	x += (-1) ** i * i
	i += 1
print(x)


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


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