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):
import numpy as np

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

all_num = list(range(0, 102, 1))
lists = [i for i in all_num if i not in num_lists]

lists_arr = np.array(lists)
diff_arr = lists_arr - x
abs_arr = np.abs(diff_arr)
index = np.where(abs_arr == abs_arr.min())
answer_list = lists_arr[index]
print(answer_list[0])

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


for i in range(101):
    if i == 0:
        if x not in p:
            print(x)
            exit()
        continue
    if (x - i) not in p:
        print(x-i)
        exit()
    elif (x + i) not in p:
        print(x+i)
        exit()

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

for d in range(X+1):
    for f in [-1,1]:
        a = X + d*f
        if p.count(a) == 0:
            print(a)
            exit()

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

abs_min = 101
for i in range(0, 102):
    if i in p:
        continue
    tmp = abs(i - x)
    if abs(i - x) < abs_min:
        ans = i
        abs_min = tmp
print(ans)

Solution (Python):
import sys
x, n = list(map(int,input().split()))
if n>0:
    p = list(map(int,input().split()))
else:
    print(x)
    sys.exit()
p.sort()
xmin = x
while True:
    if xmin in p:
        xmin -= 1
    else:
        break
xmax = x
while True:
    if xmax in p:
        xmax += 1
    else:
        break

print(xmin if abs(x-xmin)<=abs(x-xmax) else xmax)

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







for i in range(0,X+1):
    for s in [-1,1]:
        ans = X + (i * s)
        if P.count(ans) == 0:
            print(ans)
            exit(0)

Solution (Python):
X, N = map(int, input().split())
P = list(map(int, input().split()))
ans = 1000
ans_abs = 10000
for i in reversed(range(0, 102)):
    inP = False
    for p in P:
        if p == i:
            inP = True
            break
    if not inP:
        i_abs = abs(i - X)
        if ans_abs >= i_abs:
            ans = i
            ans_abs = i_abs

print(ans)

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

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

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

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

Solution (Python):
x,n = list(map(int,input().split()))
ans = 0
if n != 0:
  p_list = list(map(int,input().split()))
  for i in range(0,102):
    if i not in p_list:
      if abs(x - i) < abs(x - ans):
        ans = i
      elif abs(x - i) == abs(x - ans) and i < ans:
        ans = i
else:
  ans = x
print(ans)

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

x1 = x
x2 = x

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

Solution (Python):



import numpy as np

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

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

m = np.array(list(range(-200,400)))
m = (m-x)**2
for i in (np.argsort(m)-200):
    if p.count(i) == 0:
        print(i)
        break

Solution (Python):
import numpy as np
X, N = map(int, input().split())
if N == 0:
    print(X)
else:
    p = sorted(list(map(int, input().split())))
    ok = [i for i in range(-101, 201) if i not in p]
    ix = np.argmin(list(map(lambda a: abs(X-a), ok)))
    print(ok[ix])

Solution (Python):
X,N = map(int, input().split())
if N > 0: 
    P = list(map(int,input().split()))
    direction = -1
    i = 1
    if not X in P:
        print(X)
    else:
        while True:
            dist = i * direction
            val = dist+X
            if not (val in P):
                print(val)
                break
            if direction < 0: direction = 1
            else : 
                direction = -1
                i+=1
else: 
    print(X)

Solution (Python):
import numpy as np
def getNearestValue(Q, num):
    idx = np.abs(np.asarray(Q) - num).argmin()
    return Q[idx]

XN = list(map(int,input().split()))
X = XN[0]
N = XN[1]
if N == 0:
    print(X)
else:
    P = list(map(int,input().split()))
    Q = list(range(-100,200,1))
    for i in range(0,N):
        Q.remove(P[i])
    print(getNearestValue(Q,X))

Solution (Python):
x,n=map(int,input().split())
if n!=0:
  p=list(map(int,input().split()))
else:
  p=[]
ans=0
if x in p:
  low=x
  high=x
  while True:
    low-=1
    high+=1
    if low in p:
      if high in p:
        continue
      else:
        ans=high
        break
    else:
      ans=low
      break
  print(ans)
else:
  print(x)

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

