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

from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def solve():
    X, N = map(int, input().split())
    if N == 0:
        P  =[]
    else:
        P = list(map(int, input().split()))

    b = [0] * 1000
    for p in P:
        b[p] = 1

    ans = 0
    for i in range(len(b)):
        if b[i] == 0:
            if abs(X - i) < abs(X - ans):
                ans = i
    print(ans)


def main():
    solve()


if __name__ == '__main__':
    main()

Solution (Python):
import sys
x, n = map(int, input().split())
p = list(map(int, input().split()))
if not p or x not in p:
  print(x)
  sys.exit()
dp = [i-x for i in p]
dp_dic = {}
for i in range(len(p)):
  if abs(dp[i]) in dp_dic:
    dp_dic[abs(dp[i])].append(p[i])
  else:
    dp_dic[abs(dp[i])] = [p[i]]
i = 1
while True:
  if i in dp_dic and len(dp_dic[i]) == 1:
    if x + i == dp_dic[i][0]:
      print(x - i)
    else:
      print(x + i)
    break
  elif i not in dp_dic:
    print(x - i)
    break
  i += 1

Solution (Python):

def solve():
    x,n=map(int,input().split())
    p=set(map(int,input().split()))
    d=100
    for i in range(0,102) :
        if abs(i-x)<d and not (i in p) :
            d=abs(i-x)
            ans=i
    return ans

print(solve())

Solution (Python):
x, n = map(int, input().split())
a = set(map(int, input().split()))
print(min([i for i in range(102) if i not in a], key=lambda y:abs(x-y)))

Solution (Python):
import sys

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

if(N == 0):
    print(X)
    sys.exit()
    
min = 0
plu = 0
ans = 200
a = [1] * 102 

for i in range(N):
    a[p[i]] = 0

if(a[X] == 1):
    ans = X
    print(ans)
    sys.exit()


for k in range(100):
    min = X - (k+1)
    plu = X + (k+1)

    if(a[plu] == 1):
        ans = plu
    if(a[min] == 1):
        ans = min
    
    if(ans < 200):
        break

print(ans)

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

a = set()
for i in range(-100, 201):
    a.add(i)
for v in p:
    a.remove(v)
a = list(a)
b = list(map(lambda v: abs(v - x), a))
print(a[b.index(min(b))])

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

a = set()
for i in range(-100, 201):
    a.add(i)
for v in p:
    a.remove(v)
a = list(a)
b = list(map(lambda v: abs(v - x), a))
print(a[b.index(min(b))])

Solution (Python):
from sys import stdin
import sys

x,n = [int(x) for x in stdin.readline().rstrip().split()]
p = [int(x) for x in stdin.readline().rstrip().split()]

for i in range(10**4):
    x1 = x-i
    x2 = x+i

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

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

Solution (Python):
import math
import sys
readline = sys.stdin.readline


def main():
    x, n = map(int, readline().rstrip().split())
    p = list(map(int, readline().rstrip().split()))
    for k in range(100):
        if p.count(x - k) == 0:
            print(x - k)
            break
        if p.count(x + k) == 0:
            print(x + k)
            break


if __name__ == '__main__':
    main()

Solution (Python):
import sys



def check_number(p,numbers):
  for plis in p:
    if plis == numbers:
      return 1
  return 0


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

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


after_ans = X
i = 100


for i in range(X,X+100,1):
  if check_number(p,i) == 0:
    after_ans = i
    after_abs = abs(X-i)
    break

for i in range(X,X-100,-1):
  if check_number(p,i) == 0:
    before_ans = i
    before_abs = abs(X-i)
    break

if abs(after_abs) == abs(before_abs):
  answer = before_ans
elif abs(after_abs) > abs(before_abs):
  answer = before_ans
else:
  answer = after_ans

print( answer )

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

d = 0
while True:
    if (x - d) not in P:
        print(x - d)
        exit()
    elif (x + d) not in P:
        print(x + d)
        exit()
    d += 1

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

Solution (Python):
T = list(map(int, input().split()))
S = list(map(int, input().split()))

