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=[int(x) for x in input().split()]

ans=X
if N!=0:
    k=0
    while True:
        if X-k not in p:
            ans=X-k
            break
        elif X+k not in p:
            ans=X+k
            break
        k+=1
print(ans)

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

if N == 0:
    print(X)
else:
    a = [int(i) for i in range(-201, 201) if not i in p]
    m = 100
    val = 0
    for i in a:
        if abs(i-X) < m:
            m = abs(i-X)
            val = i
    print(val)

Solution (Python):
x, n =map(int,input().split())
ps = list(map(int, input().split()))
a=100

if not(x in ps):
    print(x)
else:
    for i in range(100):
        if x+i in ps:
            b=100
        else:
            a=x+i
            break
    for j in range(100):
        if x-j in ps:
            b=100
        else:
            if a-x>=j:
                a=x-j
                break
    print(a)

Solution (Python):
x,n = map(int,input().split())
ans = 0
if n == 0:
    print(x)
else:
    p = sorted(list(map(int,input().split())), reverse=True)
    data = []
    for i in range(200,-100,-1):
        if not(i in p):
            data.append(i)
    
    mi = 1000
    for i in data:
        
        if mi >= abs(i-x):
            mi = abs(i-x)
            ans = i
    print(ans)

Solution (Python):
x, n = map(int, input().split())
p = list(map(int,input().split()))
l = [i for i in range(x+101)]
for pi in p:
    l[pi] = 500
m = 10000
ans = 0
for li in l:
    if m > abs(x-li):
        m = abs(x-li)
        ans = li
print(ans)

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

l = set(l)
p = set(p)
dif = list(l-p)
dif.sort(reverse=True)
ans_min=1000000
ans = 0
for i in dif:
    if ans_min>=abs(x-i):
        ans_min=abs(x-i)
        ans = i

print(ans)

Solution (Python):
import math
def ip():return int(input())
def imp():return map(int,input().split())
def impstr():return map(str,input().split())
def limp():return list(map(int,input().split()))
def limpstr():return list(map(str,input().split()))

x,n=imp()
l=limp()
if n==0:
    print(x)
    exit()
else:
    k=0
    while True:
        if x-k not in l:
            print(x-k)
            exit()
        if x+k not in l:
            print(x+k)
            exit()
        k+=1

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



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

for i in range(1, 100):
    if X-i not in seq:
        print(X-i)
        exit()
    elif X+i not in seq:
        print(X+i)
        exit()

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

a = -1
if len(P) > 0:
    for p in range(0, 102):
        if abs(X - p) < abs(X - a) and (p not in P):
            a = p
else:
    a = X

print(a)

Solution (Python):
from sys import stdin, stdout

