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

"""
Created on Sat Jun 20 15:49:43 2020

@author: naoki
"""

X,N = map(int,input().split()) 
p = list(map(int,input().split())) 
p.sort() 
p1 = [ i for i in range(-101,102)] 
gap = 201
row = []
for i in range(N):
    p1.remove(p[i]) 

for i in p1:
    if gap >= abs(X-i):
        gap = abs(X-i)
 
num1 = X-gap
num2 = X+gap

if num1 in p1:
    print(num1)
elif num2 in p1:
    print(num2)

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

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

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

check = 10**10
ans = 10**10


for i in range(0, 102):
    if i in li:
        continue
    
    if abs(x-i) == check:
        ans = min(ans, i)
    elif abs(x-i) < check:
        ans = i
        check = abs(x-i)
        
print(ans)

Solution (Python):
n = input().split()
n = [int(i) for i in n]
if not n[1] == 0:
	m = input().split()
	m = [int(i) for i in m]
else:
  	m =[0]

ans_1 = n[0]
ans_2 = n[0]
ans = []
while True:
    if n[1] == 0:
        ans.append(n[0])
    if not n[0] in m:
      ans.append(n[0])
    if len(ans) > 0:
        break    
        
    ans_1 += 1
    ans_2 -= 1
    if not ans_1 in m:
        ans.append(ans_1)
    if not ans_2 in m:
        ans.append(ans_2)
    
    
        
print(min(ans))

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

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

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

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

set_p = set(p)

up = down = X
if X not in set_p:
    print(X)
    exit()
    
while True:
    up = up+1
    down = down-1

    if down not in set_p:
        print(down)
        exit()
    if up not in set_p:
        print(up)
        exit()

Solution (Python):
import sys
import operator

readline = sys.stdin.buffer.readline
a, b = map(int, readline().split())
c = set(map(int, readline().split()))

L = [(i, abs(i - a)) for i in range(0, 102) if i not in c]
L.sort(key=operator.itemgetter(1))
print(L[0][0])

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

for i in range(0,1000000000000):
  a = x-i
  b=x+i
  if(a not in set(p)):
    print(a)
    break
    
  elif(b not in set(p)):
    print(b)
    break

Solution (Python):
import argparse
import collections
import logging.config
import sys
import csv
import numpy as np

