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.



Sample input:
6 5
4 7 10 6 5


Sample output:
8

Submission status: Accepted

Solution code:
import math
import time
from collections import defaultdict, deque
from sys import stdin, stdout
from bisect import bisect_left, bisect_right
x,n=map(int,stdin.readline().split())
a=set(map(int,stdin.readline().split()))
if(x not in a):
    print(x)
else:
    diff=1
    while(True):
        if(x-diff not in a):
            print(x-diff)
            break
        elif(x+diff not in a):
            print(x+diff)
            break
        diff+=1

Submission status: Accepted

Solution code:
X,N = map(int, input().split())
p = input()
p = p.split()
p = [int(c) for c in p]
Y = Z = X
flug = 0
if X not in p:
    print(X)
if X in p:    
    for i in range(1,100):
        Y -= 1
        Z += 1
        if Y not in p:
            print(Y, end = " ")
            flug = 1
        elif Z not in p:
            print(Z)
            flug = 1
        if flug == 1:
            break

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
if(n==0):
  print(x)
  exit(0)
a=list(map(int,input().split()))
f=set(a)
mi=1000000
r=100000000
for i in range(-1000,1001):
  if(i in f):
    continue
  if(abs(x-i)<mi):
    mi=abs(x-i)
    r=i
print(r)

Submission status: Accepted

Solution code:
import sys
import math
import decimal

def input():
    return sys.stdin.readline()[:-1]

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

for i in range(0,101):
    up = X + i
    down = X - i
    if down not in P:
        print(down)
        break
    elif up not in P:
        print(up)
        break

Submission status: Accepted

Solution code:
xn = input().split()
X = int(xn[0])
N = int(xn[1])
A = [int(x) for x in input().split()]
li = [x for x in range(102)] 
li2 = list(x for x in li if x not in A )
d_tmp = 1200
ans_tmp = -1
for i in li2:
    d = abs(X-i)
    if d < d_tmp:
        d_tmp = d
        ans_tmp = i
print(ans_tmp)

Submission status: Accepted

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

if p==[]: print(X); exit()

p.sort()
l,r=p[0]-1,p[-1]+1
p=set(p)
sa=float('inf')
ans=float('inf')
for i in range(l,r+1):
    if (i not in p) and (abs(X-i)<sa):
        ans=i
        sa=abs(X-i)

print(ans)

Submission status: Accepted

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

d = [abs(x-i) for i in p]
if 0 not in d:
    print(x)
    exit()
else:
    cur = 1
    while True:
        if d.count(cur) == 0:
            print(x-cur)
            break
        elif d.count(cur) == 1:
            if x-cur not in p:
                print(x-cur)
                break
            else:
                print(x+cur)
                break
        else:
            cur += 1

Submission status: Accepted

Solution code:
x ,n = map(int, input().split())
s = list(map(int, input().split()))
number = list(range(0,102))
min = 100
if n == 0:
  print(x)
  exit()
  
for i in range(n):
  number.remove(s[i])

for i in range(102 - n):
  if min > abs(x - number[i]):
    min = abs(x - number[i])
    j = i
print(number[j])

Submission status: Accepted