abs_diff = 1000
p = set(p)
for i in range(102):
    if not i in p:
        if abs(X-i)<abs_diff:
            ans = i
            abs_diff = abs(X-i)

print(ans)

Solution (Python):
x,n=map(int,input().split())
if n==0:
    print(x)
    exit()
p=list(map(int,input().split()))
l=list(range(0,102))
for i in p:
    l.remove(i)
ans=100
min_num=1000
for i in range(len(l)):
    if abs(l[i]-x)<min_num:
        min_num=abs(l[i]-x)
        ans=l[i]
print(ans)

Solution (Python):
x,n=map(int,input().split())
if n==0:
  print(x)
  exit()
p=list(map(int,input().split()))
a=[]
ans=100000
suu=100000

for i in range(-10,120):
  a.append(i)
for i in range(n):
  a.remove(p[i])
  
for i in range(len(a)):
  sa=abs(x-a[i])
  if sa<suu:
      suu=sa
      ans=a[i]
      
print(ans)

Solution (Python):
x, n = list(map(int, input().split()))
p = list(map(int, input().split()))
pN = [i for i in range(102) if i not in p]
pm = [abs(i - x) for i in pN]
print(pN[pm.index(min(pm))])

Solution (Python):
x, n = list(map(int, input().split()))
p = list(map(int, input().split()))
pN = [i for i in range(102) if i not in p]
pNm = [abs(i - x) for i in pN]
pmin = min(pNm)
print(pN[pNm.index(pmin)])

Solution (Python):
X, N = map(int, input().split())
P = list(map(int, input().split()))
ans, mind = -1, 200
for i in range(102):
    if mind > abs(i - X) and i not in P:
        mind = abs(i - X)
        ans = i
print(ans)

Solution (Python):
X, N = map(int,input().split())
if N == 0:
    print(X)
    exit()
a = list(map(int,input().split()))
cnt = 0
while 1:
  b,c = X-cnt,X+cnt
  if b not in a:
    print(b)
    break
  elif c not in a:
    print(c)
    break
  else:
    cnt += 1

Solution (Python):

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

dis = 1000
for i in range(-100,102):
    if i not in p_list:
        sub = abs(x-i)
        dis = min(dis,sub)
            
if x-dis in p_list:
    print(x+dis)
else:
    print(x-dis)

Solution (Python):
N,M = map(int,input().split())
if M == 0:
  print(N)
else:
  c=list(map(int, input().split()))
  for i in range(N+1):
    for s in [-1,1]:
      a = N+s*i
      if c.count(a)==0:
      	print(a)
      	exit(0)

Solution (Python):
x, n = map(int,input().split())
p = list(map(int,input().split()))
y = 0
z = 0
while y == 0:
    a = x + z
    b = x - z
    if a in p and b in p:
        z += 1
    elif a not in p and b in p:
        print(a)
        y = 4
    elif b not in p:
        print(b)
        y = 5

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

Solution (Python):
x, n = map(int, input().split())
p = list(map(int, input().split()))
arr = [-1, 1]
for i in range(x+1):
    for pm in arr:
        cnt = x + i * pm
        if p.count(cnt) == 0:
            print(cnt)
            exit(0)

Solution (Python):
from math import floor,ceil,sqrt,factorial,log
from collections import Counter, deque
from functools import reduce
import numpy as np
def S(): return input()
def I(): return int(input())
def MS(): return map(str,input().split())
def MI(): return map(int,input().split())
def FLI(): return [int(i) for i in input().split()]
def LS(): return list(MS())
def LI(): return list(MI())
def LLS(): return [list(map(str, l.split() )) for l in input()]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def LLSN(n: int): return [LS() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]

X,N = MI()

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

P = LI()

_min = 10**9
ans = []
for p in range(X+1):
    for i in [-1,1]:
        a = X + (i * p)
        if a not in P:
            print(a)
            exit()

Solution (Python):


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

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

ans = 300
for i in range(-200,200):
    
    if i not in p:
        
        if abs(ans-X) > abs(X-i):
            ans = i
        elif abs(ans-X) == abs(X-i):
            ans
print(ans)

Solution (Python):
X, N = map(int, input().split())
if N == 0:
    print(X)
