Problem:
 Score : 300 points    Problem Statement Given are an integer X and an integer sequence of length N : p_1, \ldots, p_N .  Among the integers not contained in the sequence p_1, \ldots, p_N (not necessarily positive), find the integer nearest to X , that is, find the integer whose absolute difference with X is the minimum. If there are multiple such integers, report the smallest such integer.      Constraints  1 \leq X \leq 100  0 \leq N \leq 100  1 \leq p_i \leq 100  p_1, \ldots, p_N are all distinct.  All values in input are integers.         Input Input is given from Standard Input in the following format:  X  N  p_1  ...  p_N       Output Print the answer.        Sample Input 1 6 5
4 7 10 6 5      Sample Output 1 8  Among the integers not contained in the sequence 4, 7, 10, 6, 5 , the one nearest to 6 is 8 .       Sample Input 2 10 5
4 7 10 6 5      Sample Output 2 9  Among the integers not contained in the sequence 4, 7, 10, 6, 5 , the ones nearest to 10 are 9 and 11 . We should print the smaller one, 9 .       Sample Input 3 100 0      Sample Output 3 100  When N = 0 , the second line in the input will be empty. Also, as seen here, X itself can be the answer.

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

for i in range(101):
        if not x - i in p:
            print(x - i)
            break
        if not x + i in p:
            print(x + i)
            break

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

tmp = x
x_2 = x

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

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

else:
    x -= 1
    if x not in p:
        print(x)
        exit()
    if (x_2 + 1) not in p:
        print(x_2+1)
        exit()

    else:
        x_2 += 1

while True:
    if(x - 1) not in p:
        print(x-1)
        exit()

    else:
        x -= 1
        if (x_2 + 1) not in p:
            print(x_2+1)
            exit()

        else:
            x_2 += 1

Solution (Python):
import sys
X, N = map(int, input().split())
if N==0:
    P = {}
else:
    P = set(map(int, input().split()))

answer = sys.maxsize

for i in range(100):
    A = X-i
    B = X+i

    if A in P:
        pass
    else:
        print(A)
        exit()

    if B in P:
        pass
    else:
        print(B)
        exit()

Solution (Python):
x,n=map(int,input().split())
if n==0:
  print(x)
else:
	a=list(map(int,input().split()))
	box=[0]*101
	for i in a:
		if -50<= i-x <=50:
			box[50+i-x]=1
	for i in range(51):
		if box[50-i]==0:
			print(x-i)
			break
		elif box[50+i]==0:
			print(x+i)
			break

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

targets = set(range(-101, 102)) - P
if targets:
    print(min([(target, abs(X - target)) for target in targets], key=lambda x: x[1])[0])
else:
    print(X)

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

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

P = list(map(int, input().split()))
i = 0
while True:
  l = X - i
  r = X + i 
  if X - i not in P:
    print(X-i)
    exit()
  elif X + i not in P:
    print(X + i)
    exit()
  i += 1

Solution (Python):
from typing import List


def forbidden_list(x: int, p: List[int]) -> int:
    for i in range(len(p)):
        if x - i not in p:
            return x - i
        if x + i not in p:
            return x + i
    return x - len(p)


if __name__ == "__main__":
    X, _ = map(int, input().split())
    p = [int(a) for a in input().split()]

    ans = forbidden_list(X, p)
    print(ans)

Solution (Python):
X,N = map(int,input().split())
listP=[]
while True:
    try:
        listP=list(map(int,input().split()))
    except:
        break;
        
candidate_list=list(range(-101,201))
for num in listP:
  candidate_list.remove(num)

for num in range(120):
  minus=candidate_list.count(X-num)
  plus=candidate_list.count(X+num)
  if minus==1:
    print(X-num)
    break
  if plus==1:
    print(X+num)
    break

Solution (Python):
x,n=map(int,input().split())
if n==0:
    print(x)
    exit()
p=list(map(int,input().split()))
p.sort()
if p[0]>x or p[-1]<x:
    print(x)
else:
    now=x
    ans1=p[-1]+1
    ans2=p[0]-1
    while now<=p[-1]:
        if now in p:
            now+=1
        else:
            ans1=now
            break
    now=x
    while now>=p[0]:
        if now in p:
            now-=1
        else:
            ans2=now
            break
if abs(x-ans1)>=abs(x-ans2):
    print(ans2)
else:
    print(ans1)

Solution (Python):
import queue

X,N = map(int,input().split())
if N == 0:
  print(X)