def tester(x, y, p):
    c = []
    c.append(x)
    for i in range(y+1):
        c.append(int(x+(i//2+1)*(1-i%2-0.5)*-2))
    for i in range(y+1):
        if not(c[i] in p):
            return(c[i])
            break

def main():

    sa = input().split()
    x = int(sa[0])
    y = int(sa[1])
    p = []
    if sa[1] != "0":
      sb = input().split()
      for d in sb:
      	p.append(int(d))        
    print (tester(x,y,p))


if __name__ == '__main__':
    main()

Solution (Python):
X,N=map(int,input().split())
P=list(map(int,input().split()))
S=[0]*(102);a=1000;b=1000;c=10000
for i in range(N):
  S[P[i]]=1

if N==0:
  print(X)
else:
  i=X
  while i>=0:
    if S[i]==0:
      a=i
      break
    i=i-1
  i=X
  while i<=101:
    if S[i]==0:
      b=i
      break
    i=i+1
    
  if abs(a-X)>abs(b-X):
    c=b
  else:
    c=a
  print(c)

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

mn = 1000
ans = 1000
for i in range(250):
    if i not in p:
        if mn > abs(x - i):
            mn = abs(x - i)
            ans = i
print(ans)

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

Solution (Python):
from typing import List


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


def solve(x: int, n: int, P: List[int]):
    plus = minus = x
    while True:
        if minus not in P:
            return minus
        elif plus not in P:
            return plus
        plus += 1
        minus -= 1


print(solve(x, n, P))

Solution (Python):
import numpy

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

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

for (i, v) in enumerate(nmap):
  nmap[i] = abs(v-x)

for (i, v) in enumerate(pList):
  nmap[v] = 102

ans = numpy.argmin(nmap)
print(ans)

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

ans = 10 ** 5
for i in range(X - 100, X + 100 + 1):
    if i not in P:
        if ans > abs(X - i):
            ans = abs(X - i)
            tmp = i

print(tmp)

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

Solution (Python):
def solve(x, n, p):
    S = set(p)
    for d in range(n+1):
        for y in [x-d, x+d]:
            if not y in S:
                return y

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

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

hukuro = set()
p = [hukuro.add(int(x)) for x in input().split()]
for i in range(120):
    if not X-i in hukuro:
        print(X-i)
        exit()
    elif not X+i in hukuro:
        print(X+i)
        exit()

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

cnt = 0
aflg = False
bflg = False
flg=False

while True:
    
    x = X+cnt
    x_min = X-cnt
    
    if x not in p:
        flg=True
        aflg = True
    
    if x_min not in p:
        flg=True
        bflg=True
        
        
    if flg==True:
        
        if aflg == True and bflg == True:
            print(x_min)
        elif aflg == True:
            print(x)
        elif bflg == True:
            print(x_min)
            
        break
    else:
        cnt+=1

Solution (Python):
X, N = map(int, input().split())
try:
    P = set((map(int, input().split())))
except:
    print(X)
    exit()
dif = 0
while X - dif in P:
    if not X + dif in P:
            print(X + dif)
            exit()
    dif += 1
print(X - dif)

Solution (Python):

import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

X,N = map(int,readline().rstrip().split())
p = set([int(i) for i in readline().rstrip().split()])
if N == 0:
    print(X)
    exit()
for j in range(X+1):
    if not ((X-j) in p):
        print(X-j)
        exit()
    if not ((X+j) in p):
        print(X+j)
        exit()

Solution (Python):
x, n = map(int, input().split())
p = list(map(int, input().split()))
k1 = x
k2 = x
while True:  
    if k1 not in p:
        break
    k1 += 1
while True:  
    if k2 not in p:
        break
    k2 -= 1
if abs(k1-x) > abs(k2-x):
    print(k2)

elif abs(k1-x) == abs(k2-x):
    print(min(k2, k1))
else:
    print(k1)

Solution (Python):
import sys

def search(p, a):
  lo = 0
  hi = len(a)-1
  while lo <= hi:
    mid = lo + (hi-lo)//2
    if p == a[mid]:
      return True
    elif p < a[mid]:
      hi = mid-1
    else:
      lo = mid+1
  return False

X, n = list(map(int, sys.stdin.readline().rstrip().split(' ')))
if n == 0:
  print(X)
else:
  a = list(map(int, sys.stdin.readline().rstrip().split(' ')))
  i = 1
  m = 1

  a = sorted(a)
  if not search(X, a):
    print(X)
  else:
    while True:
      m *= -1
      if not search(X+m, a):
        print(X+m)
        break
      i += 1
      if i % 2 == 1:
        m += 1

Solution (Python):
from bisect import bisect_left

def find(a,l):
    i=bisect_left(l,a)
    if(i!=len(l) and l[i]==a):
        return True
    else:
        return False


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

if(find(x,l)!=True):
    print(x)
else:
    c=1
    f=0
    while(f==0 and x-c>=0):
        if(find(x-c,l)!=True):
            print(x-c)
            f=1
        elif(find(x+c,l)!=True):
            print(x+c)
            f=1
        else:
            c+=1

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

Solution (Python):
x = input().split()
for i in range(2):
  x[i] = int(x[i])
list = []
ans = 0
d = x[0] + x[1]
if x[1] == 0:
  print(x[0])
else:
  if x[1] % 2 == 0:
    for i in range(x[1]):
      list.append(x[0]+i-x[1]/2)
    ans = x[0] + x[1]/2
  else:
    for i in range(x[1]+1):
      list.append(x[0]+i-(x[1]+1)/2)
    ans = x[0] + (x[1]+1)/2
  line = input().split()
  for i in range(x[1]):
    line[i] = int(line[i])
    if line[i] in list:
      list.remove(line[i])
  if len(list) == 0:
    print(int(ans))
  else:
    for i in list:
      if abs(x[0] - i) < d:
        ans = i
        d = x[0] - i
    print(int(ans))

Solution (Python):
import sys

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

t = True
i,j=0,0

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

i,j=1,1

while t:
    ans = x+i*(-1)**j
    if ans in p:
        if j == 2:
            j = 1
            i += 1
        else:
            j += 1    
    else:
        t = False

print(ans)

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

ans_list=[]
for i in range(101):
    check=0
    if X-i not in P:
        ans_list.append(X-i)
        check+=1
    elif X+i not in P:
        ans_list.append(X+i)
        check+=1
    if check>=1:
        print(ans_list[0])
        break

Solution (Python):
X, N = [int(x) for x in input().split()]
try:
  p = list(map(int, input().split()))
except EOFError:
  p = []
option = list(range(0, 102))
for item in p:
  option[item] = -1
diff = 0
while True:
  if option[X-diff] == X-diff:
    print(X-diff)
    break
  elif option[X+diff] == X+diff:
    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()))
    lower = min(a)
    upper = max(a)
    mini = 10000005
    res = -1
    for i in range(lower-1,upper+2):
        if i not in a:
            if abs(x-i)<mini:
                mini = abs(x-i)
                res = i

    print(res)

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

s =True
while s:
    if (x-i) not in lst:
        print(x-i)
        s = False
    elif (x+i) not in lst:
        print(x+i)
        s = False
    else:
        i += 1

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

for i in range(x[1]+1):
    for j in [-1,1]:
        if set() == {x[0]+j*i}&y:
            print(x[0]+j*i)
            sys.exit()

Solution (Python):
def main():
    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)
 