else:
    A = list(map(int, input().split()))
    P = list(set(range(-100, +200)) - set(A))
    P = sorted(P)
    print(min(P, key=lambda p: abs(p - X)))

Solution (Python):
def solve(string):
    x, _, *p = map(int, string.split())
    for i in range(101):
        if x - i not in p:
            return str(x - i)
        if x + i not in p:
            return str(x + i)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Solution (Python):
x, n = map(int, input().split())
if n == 0:
    print(x)
else:
    p_l = list(map(int, input().split()))
    p_x_l = [ x-i for i in p_l ]
    for i in range(101):
        if i not in p_x_l:
            print(x-i)
            break
        if -i not in p_x_l:
            print(x+i)
            break

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

ret = 0
i = 0
if n==0:
    ret = x
else:
    ret=x
    if( ret in l):
        while True:
            i+=1
            ret = x-i
            if( not ret in l):
                break
            ret = x+i
            if( not ret in l):
                break
print(ret)

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

dif =102

for i in range(102):
  if i in p:
    continue
  else:
    now = abs(X-i)
    if dif > now:
      dif = now
      ans =i

print(ans)

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

ans = -200
for i in range(-100, 200):
    if p.count(i):
        continue
    if(abs(i - X) < abs(ans - X)):
        ans = i
print(ans)

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

li = sorted(map(int, input().split()))
i = 0
while True:
    if X - i not in li:
        print(X - i)
        exit()

    if X + i not in li:
        print(X + i)
        exit()

    i += 1

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
input=sys.stdin.readline

def main():
  x, n = map(int, input().split(' '))
  if(n):
    p = list(map(int, input().split(' ')))
  else:
    p = []
    input()
  i = 0
  while(True):
    if not x-i in p:
      ans = x-i
      break
    elif not x+i in p:
      ans = x+i
      break
    else:
      i +=1
  print(ans)
  

if __name__=='__main__':
  main()

Solution (Python):
import sys

x,n = map(int,input().split())
if n != 0 :
  p = list(map(int,input().split()))
else :
  print(x)
  sys.exit()
    
for i in range(200) :
  ans1 = x-i
  ans2 = x+i
  if not ans1 in p :
    ans = ans1
    break
  if not ans2 in p :
    ans = ans2
    break
    
print(ans)

Solution (Python):
import numpy as np
X,N=map(int,input().split())
p=np.array(list(map(int,input().split())))
ans=np.array([X,X])
while True:
  for x in ans:
    if x not in p:
      print(x)
      exit()
  ans+=[-1,1]

Solution (Python):
import numpy as np
X,N=map(int,input().split())
p=np.array(list(map(int,input().split())))
ans=np.array([X,X])
while True:
  if ans[0] not in p:
    print(ans[0])
    exit()
  if ans[1] not in p:
    print(ans[1])
    exit()
  ans+=[-1,1]

Solution (Python):
import itertools
import math
import fractions
import functools
import copy
from collections import deque
from functools import reduce
from decimal import Decimal


def main():
    x, n = map(int, input().split())
    p = list(map(int, input().split()))
    cand = []
    for i in range(102):
        cand.append(i)
    for i in range(len(cand)):
        for j in range(n):
            if cand[i] == p[j]:
                cand[i] = 100000
    mini = 100
    for i, c in enumerate(cand):
        if mini > abs(c-x):
            ans = i
            mini = abs(c-x)

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
from sys import stdin, stdout
read = stdin.readline
write = stdout.write
flush = stdout.flush
xr = xrange

def main():
	x,n = map(int,read().split())
	a = list(map(int,read().split()))
	if x not in a:
		ans = x
	else:
		for i in xr(1,100):
			if x - i not in a:
				ans = x - i
				break
			elif x + i not in a:
				ans = x + i
				break
	print ans

if __name__ == "__main__":
	main()

Solution (Python):
x,n = map(int,input().split())
if n == 0:
    print(x)
else:
    mp = set(range(-1,102))
    p = set(list(map(int,input().split())))
    lp = list(mp-p)
    sub_lp = [abs(i-x) for i in lp]
    print(lp[sub_lp.index(min(sub_lp))])