int_in = lambda: int(stdin.readline())
arr_in = lambda: [int(x) for x in stdin.readline().split()]
mat_in = lambda rows: [arr_in() for y in range(rows)]
str_in = lambda: stdin.readline().strip()
out = lambda o: stdout.write("{}\n".format(o))
arr_out = lambda o: out(" ".join(map(str, o)))
bool_out = lambda o: out("YES" if o else "NO")
tests = lambda: range(1, int_in() + 1)
case_out = lambda i, o: out("Case 


def solve(x, n, p):
    p = set(p)
    best = -1
    best_diff = abs(x + 1)
    for item in range(501):
        if item not in p and abs(item - x) < best_diff:
            best_diff = abs(item - x)
            best = item
    return best


if __name__ == "__main__":
    x, n = arr_in()
    if n == 0:
        out(x)
        exit()
    p = arr_in()
    out(solve(x, n, p))

Solution (Python):
import bisect
x,n=map(int,input().split())
if n==0:
  print(x)
  exit()
p=sorted(list(map(int,input().split())))
a=bisect.bisect_left(p,x)
if p[a]!=x or n==0:
  print(x)
  exit()
i=0
while True:
  if not (x-i) in p:
    print(x-i)
    break
  elif not (x+i) in p:
    print(x+i)
    break
  else:
    i+=1

Solution (Python):
x, n = map(int, input().split())
if n == 0:
    print(x)
    exit(0)
else:
    p = [int(x) for x in input().split()]

p.sort()


ans1 = 300
ans2 = 300

flag = 1

for i in range(100):
    if x-i not in p:
        ans1 = x-i
        flag = 0
    if x+i not in p:
        ans2 = x+i
        flag = 0
    if flag == 0:
        break
    else:
        continue

print(min(ans1, ans2))

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

if N != 0:
    P=list(map(int,input().split()))
    P.sort()
    if X < P[0]:
        imin = X
    elif X > P[N-1]:
        imin = X 
    else:
        imin = 0
        max_diff = 1000
        for i in range(P[0]-1,P[N-1]+2):
            if i not in P:
                if abs(i-X) < max_diff:
                    max_diff = abs(i-X)
                    imin = i
else:
    imin = X

print(imin)

Solution (Python):
x, n = map(int, input().split())
if n!=0:
    lst = [i for i in range(102)]
    a = list(map(int, input().split()))

    for i in range(n):
        lst.remove(a[i])
    
    if x in lst:
        print(x)
    else:
        b=x
        c=x
        for i in range(100):
            b-=1
            c+=1
            if b in lst:
                print(b)
                break
            elif c in lst:
                print(c)
                break
    
else:
    print(x)

Solution (Python):
x,n=map(int,input().split())
p=list(map(int,input().split()))
ans=10**18
a=[]
for i in range(-101,200):
  if i in p:continue
  d=abs(x-i)
  if d<ans:
    ans=d
    a.append([d,i])


a.sort(key=lambda x: x[0])

mnv=a[0][0]
mnidx=a[0][1]
for ai in a:
  v,idx=ai
  if mnv==v:
    if idx<mnidx:
      mnidx=idx
  else:
    break
print(mnidx)

Solution (Python):
x,n = map(int,input().split())
p = set()
if n:
    p = set(map(int,input().split()))
mini = float('inf')
ans = float('inf')
for i in range(-400,400):
    if i not in p:
        if abs(x-i)<mini:
            mini = abs(x-i)
            ans = i
        elif abs(x-i)==mini and ans>i:
            ans=i
print(ans)

Solution (Python):
import bisect
import sys
from collections import defaultdict
X, N = [int(x) for x in input().split()]
P = []
if N:
    P = [int(x) for x in input().split()]

Pt = defaultdict(bool)
for p in P:
    Pt[p] = True

if Pt[X] == False:
    print(X)
    sys.exit()

xl = X - 1
xr = X + 1
while True:
    if Pt[xl] == False:
        print(xl)
        break
    elif Pt[xr] == False:
        print(xr)
        break
    xl -= 1
    xr += 1

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

Ps = sorted(P)

for z in range(0,101):
    if not(X-z in P):
        print(X-z)
        break
    if not(X+z in P):
        print(X+z)
        break

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

    add_minus = -1
    while True:
        add_minus += 1
        if (X - add_minus) not in p:
            print(X - add_minus)
            break
        elif (X + add_minus) not in p:
            print(X+add_minus)
            break

Solution (Python):
def main():
    x,n = map(int,input().split())
    p = list(map(int,input().split()))
    min = 100000
    ans = 0
    for i in range(-10000,10000):
        if i in p:
            pass
        elif min > abs(i-x):
            min = abs(i-x)
            ans = i
            
    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
x,n=map(int,input().split())
a_list=list(map(int,input().split()))
current_num=0
while(True) :
  t=x+current_num not in a_list
  s=x-current_num not in a_list
  if s:
    print(x-current_num)
    break
  elif t :
    print(x+current_num)
    break
  else :
    current_num+=1

Solution (Python):
import math
import numpy as np
X, N = map(int,input().split())
ans = False
if not N == 0:
  p = list(map(int,input().split()))
else:
  print(X)
  ans = True
if not ans:
  for i in range(101):
    if not (X- i in p):
      print(X-i)
      break
    elif not (X + i in p):
      print(X+i)
      break

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


for i in range(102):
    if i in p:
        continue

    if abs(X - i) < dist:
        ans = i
        dist = abs(X - i)

print(ans)

Solution (Python):
import numpy as np

X, N = list(map(int, input().split()))
p_list = set(sorted(list(map(int, input().split()))))

if N == 0:
  print(X)
  exit()
  
i = sorted(list(set(range(X-N, X+1)) - p_list))[-1]
j = sorted(list(set(range(X, X+N+1)) - p_list))[0]

if X-i <= j-X:
  print(i)
else:
  print(j)

Solution (Python):
import sys
from io import StringIO
import unittest
import os


sys.setrecursionlimit(999999999)



def resolve():
    x, n = map(int, input().split())

    if n == 0:
        print(x)
        return

    p_list = list(map(int, input().split()))
    p_list.sort()
    p_list = set(p_list)

    ans = 9999
    work_abs = 9999
    for i in range(110):
        if i in p_list:
            continue

        work_x = max(x, i)
        work_p = min(x, i)
        if work_abs > work_x - work_p:
            work_abs = work_x - work_p
            ans = i

    print(ans)



class TestClass(unittest.TestCase):
    def assertIO(self, assert_input, output):
        stdout, sat_in = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, sat_in
        self.assertEqual(out, output)

    def test_input_1(self):
        test_input = """6 5
4 7 10 6 5"""
        output = """8"""
        self.assertIO(test_input, output)

    def test_input_2(self):
        test_input = """10 5
4 7 10 6 5"""
        output = """9"""
        self.assertIO(test_input, output)

    def test_input_3(self):
        test_input = """100 0"""
        output = """100"""
        self.assertIO(test_input, output)

    
    def tes_t_1original_1(self):
        test_input = """データ"""
        output = """データ"""
        self.assertIO(test_input, output)



if __name__ == "__main__":
    if os.environ.get("USERNAME") is None:
        
        resolve()

    else:
        
        unittest.main()

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

p_all = set(range(-200, 200)) - set(p)


mi = float('inf')
ans = 0
for i in p_all:
    if abs(x - i) < mi:
        mi = abs(x - i)
        ans = i

print(ans)

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

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

seen = [0]*(100+2)

for p in ps:
    seen[p] = 1

if seen[x] == 0:
    print(x)
    exit()

count = 1
candidate = []
while True:
    nside = max(0, x - count)
    if seen[nside] == 0:
        candidate.append(nside)
        print(nside)
        exit()

    pside = min(102, x + count)
    if seen[pside] == 0:
        candidate.append(pside)
        print(pside)
        exit()
    count += 1

Solution (Python):

 

 
import sys
from fractions import gcd
import math
from math import ceil,floor
import collections
from collections import Counter
import itertools
 

 







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

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

P.sort()

tmp1 = 0
tmp2 = 0

for i in range(X,102):
    if P.count(i)==0:
        tmp1 = i
        break

j = X
while j >= 0:
    if P.count(j)==0:
        tmp2 = j
        break    
    j -= 1

tmp3 = abs(X - tmp1)
tmp4 = abs(X - tmp2)

if tmp3 >= tmp4:
    print(tmp2)
else:
    print(tmp1)

Solution (Python):


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


i = x
while True:
    if i not in s:
        res_high = i
        break
    else:
        i += 1


j = x
while True:
    if j not in s:
        res_low = j
        break
    else:
        j -= 1


if abs(res_low - x) <= abs(res_high - x):
    print(res_low)
else:
    print(res_high)

Solution (Python):
x,n=map(int,input().split())
p=list(map(int,input().split()))
f=0
ans=[]
for i in range(60):
    if not (x+i) in p or not (x-i) in p:
        ans.append(x-i)
        ans.append(x+i)
if not ans[0] in p and not ans[1] in p:
    print(ans[0])
elif not ans[0] in p and ans[1] in p:
    print(ans[0])
elif ans[0] in p and not ans[1] in p:
    print(ans[1])

Solution (Python):

import sys
input = sys.stdin.readline
ipnl = lambda n: [int(input()) for _ in range(n)]
inp = lambda :int(input())
ip = lambda :[int(w) for w in input().split()]

k,n = ip()
if n:
    x = ip()
    x = set(x)
    if k not in x:
        print(k)
    else:
        a = k-1
        while a in x:
            a -= 1
        b = k+1
        while b in x:
            b += 1
        if abs(a-k) < abs(b-k):
            print(a)
        elif abs(b-k) < abs(a-k):
            print(b)
        else:
            print(min(a,b))
else:
    print(k)

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

Solution (Python):
a=300
x,n=map(int, input().split())
if n==0:
    a=x
else:
    p= list(map(int, input().split()))
    ls=[j  for j in range(-100,200)]

    for i in range(len(p)):
        ls.remove(p[i])
    for k in range(len(ls)):
        if abs(x-ls[k])<abs(x-a):
             a=ls[k]
        elif abs(x-ls[k])==abs(x-a):
            if ls[k]<a:
                a=ls[k]
print(a)

Solution (Python):
import sys
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)
    sys.exit()
  if x+i not in p:
    print(x+i)
    sys.exit()

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