if __name__ == "__main__":
    main()

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

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

Solution (Python):
x, n = map(int, input().split())
p = list(map(int, input().split()))
np =[0]*102 

for i in p:
    np[i] = 1

dist = 1000
ans = 1000
for i in reversed(range(102)):
    if np[i] == 0:
        if abs(x-i) <= dist:
            dist = abs(x-i)
            ans = i
    
print(ans)

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

Solution (Python):
X, N = map(int, input().split())
lst = [int(x) for x in input().split()]
if N == 0 or X not in lst:
    print(X)
else:
    i = 1
    while True:
        if X - i not in lst:
            print(X - i)
            exit()
        elif X + i not in lst:
            print(X + i)
            exit()
        i += 1

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

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

ans_l = X
ans_h = X
h_s = 0
l_s = 0

while True:
    if l_s == 0 and ans_l not in P:
        print(ans_l)
        break
    else:
        ans_l -= 1
    
    if ans_h not in P:
        print(ans_h)
        break
    else:
        ans_h += 1
        
    if ans_h > 100:
        h_s = 1
    
    if ans_l < 0:
        l_s = 1
    
    if l_s and h_s == 1:
        break

Solution (Python):

import numpy as np
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect


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


def z():
    return int(input())


def S():
    return input()


def C(line):
    return [input() for _ in range(line)]


X, N = zz()
p = zz()
small_x = X
big_x = X
if (X not in p):
    print(X)
    exit()

while True:
    
    if (small_x - 1 not in p):
        print(small_x-1)
        exit()
    if (big_x + 1 not in p):
        print(big_x+1)
        exit()
    small_x -= 1
    big_x += 1

Solution (Python):
def main():
    x, n = map(int, input().split())
    p = set([int(v) for v in input().split()])
    ans = 0
    for i in range(1, 102):
        if i in p:
            continue
        if abs(x - i) < abs(x - ans):
            ans = i
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
x, n = map(int, input().split())
p = list(map(int, input().split()))
for base in range(x+1):
    if p.count(x+base*-1) == 0:
        print(x+base*-1)
        break
    if p.count(x+base) == 0:
        print(x+base)
        break

Solution (Python):
import operator

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

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

abs_val_dict = {}

if N == 0:
    print (X)

for i in range (X-N, X+N):
    if i not in p:
        abs_val_dict[i] = abs(i-X)

if abs_val_dict != {}:
    print(min(abs_val_dict.items(), key=operator.itemgetter(1))[0])

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 6)  
to_index = lambda x: int(x) - 1  
print_list_in_2D = lambda x: print(*x, sep="\n")  


def input_int():
    return int(input())

def map_int_input():
    return map(int, input())

MII = map_int_input

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

def MII_to_index():
    return map(to_index, input())

def MII_split_to_index():
    return map(to_index, input().split())


def list_int_inputs():
    return list(map(int, input()))

LII = list_int_inputs

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


def LII_2D(rows_number):
    return [LII() for _ in range(rows_number)]