Solution (Python):
x, n = map(int, input().split())
q = list(map(int, input().split()))
p = []
for i in range(102):
    if not i in q:
        p.append(i)
l = []
for i in p:
    l.append(abs(i - x))
print(p[l.index(min(l))])

Solution (Python):
def main():
    X, N = map(int, input().split())
    if N == 0:
        print(X)
        exit()
    P = set(map(int, input().split()))
    min = 1000
    ans = None
    for v in range(-100, 201):
        if v in P:
            continue
        if abs(v - X) < min:
            min = abs(v - X)
            ans = v
    print(ans)


if __name__ == '__main__':
    main()

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

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 = 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 = map(int,input().split())
A = set(i for i in range(102))
P = set(map(int,input().split()))
B=A-P

min_ = float('inf')
ans = X
for b in B:
    if abs(X-b) < min_:
        min_ = abs(X-b)
        ans = b

print(ans)

Solution (Python):

def q3():
    x, N = [int(i) for i in input().split(" ")]
    if N != 0:
        P = set([int(i) for i in input().split(" ")])
    else:
        P = set()

    if x not in P:
        print(x)
        return

    xm = x
    xp = x

    while True:
        xm = xm - 1
        if xm not in P:
            print(xm)
            return
        xp = xp + 1
        if xp not in P:
            print(xp)
            return


q3()

Solution (Python):

def q3():
    x, N = [int(i) for i in input().split(" ")]
    if N != 0:
        P = [int(i) for i in input().split(" ")]
    else:
        P = []

    if x not in P:
        print(x)
        return

    xm = x
    xp = x

    while True:
        xm = xm - 1
        if xm not in P:
            print(xm)
            return
        xp = xp + 1
        if xp not in P:
            print(xp)
            return


q3()

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

Solution (Python):
def main():

    import numpy as np

    X, N = map(int, input().split())
    p = np.array([int(x) for x in input().split()])
    
    p_sorted = np.sort(p)
    p_X_index = np.argsort(abs(p_sorted - X))
    p_sorted = p_sorted[p_X_index]

    i = 0
    while True :
        if np.count_nonzero(p_sorted == X - i) == 0:
            print(X - i)
            break
        elif np.count_nonzero(p_sorted == X + i) == 0:
            print(X + i)
            break
        i += 1

if __name__ == '__main__':
    main()

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

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

temp = [0] * n

for i in range(n):
    temp[i] = a[i] - x

temp.sort()

abs = 0
ans = 0

while (True):
    if temp.count(abs*-1) == 0:
        ans = x - abs
        break
    elif temp.count(abs) == 0:
        ans = x + abs
        break
    else:
        abs += 1
    


print(ans)

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

ans = ''
i = 0
while ans == '':
  if x-i not in li:
    ans = x-i
  elif x+i not in li:
    ans = x+i
  else:
    i += 1
print(ans)

Solution (Python):
from bisect import bisect_left
x,n = (map(int,input().split()))
if n == 0:
    p = input()
    print(x)
else:
    p = sorted(list(map(int,input().split())))
    zn,zp = x,x
    zn_point,zp_point = bisect_left(p,x),bisect_left(p,x)
    while zn_point>=0 and zn==p[zn_point]:
        zn-=1
        zn_point -=1 
    while zp_point<len(p) and zp==p[zp_point]:
        zp+=1
        zp_point +=1 
    if abs(zn-x)<=abs(zp-x):
        print(zn)
    else:
        print(zp)

Solution (Python):
x, n = map(int, input().split())
p = list(map(int, input().split()))
ans = 1000
jugh = 1000
for i in range(0, 150):
    if abs(x-i) < jugh and i not in p:
        jugh = abs(x-i)
        ans = i
    
print(ans)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random,resource

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    x,n = LI()
    p = LI()
    s = set(p)

    for i in range(101):
        if x - i not in s:
            return x - i
        if x + i not in s:
            return x + i

    return -1


print(main())

Solution (Python):
import math