Solution (Python):


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

if S[1]==0:
  print(S[0])
else:
  N=list(map(int,input().split()))
  k=S[0]
  t=S[0]
  s=0
  u=1
  while k in N != True:
    if s==0:
      k=t-u
      s=1
    else:
      k=t+u
      s=0
      u+=1
  print(k)

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

ans = 0
tmp = float("inf")
for i in range(1000):
    if i not in p:
        if abs(x - i) < tmp:
            tmp = abs(x - i)
            ans = i

print(ans)

Solution (Python):
import sys
N , M = (map(int , input().split()))
if M == 0:
    print(N)
    sys.exit()
A = list(map(int , input().split()))
aa = [i for i in range(-102,102)]
ans_list = {}
for i in aa:
    if i not in A:
        ans_list.update({i:abs(N-i)})
for i in ans_list:
    if ans_list[i] == min(list(ans_list.values())):
        print(i)
        sys.exit()

Solution (Python):
X,N=map(int,input().split())
p=[0]*N
p=list(map(int,input().split()))
mixmix=float('inf')
hozon=-1
if(p.count(X)!=1):
    print(X)
    exit()
for i in range(1,101):
    if(p.count(X-i)!=1):
        print(X-i)
        exit()
    elif(p.count(X+i)!=1):
        print(X+i)
        exit()