else:
  p = list(map(int,input().split()))
  
  q = queue.Queue()

  q.put(X)

  while not q.empty():
    a = q.get()
    flag = "true"
    for i in p:
      if a==i:
        flag = "false"
        break
    if flag == "true":
      print(a)
      break
    else:

      if a != 0 and X-a >= 0:
        q.put(a-1)
      if a != 101 and X-a <= 0:
        q.put(a+1)

Solution (Python):
x,n=map(int,input().split())
if n==0:
    print(x)
else:
    P=list(map(int,input().split()))
    N=[i for i in range(0,102)]

    for p in P:
        N.pop(N.index(p))

    L=[]
    for a in N:
        l=abs(a-x)
        L.append(l)
    
    m=L.index(min(L))
    print(N[m])

Solution (Python):
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

X, N = MAP()
p = LIST()

ans = -1
min_num = float("INF")
for i in range(-1, 102):
    if i in p:
        continue
    
    if min_num > abs(X-i):
        min_num = abs(X-i)
        ans = i


print(ans)

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

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

Solution (Python):
X, N = map(int, input().split())
p = list(map(int, input().split()))
if X not in p:
    print(X)
else:
    n = 1
    ans = ""
    while ans == "":
        if X - n not in p:
            ans = X - n
        elif X + n not in p:
            ans = X + n
        n += 1
    print(ans)

Solution (Python):
X, N = map(int, input().split())
p = set()
if N != 0:
    p = set(map(int, input().split()))
pp = sorted(list({i for i in range(102)} - p))
ans = -100
for i in pp:
    if abs(X - ans) > abs(X - i):
        ans = i
print(ans)

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

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

p.sort()

num = [i for i in range(-2, 103)]
for i in p:
    num.remove(i)

for i in range(len(num)):
    if x < num[i]:
        if abs(num[i]-x) >= abs(num[i-1]-x):
            print(num[i-1])
            break
        else:
            print(num[i])
            break

Solution (Python):
x,n = map(int,input().split())
ans = float('inf')
find = -1

if n == 0:
    ans = x
    
else:
    p = list(map(int,input().split()))
    next = []
    next.append(x)
    while find == -1:
        y = next.pop(0)
        if all(y != p[i] for i in range(n)):
            ans = y
            find = 0
        else:
            if len(next) == 0:
                next.append(y - 1)
                next.append(y + 1)
            elif y < x:
                next.append(y - 1)
            else:
                next.append(y + 1)
        
print(ans)

Solution (Python):
X, N = map(int, input().split())
A = list(map(int, input().split()))
total = [i for i in range(-1, 102)]
for i in range(len(A)):
    total[A[i]+1] = 10000
dif = [0]*103
for i in range(103):
    dif[i] = abs(X-total[i])
min_index = dif.index(min(dif))

print(min_index-1)

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

arr = [0] * 1000
for i in p:
    arr[i] = 1

ans1 = 0
for i in range(x, -1, -1):
    if arr[i] == 0:
        ans1 = i
        break



ans2 = 0
for i in range(x, 102):
    if arr[i] == 0:
        ans2 = i
        break

if abs(ans1 - x) <= abs(x - ans2):
    print(ans1)
else:
    print(ans2)

Solution (Python):
x, n = map(int,input().split())
if n == 0:
    print(x)
    exit()
p = [int(i) for i in input().split()]
flg = True
ans = 0
d = 0
while flg:
    if not x in p:
        ans = x
        flg = False
        break
    elif not x-d in p:
        ans = x-d
        flg = False
        break
    elif not x+d in p:
        ans = x+d
        flg = False
        break
    else:
        d += 1
print(ans)

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

    l = [int(i) for i in range(105, -105, -1)]
    for i in range(n):
        l.remove(p[i])
    ans = 105
    for i in range(len(l)):
        if ans >= abs(l[i]-x):
            ans = abs(l[i]-x)
        else:
            return l[i-1]
    



print(solve())

Solution (Python):
x,n = map(int, input().split())
if n != 0:
    p = list(map(int, input().split()))
    smaller = 0
    for i in range(x):
        if x - i in p:
            pass
        else:
            smaller = x-i
            break

    bigger = 2*x
    for j in range(x):
        if x + j in p:
            pass
        else:
            bigger = x + j
            break

    ans = smaller if x - smaller <= bigger - x else bigger
    
    print(ans)
else:
    print(x)

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

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