if __name__ == "__main__":
    x, n = map(int, input().split())
    a = set(map(int, input().split()))
    p = q = x
    while True:
        if p not in a and q not in a:
            print(min(p, q))
            quit(0)
        if p not in a:
            print(p)
            quit(0)
        elif q not in a:
            print(q)
            quit(0)
        else:
            p -= 1
            q += 1

Solution (Python):
a=input("").split(" ")
x=int(a[0])
n=int(a[1])
if(n!=0):
    p=input("").split(" ")
    listp=[]
    c=0
    for i in range(n):
        listp+=[int(p[i])]
    for i in range(100):
        if not(x-i in listp):
            c=x-i
            break
        elif(not (x+i in listp)):
            c=x+i
            break
else:
    c=x


print(c)

Solution (Python):
def main():
    
    
    
    x, n = (int(i) for i in input().split())
    if n > 0:
        p = set(int(i) for i in input().split())
    else:
        p = set() 

    b, e = x, x
    while b in p and e in p:
        b -= 1
        e += 1

    if b not in p:
        print(b)
    else:
        print(e)


main()

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

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

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

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

counter = 0

for i in range(1, 101):
    if x in p:
        if counter == 0:
            x -= i
            counter = 1
        else:
            x += i
            counter = 0
    else:
        exit
print(x)

Solution (Python):
def pick(sol, a):
    count,s = 0, sol
    while (True):
        count += 1
        if s not in a:
            return s
        else:
            if count%2:
                s -= count
            else:
                s += count
def near(a, n):
    ans = set()
    for i in a:
        ans.add(max(i,n))
        if i == n:
            break
        if len(ans)!=1:
            break
    else:
        if len(ans) == 1:
            if (ans[0]==n):
                i = a[0]
            elif ans[0]==a[-1]:
                i = a[-1]
    print(pick(i, a))

n ,k = map(int,input().split())
a = sorted(list(map(int,input().split())))
if k == 0:
    print(n)
else:
    near(a,n)

Solution (Python):

import numpy as np
x,n=map(int,input().split())
if n==0:
  print(x)
else:
  plist=list(map(int,input().split()))
  newplist=sorted(plist)

  p_list=[]
  for i in newplist:
    k=abs(i-x)
    p_list.append(k)

  ind=np.argmin(p_list)
  moto=newplist[ind]
  gap=0
  while True:
    gap+=1
    if (moto-gap) in newplist:
      pass
    else:
      print(moto-gap)
      break
    if (moto+gap) in newplist:
      pass
    else:
      print(moto+gap)
      break

Solution (Python):


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

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

Solution (Python):
inp = list(map(int,input().split()))
x=inp[0]
n=inp[1]
inp = list(map(int,input().split()))
from collections import Counter
c=Counter(inp)
if c[x]==0:
  print (x)
else:
  i=1
  while (1):
    if c[x-i]==0:
      print (x-i)
      break
    elif c[x+i]==0:
      print (x+i)
      break
    i+=1

Solution (Python):
x, n = map(int, input().split())
p = [int(x) for x in input().split()]
seen = set(p)
offset = 0
while True:
    val1, val2 = x + offset, x - offset
    if val2 not in seen:
        print(val2)
        break
    if val1 not in seen:
        print(val1)
        break
    offset += 1

Solution (Python):
x,n=map(int,input().split())
p=set(list(map(int,input().split())))
ans=0
flag=0
while flag==0:
    if not x-ans in p:
        print(x-ans)
        flag=1
    elif not x+ans in p:
        print(x+ans)
        flag=1
    ans+=1

Solution (Python):
import math

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

ans = -1
dif = 10000
for i in range(102):
  if i in p: 
    continue
  else:
    if abs(x - i) < dif:
      ans = i
      dif = abs(x - i)

print(ans)

Solution (Python):
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

x,n=nii()
p=lnii()

dist=1000
for i in range(101,-1,-1):
  if i in p:
    continue

  t_dist=abs(x-i)
  if t_dist<=dist:
    dist=t_dist
    ans=i

print(ans)

Solution (Python):

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


def input_array():
	return list(map(int,input().split()))
  
x,n=input2()
p=sorted(input_array())
q=[0]*102
result=[10000,-1]
for i in range(n):
	q[p[i]]=1
for i in range(102):
	if q[i]==0:
		num=abs(i-x)
		if num<result[0]:
			result=[num,i]