X = T[0]
N = T[1]

cntup = X
cntdown = X
if N == 0:
    print(X)
    
else:
    for i in range(1,100):
        if cntup in S and cntdown in S:
            cntup += 1
            cntdown -=1
        elif cntup not in S and cntdown not in S:
            print(min(cntup,cntdown))
            break
        elif cntup in S and cntdown not in S:
            print(cntdown)
            break
        elif cntup not in S and cntdown in S:
            print(cntup)
            break

Solution (Python):


n,m=map(int,input().split())
a=list(map(int,input().split()))
if len(a)==0:
  print(n)
else:
  a.sort()
  if n not in a:
    print(n)
  else:
    cnt=0
    for i in range(102):
      if i in a:
        continue
      elif abs(cnt-n)>abs(i-n):
        cnt=i
    print(cnt)

Solution (Python):
if __name__ == "__main__":
    X,N = list(map(int,input().split()))
    p = list(map(int,input().split()))
    if not X in p: 
        print(X)
    else:
        i = 1
        while True:
            if not (X - i) in p:
                print(X-i)
                break
            if not (X + i) in p:
                print(X+i)
                break
            i += 1

Solution (Python):
X,N=map(int,input().split())
p=[]
if N != 0:
  p=list(map(int,input().split()))
  p.sort()
i=0
while True:
  if X-i not in p:
    print(X-i)
    break
  elif X+i not in p:
    print(X+i)
    break
  i += 1

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

    p.sort()

    if len(p) == 0:
        print(x)
        return

    diff_min = 1000
    min_n = 1000
    for _ in range(0, 102):
        diff = abs(_ - x)
        if diff < diff_min:
            if _ not in p:
                diff_min = diff
                min_n = _

    print(min_n)


main()

Solution (Python):
m,n = map(int, input().split())
l=list(map(int, input().split()))
for i in range(101):
    if m-i not in l:
        print(m-i)
        break
    if m+i not in l:
        print(m+i)
        break

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

Solution (Python):
X, N=list(map(int,input().split()))
p=list(map(int,input().split()))
for i in range(N+1):
    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())
p=list(map(int,input().split()))
 
ans=0
for i in range(100):
  if X-i not in p:
    ans=X-i
    break
  elif X+i not in p:
    ans=X+i
    break
 
print(ans)

Solution (Python):
number=list(map(int,input().split()))
x,n=number[0],number[1]
tmp=[]
try:
    tmp=list(map(int,input().split()))
except:
    pass
answer=x
key_m=x
key_p=x
far_p,far_m=0,0
i,j=0,0
far_answer=0
while answer==x:
    key_p=x+i
    while key_p in tmp:
        i+=1
        key_p=x+i
    key_m=x-j
    while key_m in tmp:
        j+=1
        key_m=x-j
    far_m=int(x-key_m)
    far_p=int(key_p-x)
    if far_m==far_p:
        far_answer=far_m
    else:
        far_answer=min(far_p,far_m)

    if far_answer==far_m:
        answer=key_m
        break
    else:
        answer=key_p
print(answer)

Solution (Python):
x,n = map(int,input().split())
p = [int(i) for i in input().split()]
x_abs = 100000
ans = []
for i in range(-2,102):
    if i in p:
        continue
    if x_abs > abs(x-i):
        ans = i
        x_abs = abs(x-i)
    elif x_abs == abs(x-1):
        ans = min(ans, i)
print(ans)

Solution (Python):
x,n = map(int,input().split())
p = [int(i) for i in input().split()]
x_abs = 100000
ans = []
for i in range(-2,102):
    if i in p:
        continue
    if x_abs > abs(x-i):
        ans = i
        x_abs = abs(x-i)
    elif x_abs == abs(x-1):
        ans = min(ans, i)
print(ans)

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

if N == 0 :
  print(X)
  exit()
  
p = [int(j) for j in input().split()]
p.sort()

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