Solution code:
X,N,*P=map(int,open(0).read().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

Submission status: Accepted

Solution code:
# coding: utf-8
x,n = map(int, input().split())
a = list(map(int, input().split()))
xx = x

while(True):
    if x in a:
        x-=1
    else:
        break
    
    if xx in a:
        xx+=1
    else:
        x = xx
        break

print(x)

Submission status: Accepted

Solution code:
x, n = map(int,input().split())
lst = set(map(int,input().split()))
df = 0
while True:
    if not (x + df) in lst:
        print(x + df)
        exit()
    df = -df
    if not (x + df) in lst:
        print(x + df)
        exit()
    df = -df
    df -= 1

Submission status: Accepted

Solution code:
def main():
    x, n = map(int, input().split())
    p = [i for i in map(int, input().split())]

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

    i = 0
    while 1:
        if not x-i in p:
            print(x-i)
            break
        elif not x+i in p:
            print(x+i)
            break
        i += 1


main()


# def f(n):
#     return n-x


# p_x = list(map(f, p))
# p_x_abs = list(map(abs, p_x))

# min_p_x = min(p_x)

# i = 0
# print(p_x)
# print(p_x_abs)
# while 1:
#     if i in p_x_abs:
#         i = i+1
#     else:

# print(ans)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
result = []
for i in range(102):
    if i in p:
        continue
    else:
        result.append([abs(i-x), i])
result.sort()
print(result[0][1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x,n = map(int, input().split())
a = list(map(int, input().split()))
lis = [True]*102
for i in a:
    lis[i] = False
ho = 0
while True:
    if not x-ho < 0:
        if lis[x-ho]:
            print(x-ho)
            exit()
    if not x+ho > 101:
        if lis[x+ho]:
            print(x+ho)
            exit()
    ho+=1

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
if n == 0:
  print(x)
else:
  p = list(map(int,input().split()))
  max_trial = 100
  for i in range(max_trial):
    if not x-i in p:
      print(x-i)
      break
    elif not x+i in p:
      print(x+i)
      break

Submission status: Accepted

Solution code:
import sys
x, n = map(int, input().split())
if n == 0:
  print(x)
  sys.exit()
lst = list(map(int, input().split()))
for i in range(250):
  if x - i not in lst:
    print(x - i)
    sys.exit()
  if x + i not in lst:
    print(x + i)
    sys.exit()

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
P=[int(_) for _ in input().split()]
for s in range(X+1):
  for t in [-1, +1]:
    u=X+s*t
    if P.count(u)==0:
      print(u)
      exit()

Submission status: Accepted

Solution code:
def run(x, n, num_array):
    '''
    '''
    if len(num_array) == 0:
        print(x)
        return
    
    i = 0
    while True:
        if x - i not in num_array:
            print(x - i)
            return
        elif x + i not in num_array:
            print(x + i)
            return
        i += 1
        

if __name__ == '__main__':
    x, n = list(map(int, input().split()))
    num_array = list(map(int, input().split()))
    run(x, n, num_array)

Submission status: Accepted

Solution code:
import numpy as np

X,N = map(int, input().split())
P = np.array(list(map(int,input().split())), dtype=np.int32)
num = np.arange(0,102)
kouho = np.setdiff1d(num,P)
ans = kouho[np.argmin((np.abs(kouho-X)))]
print(ans)

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
if N == 0:
  print(X)
  exit()
P = list(map(int, input().split()))
 
for i in range(X+1):
  for d in [-1, +1]:
    if not (X+i*d) in P:
      print(X + i*d)
      exit()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys

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

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

diff_prev = 10**10
for i in range(-1, 102):
    if i in P:
        continue

    diff_now = abs(X - i)
    if diff_prev <= diff_now:
        break
    else:
        diff_prev = diff_now
        i_prev = i

print(i_prev)

Submission status: Accepted

Solution code:
x , n = map(int,input().split())
if n == 0:
    print(x)
    exit()
p = set(map(int,input().split()))
i = 0
while True:
    e = x-i
    if not e in p:
        print(x-i)
        exit()
    d = x+i
    if not d in p:
        print(x+i)
        exit()

    i += 1

Submission status: Accepted

Solution code:
import sys
x,n = map(int, input().split())
if n == 0:
  print(x)
  sys.exit()
data = [int(i) for i in input().split()]
for dif in range(100):
  if x - dif not in data:
    print(x - dif)
    break
  elif x + dif not in data:
    print(x + dif)
    break

Submission status: Accepted

Solution code:
import numpy as np
[x, N] = list(map(int, input().split()))
if N != 0:
  P = list(map(int, input().split()))
  P_max = max(P) + 2
  P_mini = min(P) - 1
  if P_mini <= x <= P_max:
    A = list(range(P_mini, P_max))
    for p in P:
      A.remove(p)
    delta = [np.abs(x - a) for a in A]
    ind = delta.index(min(delta))
    ans = A[ind]
  else:
    ans = x
else:
  ans = x
    
print(ans)

Submission status: Accepted

Solution code:
"""
    Satwik_Tiwari ;) .
    16 june , 2020  - Tuesday
"""

#===============================================================================================
#importing some useful libraries.
from __future__ import division, print_function

from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase


import bisect
from heapq import *
from math import *
from collections import deque
from collections import Counter as counter  # Counter(list)  return a dict with {key: count}
from itertools import combinations as comb # if a = [1,2,3] then print(list(comb(a,2))) -----> [(1, 2), (1, 3), (2, 3)]
from itertools import permutations as permutate
from bisect import bisect_left as bl
#If the element is already present in the list,
# the left most position where element has to be inserted is returned.
from bisect import bisect_right as br
from bisect import bisect
#If the element is already present in the list,
# the right most position where element has to be inserted is returned

#==============================================================================================

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

# inp = lambda: sys.stdin.readline().rstrip("\r\n")

#===============================================================================================
#some shortcuts

mod = 1000000007
def inp(): return sys.stdin.readline().rstrip("\r\n") #for fast input
def out(var): sys.stdout.write(str(var))  #for fast output, always take string
def lis(): return list(map(int, inp().split()))
def stringlis(): return list(map(str, inp().split()))
def sep(): return map(int, inp().split())
def strsep(): return map(str, inp().split())
def graph(vertex): return [[] for i in range(0,vertex+1)]
def zerolist(n): return [0]*n
def nextline(): out("\n")  #as stdout.write always print sring.
def testcase(t):
    for p in range(t):
        solve()
def printlist(a) :
    for p in range(0,len(a)):
        out(str(a[p]) + ' ')
def lcm(a,b): return (a*b)//gcd(a,b)
def power(a,b):
    ans = 1
    while(b>0):
        if(b%2==1):
            ans*=a
        a*=a
        b//=2
    return ans
def ncr(n,r): return factorial(n)//(factorial(r)*factorial(max(n-r,1)))
def isPrime(n) : # Check Prime Number or not
    if (n <= 1) : return False
    if (n <= 3) : return True
    if (n % 2 == 0 or n % 3 == 0) : return False
    i = 5
    while(i * i <= n) :
        if (n % i == 0 or n % (i + 2) == 0) :
            return False
        i = i + 6
    return True

#===============================================================================================
# code here ;))

def solve():
    x,n = sep()
    a = lis()
    cnt = [0]*(101)
    for i in range(n):
        cnt[a[i]] +=1

    ans1= -1
    num = x
    while(num >0):
        if(cnt[num] == 0):
            ans1 = num
            break
        num-=1
    ans2 = -1
    num = x
    while(num < 101):
        if(cnt[num] == 0):
            ans2 = num
            break
        num+=1
    # print(ans1,ans2)
    if(ans1 == -1):
        ans1 = 0
    if(ans2 == -1):
        ans2 = 101

    if(abs(x-ans1) < abs(x-ans2)):
        print(ans1)
    elif(abs(x-ans1) == abs(x-ans2)):
        print(ans1)
    else:
        print(ans2)



testcase(1)
# testcase(int(inp()))

Submission status: Accepted

Solution code:
def serch_1(b,x):
    i=1
    an=0
    while 1:
        if b.count(x+i)==0:
            an=x+i
            break
        else:
            i=i+1
    return an

def serch_2(b,x):
    i=1
    an=0
    while 1:
	    if b.count(x-i)==0:
		    an=x-i
		    break
	    else:
		    i=i+1
    return an
def hikaku(a,b,x):
    if abs(a-x)>=abs(b-x):
    	return b
    else:
        return a
s = list(map(int,input().split()))
# n = int(input())
a = list(map(int,input().split()))
# print(serch_1(a,x),serch_2(a,x))
x=s[0]
n=s[1]
if a.count(x)==0:
	print(x)
else:
	print(hikaku(serch_1(a,x),serch_2(a,x),x))

Submission status: Accepted

Solution code:
import sys

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

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

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

for i in range(X+1):
  if X - i not in lst:
    print(X-i)
    sys.exit()
  if X + i not in lst:
    print(X+i)
    sys.exit()

Submission status: Accepted

Solution code:
from math import gcd

from math import factorial as f

from math import ceil,floor,sqrt
import math

import bisect
import re
import heapq


from copy import deepcopy
import itertools
from itertools import permutations

from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))


yes = "Yes"
no = "No"


def main():
    x,n = mi()
    p = li()

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



main()

Submission status: Accepted

Solution code:
X,N=map(int,input().split())
P=set()
if N!=0:
  P=set(list(map(int,input().split())))
for i in range(100):
  a=X-i
  if a not in P:
    print(a)
    exit(0)
  a=X+i
  if a not in P:
    print(a)
    exit(0)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
L = list(map(int, input().split()))

if N not in L:
  print(N)
else:
  for i in range(N,10000000000):
    i +=1
    if i not in L:
      box = i
      break
  for j in reversed(range(-10000000000, N+1)):
    j -=1
    if j not in L:
      boxm = j
      break
  if abs(N - abs(box)) >= abs(N - abs(boxm)):
    print(boxm)
  else:
    print(box)

Submission status: Accepted

Solution code:
#import math
#=input()
#=int(input())
x,n=map(int,input().split())
p=list(map(int,input().split()))
#=[list(map(int,input().split())) for _ in range()]

if x not in p:
    ans = x
else:
    j = 1
    while True:
        if (x-j) not in p:
            ans = x - j
            break
        if (x+j) not in p:
            ans = x + j
            break
        j += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
X, N = map(int, input().split())

if N == 0:
  print(X)
  sys.exit()
  
if X == 100 and N == 100:
  print(-100)
  sys.exit()
  
  
P = list(map(int, input().split()))

lis = []
for i in range (-100,102,1):
    if i not in P:
        lis.append(i)


        
        
        
ans = 10**18
suzi = 0
lis2 = []
for j in lis:
    num = abs(X-j)
    if num < ans:
        ans = num
        suzi = j

print(suzi)

Submission status: Accepted

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

ans,ansdiff = -1,1000000

for i in range(-1,102):
  if i in P:
    continue
    
  wdiff = abs(X-i)
  if wdiff < ansdiff:
    ansdiff = wdiff
    ans = i
  elif wdiff == ansdiff:
    if ans > i:
      ans = i
      
print(ans)

Submission status: Accepted

Solution code:
x, n = map(int, input().split(" "))
v = [i for i in range(102)]
min_val = 100
ans_val = 0

if n != 0:
    p = list(map(int, input().split(" ")))    
    for index in p:
        v[index] = 101


for v_val in v:
    if(min_val > abs(v_val - x)):
        ans_val = v_val
        min_val = min(min_val, abs(v_val - x))
    #print(abs(v_val - x), end=" ")


#print("")
print(ans_val)

Submission status: Accepted

Solution code:
li1 = list(map(int, input().split()))
li2 = list(map(int, input().split()))
re = li1[0]
n = 1
while True:
    if li1[0] not in li2:
        re = li1[0]
        break
    if li1[0] - n not in li2:
        re = li1[0] - n
        break
    if li1[0] + n not in li2:
        re = li1[0] + n
        break
    n += 1

print(re)

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
P = set(int(x) for x in input().split())

def solve(X, P):
    for i in range(102):
        if X-i not in P:
            return X-i
        if X+i not in P:
            return X+i
        
print(solve(X,P))

Submission status: Accepted

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


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

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


dist_min=N
min_value=X

#p2 = range(X+N,X-N,-1)


for i in range(X+N,X-N-1,-1):
	flag=False
	for j in range(N):
		if(i==p[j]):
			flag=True
	if( flag == True):
		continue
	
	
	dist = abs(X-i)
	
	if ( dist==dist_min ):
		if(i<min_value):
			min_value = i
	elif ( dist < dist_min):
		dist_min = dist
		min_value = i

print(min_value)

Submission status: Accepted

Solution code:
x,y=map(int,input().split())
if y>0:
  l=list(map(int,input().split()))
  for i in range(len(l)+1):
    if x-i not in l:
      print(x-i)
      break
    if x+i not in l:
      print(x+i)
      break
else:
  print(x)

Submission status: Accepted

Solution code:
def fac(l,li):
    for i in range(len(li)+1):
        if l-i not in li:
            return(l-i)
        if l+i not in li:
            return(l+i)

l,n = map(int,input().split())
if n>0:
    li = list(map(int,input().split()))
    print(fac(l,li))
else:
    print(l)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Jun 20 15:49:43 2020

@author: naoki
"""

X,N = map(int,input().split()) # input X and N 
p = list(map(int,input().split())) # input the row of integer 
p.sort() # sorting the row "p"
p1 = [ i for i in range(-101,102)] # making the other row of integer -100<= i <= 100 
gap = 201
row = []
for i in range(N):
    p1.remove(p[i]) # removing the number which is same to p[i]

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

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

Submission status: Accepted

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

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

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

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


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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

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

set_p = set(p)

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

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

Submission status: Accepted

Solution code:
import sys
import operator

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import argparse
import collections
import logging.config
import sys
import csv
import numpy as np

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

def main():

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
X,N=map(int,input().split())
P=list(map(int,input().split()))
S=[0]*(102);a=1000;b=1000;c=10000
for i in range(N):
  S[P[i]]=1
#print(S)
if N==0:
  print(X)
else:
  i=X
  while i>=0:
    if S[i]==0:
      a=i
      break
    i=i-1
  i=X
  while i<=101:
    if S[i]==0:
      b=i
      break
    i=i+1
    #print(a,b)
  if abs(a-X)>abs(b-X):
    c=b
  else:
    c=a
  print(c)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
x,n = map(int, input().split())
a = list(map(int, input().split()))
m=1000
idx=x
for i in range(x-100,x+101):
  k=abs(x-i)
  if(i not in a): 
    if m>k:
      m=k
      idx=i
print(idx)

Submission status: Accepted

Solution code:
from typing import List


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


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


print(solve(x, n, P))

Submission status: Accepted

Solution code:
import numpy

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

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

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

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

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

Submission status: Accepted

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

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

print(tmp)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys

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

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

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

Submission status: Accepted

Solution code:
from bisect import bisect_left

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


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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

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

t = True
i,j=0,0

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

i,j=1,1

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

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
X, N = [int(x) for x in input().split()]
try:
  p = list(map(int, input().split()))
except EOFError:
  p = []
option = list(range(0, 102))
for item in p:
  option[item] = -1
diff = 0
while True:
  if option[X-diff] == X-diff:
    print(X-diff)
    break
  elif option[X+diff] == X+diff:
    print(X+diff)
    break
  else:
    diff += 1