def LII_split_2D(rows_number):
    return [LII_split() for _ in range(rows_number)]

X, N = MII_split()
if N==0:
    print(X)
    exit()
ps = LII_split()




for dis in range(105):
    if X - dis not in ps:
        ans = X - dis
        break
    elif X + dis not in ps:
        ans = X + dis
        break
print(ans)

Solution (Python):
import sys

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

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

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

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

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

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

Solution (Python):
import sys
sys.setrecursionlimit(10 **5)




readline = sys.stdin.readline

def proc():
    x,n = map(int, readline().rstrip().split())
    a = list(map(int, readline().rstrip().split()))
    hash_map = {}
    for i in a:
        hash_map[i] = True
    
    if not n or x not in hash_map:
        return x
    
    
    p,q = x-1, x+1
    while 1:
        if p not in hash_map and q not in hash_map:
            return p
        elif p not in hash_map:
            return p
        elif q not in hash_map:
            return q
        
        p-=1
        q+=1
    


print(proc())

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

check = 1000000
ans = 0

N = list(range(102))

for i in range(1, 101):
    if i in p:
        N.remove(i)

for i in range(len(N)):
    if check > abs(N[i]-x):
        check = abs(N[i]-x)
        ans = N[i]
print(ans)

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

check = 1000000
ans = 0

N = list(range(102))

for i in range(1, 101):
    if i in p:
        N.remove(i)

for i in range(len(N)):
    if check > abs(N[i]-x):
        check = abs(N[i]-x)
        ans = N[i]
print(ans)

Solution (Python):


def submit():
    x, n = map(int, input().split())
    p = set(map(int, input().split()))

    ans = -1
    ans_d = 10000
    for c in range(102):
        if c in p:
            continue

        if abs(x - c) < ans_d:
            ans_d = abs(x - c)
            ans = c
    
    print(ans)
    

if __name__ == "__main__":
    submit()

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

Solution (Python):
import sys

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)
            sys.exit(0)

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

idx = -1
for i in range(n):
    if p[i] == 0:
        idx = i
if idx == -1:
    print(x)
    exit()
sa = 1
while 1:
    if idx-sa<0:
        print(x-sa)
        exit()
    if p[idx-sa] != -sa:
        print(x -sa)
        exit()
    if idx+sa>n-1:
        print(x+sa)
        exit()
    elif p[idx+sa] != sa:
        print(x+sa)
        exit()
    sa +=1

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

if __name__ == "__main__":
    main()

Solution (Python):
x, n = [int(i) for i in input().split()]
p = set() if n == 0 else set((int(i) for i in input().split()))
if x not in p:
  print(x)
  exit(0)
h = x + 1
l = x - 1
while True:
  if l not in p:
    print(l)
    exit(0)
  if h not in p:
    print(h)
    exit(0)
  h += 1
  l -= 1

Solution (Python):
import sys

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



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

Solution (Python):
from math import*
x,n=map(int,input().split())
arr=list(map(int,input().split()))
if len(arr)==0:
	print(x)
else:
	arr.sort()
	i=arr[0]-1
	dif=[]
	abdif=[]
	while i<arr[-1]+2:
		if i not in arr:
			dif.append(x-i)
			abdif.append(int(fabs(x-i)))
		i+=1
	
	
	ans=[]
	for i in range(len(abdif)):
		if abdif[i]==min(abdif):	
			if dif[i]>=0:
				ans.append(x-dif[i])
			else:
				ans.append(x-dif[i])
	
	print(min(ans))

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


def func(near):
    if near not in p_list:
        print(near)
        quit()


while(True):
    near = X - abs_num
    func(near)
    near = X + abs_num
    func(near)
    abs_num += 1

Solution (Python):
input=[input().split() for i in range(2)]
num=int(input[0][0])
length=int(input[0][1])
list=[]
for i in range(length):
    list.append(int(input[1][i]))
i=0
flg=True
while (flg):
    ret=num-i
    flg=ret in list
    if(flg):
        ret=num+i
        flg=ret in list
        if(flg):
            i=i+1
        else:
            print(ret)
    else:
        print(ret)

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

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

Solution (Python):
x,n=map(int,input().split())
p=sorted(map(int,input().split()))
t={}
y=[(i>>1)*(1 if i&1 else -1)+x for i in range(1000)]
for i in range(-200,200):
    t[i]=True