Solution (Python):
import itertools
import decimal
import math
import collections
import sys
input = sys.stdin.readline

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

if(N==0):
    ans=X
else:
    ListP=list(map(int,input().split()))

    min = 999999
    for i in range(-200,200):
        if(min > abs(X-i)):
            if(i not in ListP):
                min=abs(X-i)
                ans=i


print(ans)

Solution (Python):
from sys import stdin
X, Y = [int(x) for x in stdin.readline().rstrip().split()]
P = [int(x) for x in stdin.readline().rstrip().split()]
tmp = 10**9+7
P = set(list(range(-200, 200))) - set(P)
P = list(P)
P.sort(reverse=True)


ans = 0
for i in P:
    if abs(X-i) <= tmp:
        ans = i
        tmp = abs(X-i)

print(ans)

Solution (Python):
import sys
a,b = map(int,input().split())
if b==0:
  print(a)
else:
  b = list(map(int,input().split()))
  for i in range(101):
    _min=a-i
    _max=a+i
    if _min not in b:
      print(_min)
      sys.exit(0)
    if _max not in b:
      print(_max)
      sys.exit(0)

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

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

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

left = 0
right = 101

i = 1
while i <= x:
    if i not in p:
        left = i
    i += 1
while right == 101:
    if i not in p:
        right = i
        break
    i += 1

if x - left <= right - x:
    print(left)
else:
    print(right)

Solution (Python):
def main():
	X, N = map(int, input().split(" "))
	if N == 0:
		print(X)
		return
	P = list(map(int, input().split(" ")))
	CONTINUE = True
	dif = 0
	while CONTINUE:
		temp_1 = X - dif
		temp_2 = X + dif
		if (temp_1 not in P):
			print(temp_1)
			CONTINUE = False
		elif (temp_2 not in P):
			print(temp_2)
			CONTINUE = False
		else:
			dif += 1
      
      
    
      
if __name__ == "__main__":
  main()

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

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

xp = x
xm = x
while True:
    xp += 1
    xm -= 1
    if xp in p and xm in p:
        continue
    elif xm not in p:
        print(xm)
        break
    else:
        print(xp)
        break

Solution (Python):
import bisect
x,b=map(int,input().split())
arr=list(map(int,input().split()))
if x not in arr:
    print(x)
    quit()
for i in range(x+1,102):
    if i not in arr:
        ma=i
        break
for i in range(x-1,-2,-1):
    if i not in arr:
        mi=i
        break
if x-mi<=ma-x:
    print(mi)
else:
    print(ma)

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

if n == 0:
    print(x)
else:    
    p = [int(e) for e in 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

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

if n == 0:
    p = input()
    print(x)
else:
    p = [int(x) for x in input().split(' ')]
    s = set([x for x in range(102)])
    s -= set(p)
    for i in range(0,51):
        if x-i in s:
            print(x-i)
            break
        if x+i in s:
            print(x+i)
            break

Solution (Python):
X, N = map(int, input().split())
pi = list(map(int, input().split()))
newpi = [0 for i in range(N)]
for i in range(N):
    newpi[i] = pi[i] - X
for x in range(101):
    if not(((-1) * x) in newpi):
        print((-1) * x + X)
        break
    if not(x in newpi):
        print(x + X)
        break

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


pn = [0] * 105
nn = [0] * 105


for pp in p:
    a = pp - x
    if a > 0:
        pn[a] = 1
    elif a < 0:
        nn[-a] = 1
    else:
        pn[0] = nn[0] = 1

for i in range(101):
    if nn[i] == 0:
        print(x-i)
        exit(0)
    if pn[i] == 0:
        print(x+i)
        exit(0)

Solution (Python):
X,N = map(int,input().split())
p_li = set(map(int,input().split()))
p = set(range(-200,200))
kouho = p - p_li
ans = 10000
sa_min = 1000000
for i in sorted(list(kouho)):
    sa = abs(X-i)
    if sa_min > sa:
        ans = i
        sa_min = sa
print(ans)

Solution (Python):
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

x,n = mi()
p =li()


xs = x
while 1:
    if xs not in p:
        break
    xs -= 1


xl = x
while 1:
    if xl not in p:
        break
    xl += 1

if x-xs > xl - x:
    print(xl)
else:
    print(xs)

Solution (Python):
x, n = map(int,input().split())
P = list(map(int,input().split()))
a = [i for i in range(-220, 220)]
for p in P:
    a.remove(p)

if x in a:
    print(x)
    exit()

l = x-1
r = x+1
for i in range(120):
    if l in a:
        print(l)
        exit()
    l -= 1

    if r in a:
        print(r)
        exit()
    r += 1

Solution (Python):
import sys

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

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

p_set = set(P)

if not (X in p_set):
    print(X)
    sys.exit()

for i in range(1, 100):
    if not (X-i in p_set):
        print(X-i)
        break
    if not (X+i in p_set):
        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)
    exit()