Solution (Python):
X, N = [int(n) for n in input().split()]
P = [int(n) for n in input().split()]

for n in range(100):
    if (X - n) not in P:
        print(X-n)
        exit()
    if (X + n) not in P:
        print(X+n)
        exit()

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

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

Solution (Python):
X,N=map(int,input().split())
if N==0:
  print(X)
  exit()
P=list(map(int,input().split()))
nP=[]
min=10**15
for i in range(-200,200):
  if i not in P:
    nP.append(i)
anlist=[]
for i in nP:
  if min>abs(i-X):
    min=abs(i-X)
    anlist.append(i)
print(anlist[-1])

Solution (Python):
import bisect

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

if not p:
    print(X)
    exit()

pos = bisect.bisect_left(p, X)

left, right = p[pos], p[pos]
l_abs, r_abs = 0, 0
while True:
    if left in p:
        left -= 1
        l_abs += 1
    if right in p:
        right += 1
        r_abs += 1
    if left not in p and right not in p:
        break

if l_abs == r_abs:
    print(left)
elif l_abs > r_abs:
    print(right)
else:
    print(left)

Solution (Python):
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce


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


def INT(): return int(input())


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


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


def ZIP(n): return zip(*(MAP() for _ in range(n)))


sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    X, N = MAP()
    if N == 0:
        print(X)
        exit()

    p = LIST()
    ans = []
    for i in range(200):
        if not X-i in p:
            print(X-i)
            exit()
        if not X+i in p:
            print(X+i)
            exit()
        

if __name__ == '__main__':
    main()

Solution (Python):
x,n=map(int,input().split())
if n!=0:
  p=list(int(i) for i in input().split())

  for i in range(100):
    kouho1=x+i
    kouho2=x-i
    if kouho2 not in p:
      print(kouho2)
      break
    elif kouho1 not in p:
      print(kouho1)
      break
else:
  print(x)

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

ans=10000
b=0

an=10000

for i in range(0,102):
    b=0

    for _ in p:
        if i==_:
            b=1
            break
    
    if b!=1:
        if ans> abs(x-i):
            ans=abs(x-i)
            an=i

print(an)

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

if n == 0:
    print(x)
else:
    p = list(map(int, input().split()))
    a = []
    for i in range(102):
        if all([j != i for j in p]):
            a.append(i)
    z = x
    ans = 0
    for i in a:
        if z > abs(x-i):
            z = abs(x-i)
            ans = i
    print(ans)

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

Solution (Python):
def main():
    X,N = [int(x) for x in input().split()]
    P = [int(x) for x in input().split()]
    top_diff = 200
    ans = 0
    for i in range(-101,201):
        
        if not i in P:
            if abs(X-i) < top_diff:
                top_diff = X-i
                ans = i
    print(ans)

if __name__ == '__main__':
    main()

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

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

Solution (Python):

def main():
    import sys
    imput = sys.stdin.readline
    
    
    
    X, N = map(int, input().split())
    p = list(map(int, input().split()))

    
    answer1 = X
    answer2 = X
    while answer1 in p:
        answer1 -= 1
    while answer2 in p:
        answer2 += 1

    if X - answer1 == answer2 - X:
        print(answer1)
    elif X - answer1 < answer2 - X:
        print(answer1)
    elif X- answer1 > answer2 - X:
        print(answer2) 

    
if __name__ == "__main__":
    main()

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