for i in p:
    t[i]=False
for i in y:
    if t[i]:
        print(i)
        break

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

for i in range(x+1):
    for j in [-1,1]:
        y = x + j * i
        if y in l:
            pass
        else:
            print(y)
            exit()

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

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

nums = set([int(x) for x in input().split(" ")])

dist = 0

while True:
    if not x - dist in nums:
        print(x - dist)
        exit(0)

    if not x + dist in nums:
        print(x + dist)
        exit(0)

    dist += 1

Solution (Python):
import numpy as np
import sys

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

def search_list(x, p):
    flag = False
    for ii in range(len(p)):
        if p[ii]==x:
            flag = True
    return flag

if not search_list(X, p):
    print(X)
    sys.exit()

X_small = X
diff_small = 0

while search_list(X_small, p):
    X_small -= 1
diff_small = abs(X-X_small)

X_big = X
diff_big = 0

while search_list(X_big, p):
    X_big += 1
diff_big = abs(X-X_big)

if diff_small<=diff_big:
    print(X_small)
else:
    print(X_big)

Solution (Python):
import sys
import time
st = time.perf_counter()


def main():
    x, n = map(int, input().split())
    if n == 0:
        print(x)
        return
    pn = list(map(int, input().split()))
    if x not in pn:
        print(x)
        return
    for i in range(1, 1001001001):
        ls = []
        if x - i not in pn:
            ls.append(x-i)
        if x + i not in pn:
            ls.append(x+i)
        if ls:
            print(min(ls))
            return

main()
    

ed = time.perf_counter()
print('time:', ed-st, file=sys.stderr)

Solution (Python):
import numpy as np
import sys

x, n = map(int, input().split())
if(n==0):
  print(x)
  sys.exit()
c = 0
b = 0
p = list(map(int, input().split()))
for i in range(102):
  for j in range(n):
    if(p[j] - x + i == 0):
      c+=1
    if(p[j] - x - i==0):
      b+=1
  if(b==0 or c==0):
    if(c==0):
      print(x-i)
      sys.exit()
    else:
      print(x+i)
      sys.exit()
  else:
    b=0
    c=0

Solution (Python):
X,N=map(int,input().split())
if N==0:
    print(X)
    exit()
s=set(map(int,input().split()))
ans=10**9
for i in range(101):
    if not X-i in s:
        print(X-i)
        exit()
    if not X+i in s:
        print(X+i)
        exit()

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


l,r = x,x
while True:
  if l not in p:
    print(l)
    exit()
  elif r not in p:
    print(r)
    exit()

  l-=1
  r+=1

Solution (Python):



import os
import sys







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

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

    min_num = 0
    min_dist = 101
    P.sort()
    for i in range(0, 102):
        if i in P: continue

        dist = abs(X - i)

        if dist < min_dist:
            min_dist = dist
            min_num = i

    print(min_num)

    return


if __name__ == '__main__':
    main()

Solution (Python):
a,b= map(int, input().split())
if(b==0):
    print(a)
else:
    L=list(map(int,input().split(" ")))
    if(a not in L):
       print(a)
    else:
       i=int(1)
       while(True):
          if((a-i) not in L):
             print(a-i)
             break
          elif((a+i) not in L):
             print(a+i)
             break
          i+=1

Solution (Python):
tmp = input().split()
x = int(tmp[0])
n = int(tmp[1])

if(n == 0):
    print(x)
else:
    p_str_list = input().split()
    p_int_list = [int(x) for x in p_str_list]

    flg = True
    abs_count = 0
    answer = 0
    while(flg):
        search_n_minus = x - abs_count
        search_n_plus = x + abs_count
        if(search_n_minus in p_int_list):
            if(search_n_plus in p_int_list):
                abs_count += 1
            else:
                answer = search_n_plus
                break
        else:
            answer = search_n_minus
            break
    print(answer)

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

ans = -1
dmin=100
for i in range(102):
    if i in Ps:
        continue
    if abs(i-X) < dmin:
        ans =i
        dmin = abs(i-X)
print(ans)

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
    if X+i not in p:
        print(X+i)
        break

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

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

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