print(result[1])

Solution (Python):
x, n = map(int, input().split())
ps_x = {int(s)-x for s in input().split()}

if not ps_x:
    print(x)
else:
    for i in range(100):
        if -i not in ps_x:
            print(x-i)
            break
        elif i not in ps_x:
            print(x+i)
            break

Solution (Python):


x, N = map(int,input().split())
if N != 0:
    P = list(map(int,input().split()))
    L = [i for i in range(-1000, 1010)]

    l = list(set(P)^set(L))
    dis = 10**9
    
    for i in range(len(l)):
        dis_ = abs(x-l[i])
        if dis_ < dis:
            ans = l[i]
            dis = dis_
else:
    ans = x


print(ans)

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

  if x not in num:
    print(x)
  else:
    y = num.index(x)
    if y == (n-1):
      if num[y-1] == x-1:
        print(x+1)
      else:
        print(x-1)
    elif y == 0:
      print(x-1)
    else:
      for i in range(100):
        y = x-i
        if y not in num:
          under = y
          count_under = i
          break
      for j in range(100):
        y = x + j
        if y not in num:
          upper = y
          count_upper = j
          break
      
      if count_under <= count_upper:
        print(under)
      else:
        print(upper)

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

q = [i for i in Z if i not in p]
t = []

for i in range(0, len(q)):
    t.append(abs(int(X)-q[i]))

print(q[(t.index(min(t)))])

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

y = []
for i in range(102):
    if i not in p:
        y.append(i)

m = 102
ans = -1
for i in y:
    if abs(x-i) < m:
        m = abs(x-i)
        ans = i

print(ans)

Solution (Python):
import math

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

ans = -1
dif = 10000
for i in range(102):
    if i in p:
        continue
    else:
        if abs(x - i) < dif:
            ans = i
            dif = abs(x - 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()
    p2 = [i - x for i in p]
    for i in range(100):
        if not -i in p2:
            print(x - i)
            break
        if not i in p2:
            print(x + i)
            break

Solution (Python):
x,n = map(int,input().split())
if n==0:
    print(x)
else:
    p = list(map(int,input().split()))
    for i in range(101):
        if x-i==0:
            print(0)
            break
        if p.count(x-i)==0:
            print(x-i)
            break
        if x+i==101:
            print("101")
            break
        if p.count(x+i)==0:
            print(x+i)
            break

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

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 + j * i
        if p.count(a) == 0:
            print(a)
            exit(0)

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

    best_num = 0
    best_diff = 999
    for i in range(102):
        if i not in p and abs(x - i) < best_diff:
            best_num = i
            best_diff = abs(x - i)

    print(best_num)

if __name__ == '__main__':
    main()

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

m=float('inf')
l=[]
       
for i in range(-100,N+101):
    if i not in p:
        l.append(i)
    else:
        continue

for j in l:
    m=min(m,abs(X-j))
    
if (X-m) not in p:
    print(X-m)
else:
    print(X+m)

Solution (Python):
import sys

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

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

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

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

for i in range(51):
    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())
S=map(int, input().split())
K=(list(range(0,102)))
for i in S:
    K.remove(i)
L=[]
for i in K:
    L.append(abs(x-i))
m=min(L)
ind_m=L.index(m)
print(K[ind_m])

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

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

upper_ans = 0

for i in range(x, 102):
    if not (i in ps):
        upper_ans = i
        break

lower_ans = 0

for j in reversed(range(0, x + 1)):
    if not (j in ps):
        lower_ans = j
        break

if (upper_ans == 0) and (lower_ans == 0):
    ans = 0
elif abs(x - upper_ans) < abs(x - lower_ans):
    ans = upper_ans
elif abs(x - upper_ans) > abs(x - lower_ans):
    ans = lower_ans
else:
    ans = min(upper_ans, lower_ans)

print(ans)

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

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

for i in range(51):
    if (x+i not in p) and (x-i not in p):
        print(x-i)
        exit()
    if (x+i in p) and (x-i not in p):
        print(x-i)
        exit()
    if (x+i not in p) and (x-i in p):
        print(x+i)
        exit()