cnt = 0
while True:
    big = x + cnt
    small = x - cnt
    if small not in p:
        print(small)
        exit()
    if big not in p:
        print(big)
        exit()
    cnt += 1

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

r=0
while True:
  if not (x-r in p):
    print(x-r)
    exit()
  if not (x+r in p):
    print(x+r)
    exit()
  r+=1
print(1/0)

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

for i in range(102):
    if i in p:
        pass
    else:
        if abs(i-X) < min_value:
            ans = i
            min_value = abs(i-X)
print(ans)

Solution (Python):
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
    elif not x+i in p:
        print(x+i)
        break
    i += 1

Solution (Python):
def main():
    x, n = map(int, input().split())
    ps = list(map(int, input().split()))
    anti_ps = [i for i in range(102) if i not in ps]
    anti_ps_abs = [abs(i-x) for i in range(102) if i not in ps]
    ans = anti_ps[anti_ps_abs.index(min(anti_ps_abs))]
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
x, p = map(int,input().split())
N = set(list(map(int, input().split())))
for i in range(100):
    if x-i not in N:
        print(x-i)
        quit()
    if x+i not in N:
        print(x+i)
        quit()

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

ans=0
minAbs=abs(X-ans)

for i in range(0,102):
    if (i in p)==True:
        continue

    if abs(X-i)<minAbs:
        minAbs=abs(X-i)
        ans=i

print(ans)

Solution (Python):
from functools import cmp_to_key

x, n = map(int, input().split())
p = set(map(int, input().split()))
for d in range(100):
    if (x - d) >= -101 and (x - d) not in p:
        print(x - d)
        break
    elif (x + d) <= 101 and (x + d) not in p:
        print(x + d)
        break

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

if N == 0:
  print(X)
else:
  num_list = list(map(int, input().split()))
  sub_list = [x-X for x in num_list]
  
  for i in range(100):
    if -i not in sub_list:
      print(X - i)
      break
    elif i not in sub_list:
      print(X + i)
      break

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

b = [True for _ in range(0, 102)]

for i in range(n):
    b[p[i]] = False

for i in range(101):
    if 0 <= x-i <= 101:
        if b[x-i]:
            print(x-i)
            break
    if 0 <= x+i <= 101:
        if b[x+i]:
            print(x+i)
            break

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

a = 0
for i in range(x-1, -10**9, -1):
  if i not in p:
    a = i
    break
b = 0
for i in range(x, 10**9):
  if i not in p:
    b = i
    break

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

Solution (Python):
import sys

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

def main():
    x, n= map(int, input().split())
    if n == 0:
        print(x)
        return
    P=[]
    P = list(map(int, input().split()))
    
    for i in range(100):
        a = x-i
        b = x+i
        if a not in P:
            print(a)
            return
        elif b not in P:
            print(b)
            return
    


main()

Solution (Python):
def main():
    X , N = map(int, input().split())
    Pl = [A for A in input().split()]
    Pl = list(map(int, Pl))
    
    for i in range(200) :
        Xp = X + i
        Xm = X - i
        if Xp not in Pl and Xm not in Pl :
            ans = min(Xp,Xm)
            break
        elif Xm not in Pl and Xp in Pl :
            ans = Xm
            break
        elif Xp not in Pl and Xm in Pl :
            ans = Xp
            break
        else :
            pass
    print(ans)




if __name__ == '__main__':
    main()

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

Solution (Python):
import sys
X,N = map(int,input().split())
zettai = 10000
ans = 0
if N == 0:
    print(X)
    sys.exit()
    
a = list(map(int,input().split()))



for i in range(102,-1,-1):
    b = abs(X-i)
    if i in a:
        continue
    elif b <= zettai:
        zettai = b
        ans = i

print(ans)

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

if n == 0:
  print(x)

else:
  p = list(map(int, input().split()))
  p.sort()

  res = 100000
  ps = 0
  for i in p:
    ab = abs(x - i)
    if res > ab:
      res = ab
      ps = i
    else:
      break
  flug = False
  iter = 1
  while flug == False:
    ans1 = iter + ps
    ans2 = ps - iter
    if (ans2 in p) is False:
      print(ans2)
      flug = True
    elif (ans1 in p) is False:
      print(ans1)
      flug = True
    else:
      iter += 1

Solution (Python):
x,n = map(int,input().split())
p = list(map(int,input().split()))
c= x
d = x
while(1):
    if(not (c in p)):
        print(c)
        break
    if(not (d in p)):
        print(d)
        break
    c -=1
    d +=1

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