small = x - 1
large = x + 1
while True:
    if small not in p:
        print(small)
        break
    elif large not in p:
        print(large)
        break
    else:
        small -= 1
        large += 1

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

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

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

Solution (Python):

def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)








x,n=n1()

if n==0:
    print(x)
else:
    P=n1()
    if (not x in P):
        print(x)
    else:
        d=[]
        d2=[]
        for i in range(0,102):
            if (not i in P):
                d.append(i)
                d2.append(abs(x-i))

        a=min(d2)
        if (x-a) in d:
            print(x-a)
        else:
            print(x+a)

Solution (Python):

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

all_num = [i for i in range(0, 102)]

for p in ps: 
    all_num.remove(p)

diff = 1000
ans = 1000
anss = []

for num in all_num:
    my_diff = abs(num - X)
    if my_diff < diff:
        ans = num
        diff = my_diff


print(ans)

Solution (Python):
a,b = map(float,input().split())
p = list(map(int,input().split()))

t = 10000
for i in range(103,-1,-1):
    if i not in p:
        if abs(a-i)<= t:
            ans = i
            t = abs(a-i)
        
print(ans)

Solution (Python):
def readinput():
    x,n=list(map(int,input().split()))
    if (n>0):
        p=list(map(int,input().split()))
    else:
        p=[]
    return x,n,p

def main(x,n,p):
    if (len(p)==0):
        return x

    mindist=102
    nearest=0
    for y in range(0,102):
        if y in p:
            continue
        if abs(x-y) < mindist:
            mindist = abs(x-y)
            nearest=y        
    return nearest

if __name__=='__main__':
    x,n,p=readinput()
    ans=main(x,n,p)
    print(ans)

Solution (Python):
import sys

X, N = map(int, sys.stdin.readline().strip().split())
P = set(map(int, sys.stdin.readline().strip().split()))

ans = X
ans_v = X
for i in range(102):
    if i in P:
        continue
    tmp = abs(X - i)
    if tmp < ans or (tmp == ans and i < ans_v):
        ans_v = i
        ans = tmp
        
print(ans_v)

Solution (Python):

import sys




def xnxn(n=0, flag="v"):
    """
    args:
        int n: a number of lows to read
    example:
        input   1
        retrun  1

        input   1 2 3
        return  [1,2,3]
        input   1 2 3
                4 
        return  [[1,2,3],
                [4]]
    """
    if n == 0:
        temp = list(map(int, input().split()))
        if len(temp) == 1:
            if flag == "l":
                return temp
            else:
                return temp[0]
        elif len(temp) > 1:
            return temp
    else:
        temp = [list(map(int, input().split())) for _ in range(n)]
        return temp


x, n = xnxn()

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

p = xnxn(flag="l")


i = 0
while True:
    if (x - i in p) == False:
        print(x - i)
        sys.exit()
    elif (x + i in p) == False:
        print(x + i)
        sys.exit()
    i += 1

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

if n == 0:
  pass
elif x not in p:
  print(x)
else:
  for i in range(1,101):
    if x-i not in p:
      print(x-i)
      break
    elif x+i not in p:
      print(x+i)
      break

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

for i in range(0,101):
  no = x-i
  if ps.count(no) == 0 & (no > 0):
    print(no)
    exit()
  no = x+i
  if ps.count(no) == 0 & (no < 101):
    print(no)
    exit()

Solution (Python):
x, n = [int(x) for x in input().split()]
if n == 0:
    print(x)
else:
    arr = {int(x):True for x in input().split()}
    if x not in arr:
        print(x)
    else:
        left, right = x-1, x+1
        while True:
            if left not in arr:
                print(left)
                break
            elif right not in arr:
                print(right)
                break
            left -= 1
            right += 1

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

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

for i in range(110):
    if (x-i) not in p:
        print(x-i)
        sys.exit()
    if (x+i) not in p:
        print(x+i)
        sys.exit()

Solution (Python):
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

