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())
if n == 0:
    print(x)
    exit()
p = list(map(int, input().split()))
p.sort()
ans = -1
tmp = 1000
for i in range(0, 102):
    cnt = 0
    for j in range(n):
        if i == p[j]:
            cnt += 1001
            break
    cnt += abs(x - i)
    if cnt < tmp:
        tmp = cnt
        ans = i
print(ans)

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

p = set(p)

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

Solution (Python):
x, n = map(int, input().split())
if n == 0:
    print(x)
else:
    p = [int(i) for i in input().split()]
    q = [x]
    for i in range(200):
        q.append(x - 1 - i)
        q.append(x + 1 + i)
    for i in q:
        if i not in p:
            print(i)
            break

Solution (Python):
def LI(): return list(map(int, input().split()))
def I(): return map(int, input().split())
mod = 10**9 + 7

def main():
  x,n =I()
  p = LI()
  for i in range(51):
    if x - i not in p:
      ans = x - i
      break
    if x + i not in p:
      ans = x + i
      break
  print(ans)
if __name__ == '__main__':
  main()

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

if n == 0:
  print(x)
else:
  p_list = list(map(int,input().split()))
  result_list = []
  for i in range(0,102):
    if i not in p_list:
      result_list.append([i,abs(x - i)])
    
  result_list.sort(key=lambda x: x[1])
  print(result_list[0][0])

Solution (Python):
import sys

sys.setrecursionlimit(10**6)
readline = sys.stdin.readline


def main():
    X, N = map(int, readline().split())
    p = set(map(int, readline().split()))
    pallset = set(range(-1, 102))
    remain = pallset - p
    dist = 200; ans = []
    for i in remain:
        if dist > abs(i-X):
            dist = abs(i-X)
            ans.append((i, dist))
    ans.sort(key=lambda x: x[1])
    print(ans[0][0])

if __name__ == "__main__":
    main()

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

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

if X in p:
    for i in range(1,1000):
        if not (X-i) in p:
            ans = (X-i)
            break
        if not (X+i) in p:
            ans = (X+i)
            break
else:
    ans = X
    
        
print(ans)

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

ans = 200
abs_ans = 200
for i in range(102):
    if i in P:
        continue
    if abs(x-i) < abs_ans:
        ans = i
        abs_ans = abs(x-i)
print(ans)

Solution (Python):
def main():
    x,n = map(int,input().split())
    p = list(map(int,input().split()))
    now = x
    now2 = x
    while True:
        f1 = now in p
        f2 = now2 in p

        if f1 and f2:
            now += 1
            now2 -= 1
            continue
        if f1 and not f2:
            ans = now2
            break
        if f2 and not f1:
            ans = now
            break
        if not f1 and not f2:
            ans = now2
            break
        
        
        
        
        
        
        
        
        
        
        
    print(ans)
if __name__=='__main__':
    main()

Solution (Python):




import sys
input = sys.stdin.readline



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

    for diff in range(101):
        test = X - diff
        if test not in p:
            res = test
            break
        test = X + diff
        if test not in p:
            res = test
            break

    print(res)



main()

Solution (Python):

x, y, *p = map(int, open(0).read().split())
if y == 0:
    print(x)
    quit()
a = []
for i in range(min(p)-1, max(p)+2):
    if i not in p:
        a += [(abs(x-i), i)]
a.sort(key=lambda x: (x[0], x[1]))
print(a[0][1])

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()


X, N = inm()
P = inl()


def solve():
    ps = set(P)
    if X not in ps:
        return X

    mv = 1000
    my = 10000
    for y in range(-1, 102):
        if y in ps:
            continue
        if abs(y - X) < mv or abs(y - X) == mv and y < my:
            mv = abs(y - X)
            my = y
    return my


print(solve())

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

min_m = -1
min_diff = 1e9
for m in range(102):
    diff = abs(m - x)
    if diff < min_diff and m not in ps:
        min_m = m
        min_diff = diff

print(min_m)

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

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


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

    if p == [] or x not in p:
        print(x)
    else:
        p = set(p)
        i = 1
        while 1:
            if x - i not in p:
                print(x - i)
                break
            elif x + i not in p:
                print(x + i)
                break
            else:
                i += 1



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

    def test_入力例_1(self):
        input = """6 5
4 7 10 6 5"""
        output = """8"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """10 5