check = 1000000
ans = 0

N = list(range(-300, 300))

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

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

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

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

q = set(range(102))

r = q - p

ans = 0
diff = 1000

for i in r:
  if abs(x - i) < diff:
    diff = abs(x - i)
    ans = i
    
print(ans)

Solution (Python):
import sys

X, N = map(int, input().split())
p = list(map(int, input().split()))
flag = 0
if (X in p) is False:
    print(X)
    sys.exit()
Xmin = X
Xmax = X
while flag == 0:
    Xmin = Xmin - 1
    Xmax = Xmax + 1

    if (Xmin in p) is False:

        print(Xmin)
        sys.exit()
    if (Xmax in p) is False:
        print(Xmax)
        sys.exit()

Solution (Python):
X, N = map(int,input().split())
P =list(map(int,input().split()))
ans = 1000
point = 0
for i in range(103):
    if i not in P:
        if ans > abs(X-i):
            ans = abs(X-i)
            point = i
print(point)

Solution (Python):




def main():

    
    first_input = list(map(lambda x:int(x), input().split(" ")))
    

    
    
    

    
    

    X = first_input[0]
    N = first_input[1]
    if N!=0:
        p_list = list(map(lambda x:int(x), input().split(" ")))
    else:
        print(X)
        return

    if X not in p_list:
        print(X)
        return

    x = X
    for i in range(1,52):
        if x-i not in p_list:
            print(x-i)
            return
        if x+i not in p_list:
            print(x+i)
            return



if __name__ == '__main__':
    main()

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

ans = 0
m = float("inf")
for i in range(-200, 200):
    if i not in p:
        if abs(i-x) < m:
            ans = i
            m = abs(i-x)

print(ans)

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

Solution (Python):
import sys

def prepare(X):
    N = 101
    List = [X] * N
    for i in range(0, 50):
        List[2*i+1] = X-i-1
        List[2*i+2] = X+i+1
    return List

def remove(List, N, PList):
    for Num in range(N):
        if(PList[Num] in List):
            List.pop( List.index(PList[Num]) )
    print(List[0])
if(__name__ == "__main__"):

    XY = input().strip().split()
    X = int(XY[0])
    N = int(XY[1])

    PList = [0] * N
    if(N > 0):
        P_str = input().strip().split()

        for i in range(N):
            PList[i] = int( P_str[i] )

        List = prepare(X)
        remove(List, N, PList)
    else:
        print(X)

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

if N==0:
  print(X)
else:
  P = list(map(int,input().split()))
  Q = [n for n in range(-1000,1000) if n not in P]
  a = 10000
  d1 = 10000
  
  for q in Q:
    d2 = abs(q-X)
    if d2<d1:
      d1 = d2
      a = q
  
  print(a)

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

if N == 0:
    print(X)
else:
    p = list(map(int,input().split()))
    p.sort()
    q = list(range(p[-1]+2))
    pq=list(set(p)^set(q))
    ind = bisect.bisect_left(pq, X)
    

    if abs(X-pq[ind]) >= abs(X-pq[ind-1]):
        print(pq[ind-1])
    else:
        print(pq[ind])

Solution (Python):
X,N=map(int,input().split())
p=list(map(int,input().split()))
ans=0
sa=1000
if N==0:
    print(X)
    exit()
for i in range(-1,102):
    tmp=0
    if i in p:
        continue
    else:
        tmp=abs(X-i)
        if tmp<sa:
            sa=tmp
            ans=i
print(ans)

Solution (Python):
def main():
    X, N = map(int, input().split())
    P = [int(p) for p in input().split()]

    NP = list()

    for i in range(-500, 501):
        if i in P:
            pass
        else:
            NP.append(i)

    mi = 10000

    for i in range(len(NP)):
        diff = abs(NP[i] - X)

        if diff < mi:
            mi = diff

    ans = list()

    for i in range(len(NP)):
        if abs(NP[i] - X) == mi:
            ans.append(NP[i])

    ans.sort()
    print(min(ans))

if __name__ == "__main__":
    main()

Solution (Python):

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

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

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

Solution (Python):

import collections
import sys
import math


def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())


def main():
    X, N = LI()
    PArry = LI()
    ans = float("inf")
    sa = float("inf")
    for i in range(-N, N+1):
        a = X+i
        if a in PArry:
            continue
        s = abs(X-a)
        if sa == s:
            ans = min(ans, a)
        if s < sa:
            ans = a
            sa = s

    print(ans)


if __name__ == '__main__':
    main()