Solution (Python):
x,y = map(int,input().split())
list = list(map(int, input().split()))
check_x = x
while True:
    if check_x not in list:
        break
    check_x -= 1

check_x_high = x
while True:
    check_x_high += 1
    if check_x_high not in list:
        break

if check_x_high-x < x-check_x:
    print(check_x_high)
else:
    print(check_x)

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, N = map(int,input().split())
p_list = list(map(int,input().split()))

temp = -1
for i in range(102):
  if(temp == -1):
    if(i not in p_list):
      temp = abs(X - i)
      ans = i
  elif(temp > abs(X-i) and i not in p_list):
   temp = abs(X-i)
   ans = i

print(ans)

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

if n == 0:
    ans = x
else:
    ans = float('inf')

d = float('inf')

for i in range(n+2):
    tmpx = x + 1 + n//2 - i
    if not tmpx in p:
        tmpd = abs(x -tmpx) 
        if d >= tmpd:
            d = tmpd
            if ans >= tmpx:
                ans = tmpx

print(ans)

Solution (Python):
import sys
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7

X, N = LI()
P = LI()




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

elif (N != 0) and (X not in P):
    print(X)
    sys.exit()

Q = [q for q in range(-1, 102) if q not in P]  
ans = min(Q, key=lambda x: (abs(x - X), x))  

print(ans)

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

if N != 0:
    if X in p:
        sorted_p = sorted(p)

        x = sorted_p.index(X)
            
        def checknum(d,loweridx,upperidx):
            upper = sorted_p[upperidx]
            lower = sorted_p[loweridx]
            if X-d == lower:
                if X+d == upper:
                    if loweridx == 0:
                        print(X-d-1)
                    elif upperidx == N-1 and sorted_p[loweridx-1] == X-d-1:
                        print(X+d+1)
                    else:
                        checknum(d+1,loweridx-1,upperidx+1)
                else:
                    print(X+d)        
            else:
                return print(X-d)

        if x == 0:
            print(X-1)
        elif x == N-1:
            if sorted_p[x-1] != X-1:
                print(X-1)
            else:
                print(X+1)
        else:
            checknum(1,x-1,x+1)
    else:
        print(X)
else:
    print(X)

Solution (Python):
x,n = map(int,input().split())
l = list(map(int,input().split()))
s = set(l)
o = []
d = {}
for i in range(-1000,1000):
    if i not in s:
        g = abs(i-x)
        o.append(g)
        if g in d:
            h = d[g]
            h.append(i)
            d[g] = h

        else:
            d[g] = [i]

o.sort()
k = o[0]
n = d[k]
n.sort()
print(n[0])

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

distance = 1000
foundminimum = None
for i in range(102):
	if i in p:
		continue
	if distance > abs(x - i):
		distance = abs(x - i)
		foundminimum = i

print(foundminimum)

Solution (Python):
import sys
import numpy as np
from heapq import heappush, heappop 
from bisect import bisect_left as bi_l, bisect_right as bi_r
from collections import deque, Counter, defaultdict
from itertools import combinations, product
inf = float('inf')
MOD = 10**9+7



class ABC001():
  def A():
    h1, h2 = map(int, sys.stdin.read().split())
    print(h1-h2)

  def B(): pass
  def C(): pass 
  def D(): pass 


class ABC002():
  def A():
    x, y = map(int, sys.stdin.readline().split())
    print(max(x, y))

  def B():
    vowels = set('aeiou')
    s = sys.stdin.readline().rstrip() 
    t = ''
    for c in s:
      if c in vowels: continue 
      t += c 
    print(t)

  def C():
    *coords, = map(int, sys.stdin.readline().split())
    def triangle_area(x0, y0, x1, y1, x2, y2):
      x1 -= x0; x2 -= x0; y1 -= y0; y2 -= y0;
      return abs(x1*y2 - x2*y1) / 2
    print(triangle_area(*coords))

  def D():
    n, m = map(int, sys.stdin.readline().split())
    edges = set()
    for _ in range(m):
      x, y = map(int, sys.stdin.readline().split())
      x -= 1; y -= 1
      edges.add((x, y))
    cand = []
    for i in range(1, 1<<n):
      s = [j for j in range(n) if i>>j & 1]
      for x, y in combinations(s, 2):
        if (x, y) not in edges: break
      else:
        cand.append(len(s))
    print(max(cand))