4 7 10 6 5"""
        output = """9"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """100 0"""
        output = """100"""
        self.assertIO(input, output)


if __name__ == "__main__":
    
    resolve()

Solution (Python):
X,N=map(int,input().split())
if N!=0:
  ls=list(map(int,input().split()))
  a=0
  for i in range(102):
    if i in ls:
      continue
    else:
      if abs(i-X)<abs(a-X):
        a=i
  else:
    print(a)
else:
  print(X)

Solution (Python):
def main():
    x, n = map(int, input().split())
    if n == 0:
        print(x)
        exit(0)
    p = list(map(int, input().split()))
    mx = max(p)
    mn = min(p)
    c = list(set(range(mn-1, mx+2)) - set(p))
    diff = 1000
    ans = 1000
    for i in c:
        if (abs(x-i) < diff) or (abs(x-i) == diff and x < ans):
            diff = abs(x-i)
            ans = i
    print(ans)
    
            
    

if __name__ == "__main__":
    main()

Solution (Python):

x, n = map(int, input().split())
p = sorted(map(int, input().split()))
ok = [True] * 300
for y in p:
    ok[y + 150] = False
for i in range(150):
    if ok[x - i + 150]:
        print(x - i)
        exit()
    if ok[x + i + 150]:
        print(x + i)
        exit()

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

    move = 0
    while True:
        minus_check = X - move
        if minus_check not in p:
            print(minus_check)
            break

        pulus_check = X + move
        if pulus_check not in p:
            print(pulus_check)
            break

        move += 1
else:
    print(X)

Solution (Python):

X,N = map(int,input().split())
def seek(X):
    r=map(int,input().split())
    s= set()
    
    for it in r:
        s.add(it)
    for d in range(0,N+1):
        if not X-d in s:
            print(X-d)
            break
        if not X+d in s:
            print(X+d)
            break
if(N>0):
    seek(X)
else:
    print(X)

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

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

s = 1
while True:
    if x - s not in p :
        print(x-s)
        exit()
    elif x + s not in p:
        print(x+s)
        exit()
    else:
        s += 1

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

x1 = x - 1
x2 = x + 1
while True:
    if x1 not in p:
        print(x1)
        exit()
    elif x2 not in p:
        print(x2)
        exit()
    x1 -= 1
    x2 += 1

Solution (Python):
x,n = map(int, input().split())
p = set(map(int, input().split()))
a = set(range(-200, 200))
b = a - p

mi = 10**6
ans = -1
for bi in b:
    if abs(bi - x) < mi:
        mi = abs(bi - x)
        ans = bi
print(ans)

Solution (Python):
x, n = list(map(int, input().split()))
p = list(map(int, input().split()))
if x not in p:
    print(x)
    exit()
    
for i in range(1, 51):
    ok1 = False
    ok2 = False
    if x-i not in p:
        ok1 = True
    if x+i not in p:
        ok2 = True
    if ok1 or ok2:
        if not ok2:
            print(x-i)
        elif not ok1:
            print(x+i)
        else:
            print(x-i)
        exit()

Solution (Python):
x,n = map(int,input().split())
if n == 0: 
    print(x)
    exit()
p = list(map(int,input().split()))
p = sorted(p)
ans = 100000
for i in range(-10000,10000):
    ok = True
    for j in range(n):
        if i == p[j]: ok = False
    if ok:
        if(abs(ans - x) > abs(x - i)):
            ans = i
print(ans)

Solution (Python):
X, N = map(int, input().split())
ps = list(map(int, input().split()))
for i in range(101):
    if X - i not in ps:
        print(X-i)
        exit()
    if X + i not in ps:
        print(X+i)
        exit()

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

diff = 1000
ans = x
for i in range(-300, 300):
    xx = x + i
    if abs(i) < diff and xx not in p:
        ans = xx
        diff = abs(i)

print(ans)

Solution (Python):

X, N = map(int, input().split())
if N == 0:
    print(X)
    exit()
P = list(map(int, input().split()))
P.sort()
ans = 10 ** 9

li = []
for i in range(-200, 201, 1):
    if i not in P:
        li.append(i)
for i in range(len(li)):
    if abs(ans - X) > abs(li[i] - X):
        ans = li[i]
print(ans)

Solution (Python):
x,n=map(int,input().split())
p=list(map(int,input().split()))
tmp=1000
for i in range(-100,300):
    if not i in p:
        tmp=min(tmp,abs(x-i))
for i in range(-100,300):
    if abs(x-i) == tmp and not i in p:
        print(i)
        exit()

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

i = 0
while True:
    y = X - i
    if not y in p:
        print(y)
        break
    y = X + i
    if not y in p:
        print(y)
        break
    i += 1

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

li = [0]*(100+2)
for i in range(n):
    li[pi[i]] = 1
    


dif = 10**10
ans = -1
    
for i in range(102):
    if li[i] == 0:
        if dif > abs(x-i):
            dif = abs(x-i)
            ans = i
            
print(ans)

Solution (Python):
x, n = map(int, input().split())
P = set([int(x) for x in input().split()])
ans = 10 ** 4
for i in range(-1, 102):
    if i in P:
        continue
    if abs(x - ans) == abs(i - x):
        ans = min(ans, i)
    if abs(x - ans) > abs(i - x):
        ans = i
print(ans)

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

k = 0
for i in range(N):
    if P[i] == X:
        k = 1
if k == 0:
    print(X)
    sys.exit()

mi = X-1
ma = X+1
while(True):
    k = 0
    for i in range(N):
        if P[i] == mi:
            k = 1
    if k == 0:
        print(mi)
        sys.exit()
    mi -= 1
    k = 0
    for i in range(N):
        if P[i] == ma:
            k = 1
    if k == 0:
        print(ma)
        sys.exit()
    ma += 1

Solution (Python):




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



def int1(x):
    return int(x) - 1



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



def input_to_int_tuple():
    return tuple(map(int, input().split()))



def input_to_int_tuple_minus1():
    return tuple(map(int1, input().split()))


def main():
    x, n = input_to_int_map()
    p_list = input_to_int_tuple()

    target = []
    for i in range(-1, 102):
        if i not in p_list:
            target.append(i)

    sa = 200
    ret = x
    for val in target:
        t_sa = abs(x - val)
        if sa > t_sa:
            sa = t_sa
            ret = val

    return ret



if __name__ == "__main__":
    print(main())

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

if __name__ == '__main__':
    main()

Solution (Python):
import sys
x,n=map(int,input().split())
if n==0:
    print(x)
    sys.exit()
p=list(map(int,input().split()))
ans=1000
for i in range(0,102):
    if i not in p:
        tmp=abs(x-i)
        if tmp<ans:
            ans=tmp
            ansa=i
print(ansa)

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

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

Solution (Python):
from bisect import bisect_left
X, N = map(int, input().split())
P = sorted(list(map(int, input().split())))
i = 0
if N == 0:
  print(X)
else:
  while True:
    x = X-i
    idx = bisect_left(P, x)
    if idx < 0 or idx >= N or P[idx] != x:
      print(x)
      break
    else:
      x = X+i
      idx = bisect_left(P, x)
      if idx < 0 or idx >= N or P[idx] != x:
        print(x)
        break
    i += 1

Solution (Python):
X,N=map(int,input().split())
A=[]
if N != 0:
  A=list(map(int,input().split()))

visited=[False]*102

for a in A:
  visited[a] = True
  
min = 200
ans=-1
for i in range(102):
  if (not visited[i]) and min > abs(i - X):
    min=abs(i-X)
    ans=i
    
print(ans)

Solution (Python):


def main():
    X, N = map( int, input().split())
    if N == 0:
        print(X)
        return
    Q = list( map( int, input().split()))
    
    Z = [True]*102
    for q in Q:
        Z[q] = False
    P = []
    for i in range(102):
        if Z[i]:
            P.append(i)
    
    now = P[0]
    ab = abs(X-P[0])
    for p in P:
        pab = abs(X-p)
        if pab == ab:
            if p < now:
                now = p
        elif pab < ab:
            now = p
            ab = pab
    print(now)
if __name__ == '__main__':
    main()

Solution (Python):

import sys


def solve(X: int, N: int, p: "List[int]"):
    if not X in p:
        print(X)
        return
    for i in range(1, 100):
        left = X - i
        if not left in p:
            print(left)
            return
        right = X + i
        if not right in p:
            print(right)
            return
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  
    N = int(next(tokens))  
    p = [int(next(tokens)) for _ in range(N)]  
    solve(X, N, p)

if __name__ == '__main__':
    main()

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

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


for i in range(x,102):
    if i not in p:
        ans = i
        break

for i in reversed(range(-1,x)):
    if i not in p:
        if ans-x>=x-i:
            ans = i
        break
print(ans)

Solution (Python):
x,n = map(int, input().split())
p = [False] * 110
line = list(map(int, input().split()))
for i in range(n):
    p[line[i]] = True

ans = 0
a = 10000
for i in range(110):
    if p[i]:
        continue

    ai = abs(i - x)
    if ai < a:
        a = ai
        ans = i

print(ans)

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

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

for p in P:
    cands[p] = False

flag = False

if cands[X]:
    result = X
    flag = True

for i in range(1, 102):
    if flag:
        break
    if X + i < 102 and cands[X + i]:
        flag = True
        result = X + i
    if 0 <= X - i and cands[X - i]:
        flag = True
        result = X - i

print(result)

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

m = 0
d = X
for i in range(1, 102):
    if i in ps:
        continue

    if abs(X - i) < abs(X - m):
        m = i
        d = abs(X - i)

print(m)

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

for i in range(1000):
    if (X - i) not in p:
        print(X - i)
        exit()
    elif (X + i) not in p:
        print(X + i)
        exit()

Solution (Python):
import sys
from math import factorial
from collections import Counter
from fractions import Fraction
import heapq, bisect, fractions
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
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()))
MOD = 10**9 + 7

x, n = MAP()
p = LIST()
i = 0
while True:
    if x-i not in p:
        print(x-i)
        sys.exit()
    if x+i not in p:
        print(x+i)
        sys.exit()
    i += 1

Solution (Python):
x,n=map(int, input().split())
if n==0:
  print(x)
  exit()
p=list(map(int, input().split()))
ans=10**10
for i in range(102):
  if not x-i in p:
    print(x-i)
    exit()
  if not x+i in p:
    print(x+i)
    exit()

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

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

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

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

for i in range(102):
    if p.count(X-i) == 0:
        print(X-i)
        break
    if p.count(X+i) == 0:
        print(X+i)
        break

Solution (Python):






from collections import deque,defaultdict











import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
x,n = readInts()
if n == 0:
    print(x)
    exit()
P = readInts()
A = []
for i in range(-1,max(P)+1,1):
    if i + 1 in P:
        pass
    else:
        A.append(i+1)

m = float('inf')
ans = -1
for a in A:
    if abs(x - a) < m:
        ans = a
        m = abs(x-a)
print(ans)

Solution (Python):
inf = float('inf')
X,N = map(int,input().split())
p = list(map(int,input().split()))
ans = 101
diff = inf
for i in range(101,-1,-1):
    if i not in p:
        if diff >= abs(i-X):
            diff = abs(i-X)
            ans = i

print(ans)

Solution (Python):
X,N = map(int,input().split())
P = set(map(int,input().split()))
ans = 1001
diff = 1000
for i in range(102):
    if i in P:
        continue
    if abs(X-i) < diff:
        ans = i
        diff = abs(X-i)
print(ans)

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

ans = 1000
for i in range(-100, 1000):
    if abs(X-i) < abs(X-ans) and i not in P:
        ans = i
print(ans)

Solution (Python):
x,n = map(int,input().split())
P = [int(i) for i in input().split()]
kouho=[int(i) for i in range(-200,200)]
List = []
ans = 10**9
for i in kouho:
    if i not in P:
        tmp = abs(x-i)
        if tmp<ans:
            ans = tmp
            List = [i]
        elif tmp == ans:
            List.append(i)
List.sort()
print(List[0])

Solution (Python):


import re
import math
from collections import defaultdict
from collections import deque
import collections
from fractions import Fraction
import bisect
from queue import PriorityQueue
import itertools
from itertools import accumulate
from copy import deepcopy
import random
import time
import os
import sys
import datetime
from functools import lru_cache
from functools import reduce
readline=sys.stdin.readline
sys.setrecursionlimit(2000000)
alphabet="abcdefghijklmnopqrstuvwxyz"
numbers="0123456789"
mod=int(10**9+7)
inf=int(10**19)
class Edge():
    def __init__(self,x,y,val=1):
        self.x=x
        self.y=y
        self.val=val
class unionfind():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(n)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):
            self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def yn(b):
    if b:print("yes")
    else:print("no")
def Yn(b):
    if b:print("Yes")
    else:print("No")
def YN(b):
    if b:print("YES")
    else:print("NO")
def ispow(a,b):
    now=b
    while now<a:
        now*=b
    return now==a
def getbin(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def getfacs(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod_>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def nextcomb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:return num
def getprimes(n):
    if n==0:return []
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    ret=[]
    for a in range(n+1):
        if(A[a]):ret.append(a)
    return ret
def isprime(num):
    if(num<=1):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def ifelse(bbool,ret1,ret2):
    if bbool:return ret1
    else:return  ret2
def join(A,c=" "):
    n=len(A)
    A=list(map(str,A))
    return c.join(A)
def factorize(n):
    b = 2
    ret=defaultdict(int)
    while b * b <= n:
        while n % b == 0:
            n //= b
            ret[b]+=1
        b+=1
    if n > 1:ret[n]+=1
    return ret
def pm(x):
    return x//abs(x)
def inputintlist(): 
    return list(map(int,input().split()))
def inputfloatlist(): 
    return list(map(float,input().split()))
def tozero(A):
    ret=[None]*len(A)
    for a in range(len(A)):
        ret[a]=A[a]-1
    return ret
def istanchouzouka(A):
    f=True
    prev=min(A)-1
    for a in A:
        if prev>=a:
            f=False
        prev=a
    return f
def istanchouhigensyou(A):
    f=True
    prev=min(A)-1
    for a in A:
        if prev>a:
            f=False
        prev=a
    return f
def getallsum(A):
    s=sum(A)
    dp=defaultdict(int)
    dp[0]=1
    for a in range(0,len(A)):
        for b in range(s,-1,-1):
            if b-A[a]>=0:
                dp[b]+=dp[b-A[a]]
    return dp
def yuukoutomukou(edges):
    ret=deepcopy(edges)
    for edge in edges:
        if not edge.x==edge.y:
            ret.append(Edge(edge.y,edge.x,edge.val))
    return ret
def dijkstra(edges,V,start):
    mincost=[inf]*V
    G=[[] for a in range(V)]
    for edge in edges:
        G[edge.x].append([edge.val,edge.y])
    Q=PriorityQueue()
    Q.put([0,start])
    while not Q.empty():
        nowcost,nowx=Q.get()
        if mincost[nowx]==inf:
            mincost[nowx]=nowcost
            for cost,y in G[nowx]:
                newcost=nowcost+cost
                Q.put([newcost,y])
    return mincost
def warshallfloyd(edges,V):
    mincost=[[inf for b in range(V)] for a in range(V)]
    for a in range(V):mincost[a][a]=0
    for edge in edges:
        mincost[edge.x][edge.y]=min(mincost[edge.x][edge.y],edge.val)
    for k in range(V):
        for s in range(V):
            for t in range(V):
                if mincost[s][k]==inf or mincost[k][t]==inf:continue
                mincost[s][t]=min(mincost[s][t],mincost[s][k]+mincost[k][t])
    return mincost
def bellemanford(edges,V,start):
    mincost=[inf]*V
    mincost[start]=0
    for _ in range(V):
        for edge in edges:
            if mincost[edge.x]==inf:continue
            mincost[edge.y]=min(mincost[edge.y],mincost[edge.x]+edge.val)
    return mincost
def getmd(x1,y1,x2,y2):
    return abs(x1-x2)+abs(y1-y2)
def geted(x1,y1,x2,y2):
    return math.sqrt((x1-x2)**2+(y1-y2)**2)
class fordfulkerson():
    def __init__(self,edges,V,s,t):
        self.V=V
        self.used=[False]*V
        self.G=[[] for a in range(V)]
        self.s=s
        self.t=t
        for edge in edges:
            self.G[edge.x].append({"x":edge.x,"y":edge.y,"cap":edge.val,"rev":len(self.G[edge.y])})
            self.G[edge.y].append({"x":edge.y,"y":edge.x,"cap":0,"rev":len(self.G[edge.x])-1})
    def dfs(self,v,t,f=inf):
        if v==t:return f
        self.used[v]=True
        for a in range(len(self.G[v])):
            x=self.G[v][a]["x"]
            y=self.G[v][a]["y"]
            cap=self.G[v][a]["cap"]
            rev=self.G[y][self.G[x][a]["rev"]]
            if self.used[y] or cap==0:continue
            f2=self.dfs(y,t,min(f,cap))
            if f2>0:
                self.G[v][a]["cap"]-=f2
                rev["cap"]+=f2
                return f2
        return 0
    def maxflow(self):
        flow=0
        while True:
            self.used=[False]*V
            zouka=self.dfs(self.s,self.t)
            if zouka==0:break
            flow+=zouka
        return flow
def heron(a,b,c):
    s=(a+b+c)/2
    S=s(s-a)(s-b)(a-c)
    S=math.sqrt(S)
    return S
def getAreaOfTriangle(x1,y1,x2,y2,x3,y3):
    a=geted(x1,y1,x2,y2)
    b=geted(x2,y2,x3,y3)
    c=geted(x3,y3,x1,y1)
    return heron(a,b,c)








X,N=inputintlist()
P=inputintlist()
nums=set(list(range(-100,200)))
minabs=inf
minnum=inf
for p in P:
    nums.remove(p)
for a in nums:
    if abs(a-X)<minabs:
        minabs=abs(a-X)
        minnum=a
    elif abs(a-X)==minabs:
        if minnum>a:
            minnum=a
print(minnum)

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

d_min = 300
i_ans = 300
for i in range(100+1,-100-1,-1):
    if i not in p:
        if abs(x-i) <= d_min:
            d_min = min(d_min,abs(x-i))
            i_ans = i

print(i_ans)

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians

from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))

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


def main():
    X, N = MAP()

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

    P = LIST()

    for i in range(100):
        if not X - i in P:
            print(X - i)
            sys.exit()
        elif not X + i in P:
            print(X + i)
            sys.exit()


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(102):
    if i in p:
        continue
    else:
        if abs(x - i) < m:
            ans = i
            m = abs(x - i)
print(ans)

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

for i in range(100):
    if X-i not in p:
        print(X-i)
        break
    if X+i not in p:
        print(X+i)
        break

Solution (Python):
x,n = [int(j) for j in input().split()]
l = set([int(j) for j in input().split()])
ans1 = x+n
for i in range(x, x+n):
    if i not in l:
        ans1 = i
        break
for i in range(x, -1, -1):
    if i not in l:
        ans2 = i
        break
if abs(ans1-x)<abs(ans2-x):
    print(ans1)
else:
    print(ans2)

Solution (Python):
from collections import Counter
def main():
    X,N = map(int, input().split())
    p = list(map(int, input().split()))
    counter = Counter(p)
    gap = 0
    while 1:
        if counter.get(X-gap,0)==0:
            print(X-gap)
            return
        elif counter.get(X+gap,0)==0:
            print(X+gap)
            return
        else:
            gap+=1


main()

Solution (Python):

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

P = set((map(int, input().split(' '))))

ans, min_diff = None, float('inf')
for n in range(102):
    if n in P:
        continue

    diff = abs(X - n)
    if diff < min_diff:
        min_diff = diff
        ans = n

print(ans)

Solution (Python):
import sys

if __name__ == "__main__":
    X, N = [int(x) for x in input().split(" ")]
    if N == 0:
        print(X)
        sys.exit(0)
    P = set([int(x) for x in input().split(" ")])
    for diff in range(10 ** 3):
        if (X - diff) not in P:
            print(X - diff)
            sys.exit(0)
        if (X + diff) not in P:
            print(X + diff)
            sys.exit(0)

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

if x not in p:
  print(x)
  exit()
l = x - 1
r = x + 1

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