Solution (Python):
X, N = map(int, input().split())
P = list(map(int, input().split()))
ans_p = X
ans_m = X
while True:
    if ans_m not in P:
        ans = ans_m
        break
    if ans_p not in P:
        ans = ans_p
        break
    ans_p += 1
    ans_m -= 1
print(ans)

Solution (Python):





import math
import sys
import bisect
import heapq  
import collections
from collections import deque
import pprint

inf = 10**18
mod = 10**9+7

x,n = map(int, input().split())
if n == 0:
    print(x)
    sys,exit()
p = list(map(int, input().split()))
p.sort()
ind = bisect.bisect_left(p,x)
if ind == n:
    print(x)
elif ind == 0:
    if p[ind] != x:
        print(x)
    else:
        print(x-1)
else:
    if p[ind] != x:
        print(x)
    else:
        maxans = 0
        minans = inf
        pre = x
        k = ind
        while k != n and pre == p[k]:
            k+=1
            pre+=1
        maxans = p[k-1]+1
        pre = x
        k = ind
        while k != -1 and pre == p[k]:
            k-=1
            pre-=1
        minans = p[k+1]-1
        ans = 0
        if abs(x-maxans) < abs(x-minans):
            ans = maxans
        else:
            ans = minans
        print(ans)

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

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

m = [True] * (105)
for i in range(n):
  m[p[i]] = False

l = x
r = x

for i in range(105):
  if m[l] and m[r]:
    print(l)
    exit(0)
  if m[l] and not m[r]:
    print(l)
    exit(0)
  if not m[l] and m[r]:
    print(r)
    exit(0)
  l -= 1
  r += 1

Solution (Python):
X,N = map(int,input().split())
if N ==0:
  print(X)
  exit()
p = [int(i) for i in input().split()]



for i in range(1000000):
  x = X-i
  if x not in p:
    print(x)
    exit()
  x = X+i
  if x not in p:
    print(x)
    exit()

Solution (Python):
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

Solution (Python):
x,n = map(int,input().split())
p_li = list(map(int,input().split()))
p_li.sort()
if p_li.count(x) == 0:
    print(x)
    exit()
dum1 = x-1
dum2 = x+1
for i in range(n):
    if p_li.count(dum1) == 0:
        print(dum1)
        exit()
    if p_li.count(dum2) == 0:
        print(dum2)
        exit()
    dum1 -= 1
    dum2 += 1

Solution (Python):
import sys
import math as mt
input=sys.stdin.buffer.readline  

mod=10**9+7
t=1
for __ in range(t):
    
    x,n=map(int,input().split())
    l=[0]*103
    
    
    p=list(map(int,input().split()))

    for i in range(n):
        l[p[i]]=1
    mini=abs(x)
    ans=0
    
    for i in range(102):
        if l[i]==0:
            if abs(x-i)<mini:
                mini=abs(x-i)
                
                ans=i
        
    print(ans)

Solution (Python):
X,N = map(int,input().split())
if N>0:
    p_set = set(map(int,input().split()))
else:
    p_set = set()
min_dist_xp = 1000
for p in reversed(range(0,102)):
    if p not in p_set:
        dist_xp = abs(X-p)
        if dist_xp<=min_dist_xp:
            min_dist_xp = dist_xp
            ans = p
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(10**7) 
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right

from collections import deque


from collections import Counter

from itertools import accumulate

from heapq import heapify,heappop,heappush


from functools import lru_cache


def input(): return sys.stdin.readline()[:-1]
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 1000000007
    

    
    X,N = map(int, input().split())
    if N==0:
        _=input()
        print(X)
        return 
    A = list(map(int, input().split())) 
    
    
    
    A.sort()
    a=A

    i=bisect_left(A,X)
    
    if i==len(A):
        print(X)
        return 
    if A[i]!=X:
        print(X)
        return
    
    j=i-1
    cur=X
    amin=min(A)-1
    while j>=0:
        if abs(a[j]-cur)<2:
            cur=a[j]
            j-=1
            continue
        else:
            amin=cur-1
            break
    j=i+1
    amax=max(A)+1
    cur=X
    while j<=len(A)-1:

        if abs(a[j]-cur)<2:
            cur=a[j]
            j+=1
            continue
        else:
            amax=cur+1
            break
    
    if abs(amin-X)<=abs(amax-X):
        print(amin)
    else:
        print(amax)
    
if __name__ == "__main__":
    main()

Solution (Python):
X, N = map(int, input().split())
p = list(map(int, input().split()))
l = []
if len(p) == 0:
    print(X)
    exit()