for i in range(100):
    if n-i not in l:
        print(n-i)
        break
    if n+i not in l:
        print(n+i)
        break

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

answer = -1
for i in range(max(x - n, 0), x + n + 1):
    if i in li_p:
        continue
    if abs(answer - x) > abs(i - x):
        answer = i
print(answer)

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())
a = list(map(int, input().split()))
ans = 1
min_diff = float('inf')
for i in range(0, 102):
    if i in a:
        continue
    if (abs(i - X) < min_diff) or (abs(i - X) == min_diff and i < ans):
        min_diff = abs(i - X)
        ans = i
print(ans)

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

if N == 0:
  ans = X
else:
  p = list(map(int, input().split()))
  ans = 0
  for i in range(200):
    if i in p:
      continue
    else:
      dis = abs(i - X)
      if dis < abs(ans - X):
        ans = i

print(ans)

Solution (Python):
x, n = map(int, input().split())
p = {*map(int, input().split())}

ans = 1000
diff = 1000
for i in range(102):
  if i in p:
    continue
  if abs(x - i) < diff:
    diff = abs(x - i)
    ans = i
print(ans)

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

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

Solution (Python):
str1 = input()
lst1 = str1.split()
x = int(lst1[0])
n = int(lst1[1])

string = input()
list = string.split()
p = []
for num in list:
    p.append(int(num))

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
    else:
        continue

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

ans_enable = [True] * 102

for pi in p:
    ans_enable[pi] = False

diff = 0

check_ok = ans_enable[X]

ans_small = True

while not check_ok:
    diff += 1
    if ans_enable[X - diff]:
        check_ok = True
        ans_small = True
    elif ans_enable[X + diff]:
        check_ok = True
        ans_small = False

print(X - diff if ans_small else X + diff)

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

for i in range(102):
    if i not in p:
        lst.append(abs(x- i))
d = min(lst)
l = x-d
u = x+d
if l not in p:
    print(l)
else:
    print(u)

Solution (Python):
import numpy as np


def getNearestValue(list, num):
    """
    概要: リストからある値に最も近い値を返却する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]


X, Y = map(int, input().split())
list = list(map(int, input().split()))
list = sorted(list)


listHandred = []
for i in range(0,102):
    listHandred.append(i)
    
ansList = listHandred

for i in list:
    if i in ansList:
        ansList.remove(i)

print(getNearestValue(ansList,X))

Solution (Python):
def solve():
	X, N = map(int, input().split())
	arr = set(map(int, input().split()))
	if X not in arr:
		return X
	i = X - 1
	j = X + 1
	while True:
		if i not in arr:
			return i
		else:
			i -= 1
		if j not in arr:
			return j
		else:
			j += 1
		


def main():
	print(solve())


if __name__ == '__main__':
	main()

Solution (Python):
import math
x,n=map(int,input().split())
arr=list(map(int,input().split()))
min1,ans1=float('INF'),float('INF')
for i in range(x,x+n+1):
    if i not in arr:
        min1=abs(i-x)
        ans1=i
        break
min2,ans2=float("INF"),float("INF")
for i in reversed(range(x-n,x+1)):
    if i not in arr:
        min2=abs(i-x)
        ans2=i
        break

if min1>min2:
    print(ans2)
elif min1==min2:
    print(min([ans1,ans2]))
else:
    print(ans1)

Solution (Python):
x,n=map(int, input().split())
ans=x
judge=True
if(n!=0):
  p=list(map(int, input().split()))
else:
  ans=x
  judge=False

if(judge):
  check=True
  s_list=[]
  l_list=[]
  for i in range(n):
    for j in range(n):
      if(x-i==p[j]):
        check=False
    if(check):
      s_list.append(x-i)
    check=True

    for i in range(n):
      for j in range(n):
        if(x+i==p[j]):
          check=False
      if(check):
        l_list.append(x+i)
      check=True
    if(l_list == [] and s_list == []):
      ans = x-1
    elif(l_list == []):
      ans = max(s_list)
    elif(s_list == []):
      ans = min(l_list)
    else:
      if(abs(x-min(l_list)) > abs(x-max(s_list))):
        ans = max(s_list)
      elif(abs(x-min(l_list))==abs(x-max(s_list))):
        ans=max(s_list)
      else:
        ans=min(l_list)  

print(ans)