class ABC003():
  def A():
    n = int(sys.stdin.readline().rstrip())
    print((n+1)*5000)

  def B():
    atcoder = set('atcoder')
    s, t = sys.stdin.read().split()
    for i in range(len(s)):
      if s[i] == t[i]: continue
      if s[i] == '@' and t[i] in atcoder: continue 
      if t[i] == '@' and s[i] in atcoder: continue
      print('You will lose')
      return 
    print('You can win')

  def C():
    n, k, *r = map(int, sys.stdin.read().split())
    res = 0
    for x in sorted(r)[-k:]:
      res = (res+x) / 2
    print(res)

  def D(): pass 


class ABC004():
  def A():
    print(int(sys.stdin.readline().rstrip())*2)

  def B():
    c = [sys.stdin.readline().rstrip() for _ in range(4)]
    for l in c[::-1]:
      print(l[::-1])

  def C():
    n = int(sys.stdin.readline().rstrip())
    n %= 30
    res = list(range(1, 7))
    for i in range(n):
      i %= 5
      res[i], res[i+1] = res[i+1], res[i]
    print(''.join(map(str, res)))

  def D(): pass 


class ABC005():
  def A():
    x, y = map(int, sys.stdin.readline().split())
    print(y//x)

  def B():
    n, *t = map(int, sys.stdin.read().split())
    print(min(t))

  def C():
    t = int(sys.stdin.readline().rstrip())
    n = int(sys.stdin.readline().rstrip())
    a = [int(x) for x in sys.stdin.readline().split()]
    m = int(sys.stdin.readline().rstrip())
    b = [int(x) for x in sys.stdin.readline().split()]
    i = 0
    for p in b:
      if i == n: print('no'); return 
      while p-a[i] > t:
        i += 1
        if i == n: print('no'); return 
      if a[i] > p: print('no'); return 
      i += 1
    print('yes')

  def D():
    n = int(sys.stdin.readline().rstrip())
    d = np.array([sys.stdin.readline().split() for _ in range(n)], np.int64)
    s = d.cumsum(axis=0).cumsum(axis=1)
    s = np.pad(s, 1)
    max_del = np.zeros((n+1, n+1), dtype=np.int64)
    for y in range(1, n+1):
      for x in range(1, n+1):
        max_del[y, x] = np.amax(s[y:n+1, x:n+1] - s[0:n-y+1, x:n+1] - s[y:n+1, 0:n-x+1] + s[0:n-y+1, 0:n-x+1])
    res = np.arange(n**2+1)[:, None]
    i = np.arange(1, n+1)
    res = max_del[i, np.minimum(res//i, n)].max(axis=1)
    q = int(sys.stdin.readline().rstrip())
    p = np.array(sys.stdin.read().split(), dtype=np.int64)
    print(*res[p], sep='\n')


class ABC006():
  def A():
    n = sys.stdin.readline().rstrip()
    if '3' in n: print('YES')
    elif int(n)%3 == 0: print('YES')
    else: print('NO')

  def B():
    mod = 10007
    t = [0, 0, 1]
    for _ in range(1001001):
      t.append(t[-1]+t[-2]+t[-3]); t[-1] %= mod
    n = int(sys.stdin.readline().rstrip())
    print(t[n-1])
    
  def C():
    n, m = map(int, sys.stdin.readline().split())
    cnt = [0, 0, 0]
    if m == 1: cnt = [-1, -1, -1]
    else:
      if m & 1: m -= 3; cnt[1] += 1; n -= 1
      cnt[2] = m//2 - n 
      cnt[0] = n - cnt[2]
    if cnt[0]<0 or cnt[1]<0 or cnt[2]<0: print(-1, -1, -1)
    else: print(*cnt, sep=' ')
      
  def D():
    n, *c = map(int, sys.stdin.read().split())
    inf = float('inf')
    lis = [inf]*n 
    for x in c: lis[bi_l(lis, x)] = x 
    print(n - bi_l(lis, inf))


class ABC007():
  def A():
    n = int(sys.stdin.readline().rstrip())
    print(n-1)

  def B():
    s = sys.stdin.readline().rstrip()
    if s == 'a': print(-1)
    else: print('a')

  def C():
    r, c = map(int, sys.stdin.readline().split())
    sy, sx = map(int, sys.stdin.readline().split())
    gy, gx = map(int, sys.stdin.readline().split())
    sy -= 1; sx -=1; gy -= 1; gx -= 1
    maze = [sys.stdin.readline().rstrip() for _ in range(r)]
    queue = deque([(sy, sx)])
    dist = np.full((r, c), np.inf); dist[sy, sx] = 0
    while queue:
      y, x = queue.popleft()
      for i, j in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
        i += y; j += x
        if maze[i][j] == '
        dist[i, j] = dist[y, x] + 1
        queue.append((i, j))
    print(int(dist[gy, gx]))
  
  def D(): pass 


class ABC008():
  def A():
    s, t = map(int, sys.stdin.readline().split())
    print(t-s+1)

  def B():
    n, *s = sys.stdin.read().split()
    res = defaultdict(int)
    for name in s: res[name] += 1
    print(sorted(res.items(), key=lambda x: x[1])[-1][0])

  def C():
    n, *a = map(int, sys.stdin.read().split())
    a = np.array(a)
    c = n - np.count_nonzero(a[:, None]%a, axis=1)
    print(np.sum((c+1)//2/c))
  
  def D(): pass

class ABC009():
  def A():
    n = int(sys.stdin.readline().rstrip())
    print((n+1)//2)

  def B():
    n, *a = map(int, sys.stdin.read().split())
    print(sorted(set(a))[-2])
    
  def C():
    n, k = map(int, sys.stdin.readline().split())
    s = list(sys.stdin.readline().rstrip())
    cost = [1]*n
    r = k
    for i in range(n-1):
      q = []
      for j in range(i+1, n):
        if s[j] < s[i] and cost[i]+cost[j] <= r:
          heappush(q, (s[j], cost[i]+cost[j], -j))
      if not q: continue
      _, c, j = heappop(q); j = -j 
      s[i], s[j] = s[j], s[i]
      r -= c 
      cost[i] = cost[j] = 0
    print(''.join(s))
      
  def D(): pass 


class ABC010():
  def A():
    print(sys.stdin.readline().rstrip()+'pp')
  def B():
    n, *a = map(int, sys.stdin.read().split())
    tot = 0
    for x in a:
      c = 0 
      while x%2==0 or x%3==2:
        x -= 1
        c += 1
      tot += c
    print(tot)

  def C():
    sx, sy, gx, gy, t, v, n, *xy = map(int, sys.stdin.read().split())
    x, y = np.array(xy).reshape(-1, 2).T
    def dist(x1, y1, x2, y2):
      return np.sqrt((x2-x1)**2 + (y2-y1)**2)
    ans = 'YES' if (dist(sx, sy, x, y)+dist(x, y, gx, gy) <= v*t).any() else 'NO'
    print(ans)

  def D(): pass 

class ABC011():
  def A():
    n = int(sys.stdin.readline().rstrip())
    print(n%12+1)

  def B():
    s = sys.stdin.readline().rstrip() 
    print(s[0].upper()+s[1:].lower())

  def C():
    n, *ng = map(int, sys.stdin.read().split())
    ng = set(ng)
    if n in ng: print('NO')
    else:
      r = 100
      while n > 0:
        if r == 0: print('NO'); return
        for i in range(3, 0, -1):
          if (n-i) in ng: continue 
          n -= i
          r -= 1
          break 
        else: print('NO'); return 
      print('YES')

  def D(): pass 


class ABC170():
  def A():
    x = [int(x) for x in sys.stdin.readline().split()]
    for i in range(5):
      if x[i] != i+1:
        print(i+1)
        break

  def B():
    x, y = map(int, sys.stdin.readline().split())
    print('Yes' if 2*x <= y <= 4*x and y%2 == 0 else 'No')
      
  def C():
    x, n, *p = map(int, sys.stdin.read().split())
    a = list(set(range(102)) - set(p))
    a = [(abs(y-x), y) for y in a]
    print(sorted(a)[0][1])
    
  def D(): pass 
  def E(): pass 
  def F(): pass 

if __name__ == '__main__':
  ABC170.C()

Solution (Python):
import collections
x, n= map(int, input().split())
P = list(map(int, input().split()))
 
PX = list(map(lambda p: p-x,P))
CPX = collections.Counter(PX)
ans = 0

for i in range(100):
  if CPX[-i] == 0:
    ans = x -i
    break
  elif CPX[i] == 0:
    ans = x +i
    break

print(ans)

Solution (Python):
from bisect import bisect_left
x, n = map(int, input().split())
if n != 0:
    P = list(map(int, input().split()))
    P = sorted(P)
else:
    P = []

flag = False
ans = []
if x not in P or n == 0:
    ans.append(x)
else:
    idx = bisect_left(P, x)
    for i in range(1, 110):
        for_num = P[idx] + i
        bac_num = P[idx] - i
        if for_num not in P:
            ans.append(for_num)
            flag = True
        if bac_num not in P:
            ans.append(bac_num)
            flag = True
        if flag:
            break

print(min(ans))

Solution (Python):
x, n = map(int, input().split())
if (n == 0):
    print(x)
    exit()
p = list(map(int, input().split()))
pp = list(set(sorted([i - x for i in p if i-x > 0])))
pm = list(set(sorted([abs(i - x) for i in p if i - x < 0])))
pp.append(9999)
pm.append(9999)
if ([1 for i in p if i == x]):
    pass
else:
    print(x)
    exit()
a = 1
i = 0
while 1:
    if (pm[i] != a):
        print(x - a)
        exit()
    if(pp[i] != a):
        print(x + a)
        exit()
    a += 1
    i += 1

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

def judge(X):
  if (X not in lis) and (X >= 0):
    print(X)
    exit(0)
    
for j in range(100):
  judge(x-i)
  judge(x+i)
  i+=1

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

d = float("inf")
ans = -1
for x in range(102):
    if x in P:
        continue
    if abs(x-X) < d:
        ans = x
        d = abs(x-X)

print(ans)

Solution (Python):
def solution():
    input1 = input()
    input2 = input()
    target, _ = [int(x) for x in input1.split()]
    num_list = set()
    for n in input2.split():
        num_list.add(int(n))
    diff = 0
    while True:
        candidate1 = target - diff
        candidate2 = target + diff
        if candidate1 not in num_list:
            print(candidate1)
            return
        if candidate2 not in num_list:
            print(candidate2)
            return
        diff += 1
    
solution()

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

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

k = 0
while(True):
    if not x-k in a:
        print(x-k)
        quit()
    if not x+k in a:
        print(x+k)
        quit()
    k += 1

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

if n != 0:
    ls = list(map(int, input().split(' ')))
    ls_remaind = []
    for i in range(1, 102):
        if i not in ls:
            ls_remaind.append(i)
    for j in ls_remaind:
        if abs(x-j) == diff:
            result = min(result, j)
        elif abs(x-j) < diff:
            diff = abs(x-j)
            result = j
else:
    result = x

print(result)

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

for i in range(x+1):
    for j in [-1,+1]:
        a = x + i * j
        if a not in p:
            print(a)
            exit()

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

i = 0
ans = []
flag = 0
while True:
    if (x + i) not in p:
        ans += [x+i]
        flag = 1
    if (x - i) not in p:
        ans += [x-i]
        flag = 1
    if flag == 0:
        i += 1
    else:
        break

print(min(ans))

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):
def c170(x, n, plist):

    if n == 1:
        if x - n not in plist:
            return x - n
        else:
            return x + n

    for i in range(n):
        if x-i not in plist:
            return x-i
        elif x+i not in plist:
            return x+i

def main():
    x, n = map(int, input().split())
    if n == 0:
        print(x)
        return
    plist = list(map(int, input().split()))
    print(c170(x, n, plist))

if __name__ == '__main__':
    main()

Solution (Python):

from collections import deque















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

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

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



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

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

p = set(p)
for i in range(200):
    if X - i not in p:
        print(X - i)
        break
    if X + i not in p:
        print(X + i)
        break

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

if n != 0:
    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
        else:
            i += 1
        
else:
    print(x)

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

ans_i = 0
for i in range(N+1):
    if X-i not in p or X+i not in p:
        ans_i = i
        break

if X-ans_i not in p:
    print(X-ans_i)
elif X+i not in p:
    print(X+ans_i)

Solution (Python):
x,n = map(int,input().split())
if n == 0:
  print(x)
else:
  ps= set(map(int,input().split()))
  diff = 0
  while(True):
    if x-diff not in ps:
      print(x -diff)
      break
    elif x + diff not in ps:
      print(x + diff)
      break
    diff +=1

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

nn = input().split()
nums = list(map(int, nn))




pos = X
neg = X
result = X

while True:
    if (len(nums) <= 0):
        break
    if (not neg in nums):
        result = neg
        break
    if (not pos in nums):
        result = pos
        break
    neg -= 1
    pos += 1
print(result)

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

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

p = [int(x) for x in input().split()]

for i in range(150):
    if x-i not in p:
        print(x-i)
        exit()
    elif x+i not in p:
        print(x+i)
        exit()

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

Solution (Python):
import sys
X,N=map(int,input().split())
if N==0:
  print(X)
  sys.exit()
else:
  P=list(map(int,input().split()))
L=[]
A=[]
A_1=[]
for i in range(-100,200):
  L.append(i)
for i in P:
  L[i+100]=200
for i in L:
  A.append(abs(X-i))
A_1=sorted(A)
a=A_1[0]
for i in L:
  if i==X-a:
    print(i)
    sys.exit()
  elif i==X+a:
    print(X+a)
    break

Solution (Python):
x,n=map(int,input().split())
P=list(map(int,input().split()))
Q=[-1,0]
for i in range(1,102):
    if i not in P:
        Q.append(i)

ans=10**9
A=[]
for i,q in enumerate(Q):
    A.append([i,abs(q-x)])
A.sort(key=lambda x:(x[1],x[0]))
print(Q[A[0][0]])

Solution (Python):
X,N = map(int,input().split())
p = list(map(int,input().split()))
p.sort()
diff = 100000
ans = 0
for i in range(-200, 200):
  if i not in p:
    if abs(X-i) < diff:
      diff = abs(X-i)
      ans = i
print(ans)

Solution (Python):
n,k = map(int,input().split())
a = list(map(int,input().split()))
for i in range(n+1):
	for x in [-1,+1]:
		y = n + x*i
		if y not in a:
			print(y)
			exit(0)

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,n = map(int,input().split())
p = list(map(int,input().split()))
cnt = 0
while(1):
    key = x + (-1)**cnt*((cnt+1)//2)
    if key not in p:
        print(key)
        break
    cnt += 1

Solution (Python):
x,n = map(int,input().split())
li = []
if n != 0:
  li = list(map(int,input().split()))
answer = 0
for i in range(0, 102):
  if (i in li):
    continue
  if abs(i-x) < abs(answer - x):
    answer = i
print(answer)

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

ls = [0] * 201
for i in range(0, 201):
    ls[i] = i

ls_in = [0] * n
if n > 0:
    ls_in = list(map(int, input().split(' ')))
    for i in ls_in:
        ls.remove(i)
    ls.reverse()
    for i in ls:
        min_num = min(abs(x-i), min_num)
        if abs(x-i) == min_num:
            ans = i 
    print(ans)
else:
    print(x)

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

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