for i in range(-1000, 1000):
    if not i in p:
        l.append(i)

ans_n = 1000
ans = 0
for i in range(-1000, 1000):
    if ans_n > abs(X-l[i]):
        ans_n = abs(X-l[i])
        ans = l[i]

print(ans)

Solution (Python):

x,n = map(int,input().split())
p = list(map(int,input().split()))
tmp = 1000
a = [i for i in range(0,150)]



p_dif = set(a) - set(p)


for i in p_dif:
    if tmp > abs(i-x):
        tmp = abs(i-x)
        result = i
        
        
print(result)

Solution (Python):


import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())

def resolve():
    it = map(int, sys.stdin.read().split())
    X, N = next(it), next(it)

    if N == 0:
        print(X)
        return
    P = set(next(it) for i in range(N))

    if not X in P:
        print(X)
        return

    i = 1
    while True:
        ans = X - i
        if not ans in P:
            break
        ans = X + i
        if not ans in P:
            break
        i += 1

    print(ans)



if __name__ == "__main__":
    resolve()

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

ps = []
anti_Ps = []
if N != 0:
  ps = input()
  anti_Ps = [int(i) for i in ps.split()]
Ps = [int(i) for i in range(-100, 200) if i not in anti_Ps]

most_like_p = 1000
for p in Ps:
  if abs(p-X) == abs(most_like_p - X):
    most_like_p = min(p, most_like_p)
  elif abs(p-X) < abs(most_like_p - X):
    most_like_p = p

print(most_like_p)

Solution (Python):
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)

Solution (Python):
X, N = (int(s) for s in input().rstrip().split())
if N == 0:
  nums = []
else:
  nums = [int(s) for s in input().rstrip().split()]

def find(nums, X):
  if not nums:
    return X
  if X not in nums:
    return X
  for i in range(1, X + 1):
    X_plus = X + i
    X_minus = X - i
    
    if X_minus not in nums:
      return X_minus
    if X_plus not in nums:
      return X_plus

print(find(nums, X))

Solution (Python):
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)

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

diff = 0
while True:
    if X - diff not in P:
        print(X - diff)
        break
    elif X + diff not in P:
        print(X + diff)
        break
    else:
        diff += 1

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

Solution (Python):
x,n = map(int,input().split())
p = list(map(int,input().split()))
p1 = [i for i in range(0,102)]
for i in p:
    if i in p1:
        p1.remove(i)
ans = 1000
al = []
for i in p1:
    if ans >= abs(i-x):
        ans = min(abs(i-x),ans)
        al.append(i)

if len(al) == 0:
    if x < 50:
        print(0)
    else:
        print(101)
elif len(al) > 1:
    if abs(al[-1]-x) == abs(al[-2]-x):
        print(al[-2])
    else:
        print(al[-1])
else:
    print(al[-1])

Solution (Python):



k,n=map(int,input().split())
p=[int(x) for x in input().split()]
if n==0:
	print(k)
else:
	diff=500
	ans=0
	for i in range(0,105):
		if i not in p:
			if diff>abs(k-i):
				diff=abs(k-i)
				ans=i
	print(ans)

Solution (Python):
from collections import deque
import sys
x,n = map(int,input().split())
p = []
if n != 0:
    p = list(map(int, input().split()))
tmp1 = x
if tmp1 not in p:
    print(tmp1)
    sys.exit()
i = 1
while True:
    tmp1 = x - i
    tmp2 = x + i
    if tmp1 not in p:
        print(tmp1)
        sys.exit()
    if tmp2 not in p:
        print(tmp2)
        sys.exit()
    i += 1

Solution (Python):
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))



X,N = LI()
p = LI()

p.sort()
v = 0
while True:
    pl = bisect_left(p,X-v)
    if pl >= N or p[pl] != X-v:
        print(X-v)
        exit()
    pl = bisect_left(p,X+v)
    if pl >= N or p[pl] != X+v:
        print(X+v)
        exit()
    v += 1

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

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

mindiff = 1000
minval = None
for i in range(0, 101+1):
    diff = abs(X- i)
    if i not in P and diff < mindiff:
        mindiff = diff
        minval = i
print(minval)

Solution (Python):
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd 
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) 


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)
        sys.exit()
    elif not (x + i) in p:
        print(x + i)
        sys.exit()
    i += 1

Solution (Python):









import os
import sys




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


if __name__ == "__main__":
    main()