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 sys
import numpy as np
import random
from decimal import Decimal
import itertools
import re
import bisect
from collections import deque, Counter
from functools import lru_cache

sys.setrecursionlimit(10**9)
INF = 10**13
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)]
def SERIES(n): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ')
def GRID(h,w): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ').reshape(h,-1)[:,:w]
def GRIDfromString(h,w): return np.frombuffer(sys.stdin.buffer.read(), 'S1').reshape(h,-1)[:,:w]
MOD = 1000000007

def main():
	x, n = LI()
	p = LI()
	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



if __name__ == '__main__':
    main()

Submission status: Accepted

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

#p_L = list(sorted(p_L))
p_L = set(p_L)

sa = 101
for i in range(0,200):
    if i not in p_L:
        if sa > min(sa,abs(i-x)):
            sa = abs(x-i)
            ans = i
        #ans = min(i,)

print(ans)

Submission status: Accepted

Solution code:
X,N = map(int,input().split())
a = []
if N != 0:
  a = list(map(int,input().split()))
if a == []:
  print(X)
else:
  for i in range(200):
    if X-i not in a:
      print(X-i)
      break
    if X+i not in a:
      print(X+i)
      break

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce, lru_cache  # @lru_cache(None)
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**6)
# ----------------------------------------------------------- #

x, n = (int(x) for x in input().split())
if n == 0:
    print(x)
    exit()
P = list(int(x) for x in input().split())

for i in range(53):
    if x-i not in P:
        print(x-i)
        exit()
    if x+i not in P:
        print(x+i)
        exit()

Submission status: Accepted

Solution code:
import math


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

while True:

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import sys
from math import pi, cos, sqrt
from collections import defaultdict
readline = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**8)


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def main():
    x, n = geta(int)
    p = set(tuple(geta(int)))

    if x not in p:
        print(x)
        return

    x1 = x - 1
    x2 = x + 1

    while True:
        if x1 not in p:
            print(x1)
            return

        if x2 not in p:
            print(x2)
            return

        x1 -= 1
        x2 += 1


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys

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

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

d=0
for i in range(1000):
    if x-d not in p:
        print(x-d)
        sys.exit()
    elif x+d not in p:
        print(x+d)
        sys.exit()
    d+=1

Submission status: Accepted

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

s = list(range(0, 102))
for pi in p:
    s.remove(pi)

y = [(abs(pi - X), pi) for pi in s]
ans = min(y)[1]
print(ans)

Submission status: Accepted

Solution code:
def main():
    x,n = map(int,input().split())
    p = set(map(int,input().split()))
    x1,x2 = x,x
    if n == 0:
        print(x)
        return 0
    if x not in p:
        print(x)
        return 0
    while True:
        x1 -= 1
        x2 += 1
        if x1 not in p:
            print(x1)
            return 0
        if x2 not in p:
            print(x2)
            return 0

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
p=list(map(int,input().split()))
k=0
sa=100
for i in range(200,-200,-1):
    if i in p:
        continue
    value=abs(x-i)
    if value<=sa:
        k=i
        sa=value
print(k)

Submission status: Accepted

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

if N == 0:
  print(X)
else:
  ps = set(list(map(int, input().split())))

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

Submission status: Accepted

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

q = set(range(-1, 100 + 2)) - set(p)

f = []

for e in q:
  f.append((abs(e - x), e - x))

print(x + min(f)[1])

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
p = list(map(int,input().split()))
f = [False] * 301
#f[0]は-1
    
a = 1145141919
ans = 0
for i in range(-100,300):
    fl = 1
    for j in p:
        if i == j:
            fl = 0
            
    if fl == 1:
        if abs(i-x) < a:
            ans = i
            a = abs(i-x)
            
print(ans)

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
if N >= 1:
    P = sorted(list(map(int, input().split())))
else:
    P = []

c = 200
for x in range(-1, 102):
    if x in P:
        continue
    else:
        tmp = abs(X-x)
        if tmp < c:
            c = tmp
            ans = x
print(ans)

Submission status: Accepted

Solution code:
X, N =map(int, input().split())
p = list(map(int, input().split()))
for k in range(300):
    if X - k not in p:
        print(X-k)
        break
    if X + k not in p:
        print(X+k)
        break

Submission status: Accepted

Solution code:
import sys, math
#import io, os
#data = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
#from bisect import bisect_left as bl, bisect_right as br, insort
#from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter
#from itertools import permutations,combinations
def data(): return sys.stdin.buffer.readline().strip()
def mdata(): return list(map(int, data().split()))
def outl(var) : sys.stdout.write(' '.join(map(str, var))+'\n')
def out(var) : sys.stdout.write(str(var)+'\n')
#sys.setrecursionlimit(100000)
INF = float('inf')
mod = 998244353
#from decimal import Decimal

x,n=mdata()
p=set(mdata())
m=x
v=0
for i in range(1,102):
    if i not in p:
        if abs(i-x)<m:
            v=i
            m=abs(i-x)
out(v)

Submission status: Accepted

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

ans = None
d = float('inf')
for i in range(-100, 200):
    if i in PS:
        continue
    a = abs(X-i)
    if a < d:
        ans = i
        d = a

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
X, N = map(int, sys.stdin.readline().rstrip().split())
P = list(map(int, sys.stdin.readline().rstrip().split()))
P = set(P)
for i in range(1000):
    if X - i not in P:
        print(X - i)
        exit()
    if X + i not in P:
        print(X + i)
        exit()

Submission status: Accepted

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

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

  res = set(range(102)) - set(p_list)
  res = [(abs(r-x), r) if r<=x else (abs(r-x)+0.5, r)
         for r in res]
  res = sorted(res, key=lambda r: r[0])

  print(res[0][1])
else:
  print(x)

Submission status: Accepted

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

mini = None
minabs = 1000

for i in range(102):
    if i not in Ps and abs(X-i) < minabs:
        mini = i
        minabs = abs(X-i)
print(mini)

Submission status: Accepted

Solution code:
import sys

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

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

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

for i in range(200):
    a=X-i
    b=X+i

    if a not in p_list:
        print(a)
        sys.exit(0)
    
    if b not in p_list:
        print(b)
        sys.exit(0)

Submission status: Accepted

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

for i in range(200):
    y,yy = X-i,X+i
    if y not in P:
        print(y)
        break
    elif yy not in  P:
        print(yy)
        break

Submission status: Accepted

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

for i in range(101):
    if not X - i in A:
        print(X - i)
        break
    if not X + i in A:
        print(X + i)
        break

Submission status: Accepted

Solution code:
# coding: utf-8
import sys

stdin = sys.stdin
ns = lambda: stdin.readline().rstrip() # ignore trailing spaces
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))


def BinarySearch(num, List):
    if len(List) == 0:
        print("Erorr : list has no element")
        return
    left,right = 0,len(List)
    while left < right:
        mid  = (left+right)//2
        if num < List[mid]:#
            right = mid
        else:
            left = mid + 1
    return right


def main():
    x,n = na()
    ps = sorted(na())
    if n==0:
        print(x)
        return
    cnt = 0
    while 1:
        right = BinarySearch(x-cnt, ps)
        if ps[right-1] != x-cnt:
            print(x-cnt)
            return
        right = BinarySearch(x+cnt, ps)
        if ps[right-1] != x+cnt:
            print(x+cnt)
            return
        cnt += 1
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

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

p=[int(i) for i in input().split()]
p.sort()
p.append(999999)

sco=999999
ans=None
i=-2
now=0
while i<105:
    if abs(i-x)<sco and p[now]!=i:
        sco=abs(i-x)
        ans=i
    i+=1
    if i>p[now]:
        now+=1
print(ans)

Submission status: Accepted

Solution code:
import sys
import  math
import fractions
from collections import defaultdict
stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

X,N=nm()
p=nl()
cur=0
while(1):
    min_X=X-cur
    max_X=X+cur
    if(min_X not in p):
        print(min_X)
        sys.exit(0)
    if(max_X not in p):
        print(max_X)
        sys.exit(0)
    cur+=1

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
if N != 0:
  p = list(map(int, input().split()))
else:
  print(X)
  quit()
  
b = True
i = 0
while b:
  if X - i not in p:
    print(X - i)
    quit()
  elif X + i not in p:
    print(X + i)
    quit()
  i += 1

Submission status: Accepted

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

for i in range(X, 1000):
    if i not in P:
        a = i
        break
b = 0
for i in range(X, -1, -1):
    if i not in P:
        b = i
        break

if a-X < X-b:
    print(a)
else:
    print(b)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
ans = None
dif = 10**10

for i in range(-1000, 1000):
    if i in p:
        continue
    if abs(i - x) < dif:
        dif = abs(i - x)
        ans = i

print(ans)

Submission status: Accepted

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

p_set = set(p)

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

Submission status: Accepted

Solution code:
x, N = list(map(int, input().split()))
p = list(map(int, input().split()))
dif = 0

while(dif <= x):
    if x - dif not in p:
        print(x - dif)
        break
    if x + dif not in p:
        print(x + dif)
        break
    dif += 1

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
array = [int(x) for x in input().split()]
res = float("inf")
diff = float("inf")
for a in range(200):
    if diff > abs(x-a) and a not in array:
        diff = abs(x-a)
        res = a
else:
    print(res)

Submission status: Accepted

Solution code:
import sys
X,N=map(int, input().split())
p=set(list(map(int, input().split())))
count=0
if N==0:
    print(X)
    sys.exit()

while(True):
    x1=X-count
    x2=X+count
    if x1 not in p:
        print(x1)
        sys.exit()
    if x2 not in p:
        print(x2)
        sys.exit()    
    count+=1

Submission status: Accepted

Solution code:
X,N = map(int,input().split())
if N != 0:
    p = list(map(int,input().split()))
    setp = set(p)
    ans_plus = X
    ans_minus = X
    val = 0
    while True:
        ans_plus = X + val
        ans_minus = X - val
        if ans_minus not in setp:
            print(ans_minus)
            break
        elif ans_plus not in setp:
            print(ans_plus)
            break
        else:
            val += 1
else:
    print(X)

Submission status: Accepted

Solution code:
x,n = list(map(int, input().split()))
p = set(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

Submission status: Accepted

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

ans = -1
i = 1

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

while ans == -1:
    temp = x -i
    if temp not in p:
        ans = temp
        break
    temp = x + i
    if temp not in p:
        ans = temp
        break
    i += 1

print(ans)

Submission status: Accepted

Solution code:
X,N = map(int,input().split())
if N==0:
    li = [-1]
else:
    li = list(map(int,input().split()))

mm = 200
for i in range(-10,110):
    for j in li:
        if i==j:
            break
    else:
        if abs(i-X)<abs(mm-X):
            mm = i
print(mm)

Submission status: Accepted

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

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

if X in P:
    ans = -1
else:
    ans = 0
for i in range(102):
    if i in P:
        continue
    if abs(i-X) < abs(ans-X):
        ans = i

print(ans)

Submission status: Accepted

Solution code:
from bisect import bisect_left as bil
from bisect import bisect_right as bir
x, N = map(int, input().split())
*A, = map(int, input().split())
S = set(A)

mn = 1 <<60
mna = -1
for i in range(-100, 200):
    if i in S:
        continue
    if abs(i - x) < mn:
        mn  = abs(i - x)
        mna = i

print(mna)

Submission status: Accepted

Solution code:
X,N = map(int, input().split())
p = list(map(int, input().split()))
ans = -100
for i in range(-10,110,1):
    if not (i in p):
        if abs(X-ans)>abs(X-i):
            ans = i

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
ans1, ans2 = x, x
cnt1, cnt2 = 0, 0
while ans1 in p:
    ans1 += 1
    cnt1 += 1
while ans2 in p:
    ans2 -= 1
    cnt2 += 1
if cnt1 >= cnt2:
    print(ans2)
else:
    print(ans1)

Submission status: Accepted

Solution code:
X, N = map(int, input().split(' '))
P = list(map(int, input().split(' '))) if N else []
ans = 102
for i in range(102,-2,-1):
    if i not in P:
        ans = i if abs(ans-X) >= abs(i-X) else ans
print(ans)

Submission status: Accepted

Solution code:
X,N=map(int,input().split())
P=list(map(int,input().split()))
if X not in P:
    print(X)
    exit()
d=1
while True:
    a=X-d
    b=X+d
    if a not in P:
        print(a)
        break
    if b not in P:
        print(b)
        break
    d+=1

Submission status: Accepted

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

p=set(p)
ans=1000
for i in range(x+100):
    if i not in p:
        if abs(ans-x)>abs(i-x):
            ans=i
print(ans)

Submission status: Accepted

Solution code:
import math
import sys
import itertools
from math import gcd
from math import sqrt
from sys import stdin
def input() : return stdin.readline().rstrip()
def mips():
    return map(int,input().split())
def ii():
    return int(input())
sys.setrecursionlimit(10**9)

X,N = mips()
P = [i for i in mips()]
A = []
c1 = -1
c2 = -1
for i in range(100):
    if c1 == 1 and c2 == 1:
        break
    a1 = X-i
    a2 = X+i
    if c1 == -1 and a1 not in P:
        A.append(a1)
        c1 = 1
    if c2 == -1 and a2 not in P:
        A.append(a2)
        c2 = 1
ans = 1000
B = []
for el in A:
    if abs(ans-X) >= abs(el-X):
        ans = el
        B.append(ans)
print(min(B))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

def slove():
    x, n = map(int,input().split())
    p = list(map(int,input().split()))
    for i in range(101):
        if x-i not in p:
            print(x-i)
            break
        if x+i not in p:
            print(x+i)
            break

if __name__ == "__main__":
    slove()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

def ans(P, X):
    P = set(P)
    for i in range(200):
        if X - i not in P:
            return X-i 
        if X + i not in P:
            return X+i

X, N = input().split(' ')
X = int(X)
N = int(N)
if N == 0:
    print(X)
else:
    P = input().split(' ')
    P = [int(x) for x in P]

    print(ans(P, X))

Submission status: Accepted

Solution code:
X,N=map(int, input().split())
P=list(map(int, input().split()))
if N==0:
    print(X)
    exit()
if X not in P:
    print(X)
    exit()
add=1
while True:
    if X-add not in P:
        print(X-add)
        break
    if X+add not in P:
        print(X+add)
        break
    add+=1

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

'''

'''

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

l, r = x,x 

if not(x in p):
    print(x)
else:
    while True:
        if not(l in p):
            print(l)
            break
        elif not(r in p):
            print(r)
            break

        l -= 1
        r += 1

Submission status: Accepted

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

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



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

Submission status: Accepted

Solution code:
X,N = [int(i) for i in input().split()]
if N == 0:
    print(X)
    exit()
p = [int(i) for i in input().split()]
if not X in p:
    print(X)
    exit()
for i in range(1,100):
    if not X-i in p:
        print(X-i)
        exit()
    if not X+i in p:
        print(X+i)
        exit()

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = list(map(int ,input().split()))
p.sort()
ans = []
for i in range(100):
    x_left = x-i
    x_right = x + i
    if x_left not in p:
        print(x_left)
        exit()
    elif x_right not in p:
        print(x_right)
        exit()

Submission status: Accepted

Solution code:
x,n = map(int, input().split())
ps = list(map(int, input().split()))
ps = set(ps) 
mn = 1000
ans = -1
for i in range(102):
    if i in ps: continue
    if abs(i-x) < mn:
        ans = i
        mn = abs(i-x)
print(ans)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
P = list(map(int, input().split()))
ans_sma = x
ans_lar = x
while True:
    if ans_sma not in P:
        print(ans_sma)
        break
    elif ans_lar not in P:
        print(ans_lar)
        break
    ans_sma -= 1
    ans_lar += 1

Submission status: Accepted

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

i = 0
while (x + i in p) and (x - i) in p:
    i += 1

if x - i not in p:
    print(x - i)
else:
    print(x + i)

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
if n==0:
  print(x)
  exit()
P=list(map(int,input().split()))
f=10**10
ans=0
for i in range(-120,220):
  if i not in P:
    a=abs(x-i)
    if a<f:
      f=a
      ans=i
print(ans)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    x,n=MI()
    pp=set(MI())
    for d in range(100):
        if x-d not in pp:
            ans=x-d
            break
        if x+d not in pp:
            ans=x+d
            break
    print(ans)

main()

Submission status: Accepted

Solution code:
x,n = map(int, input().split())
P = sorted(list(map(int, input().split())))
tmp = 0
for i in range(100):
    if x-tmp not in P:
        print(x-tmp)
        exit()

    elif x + tmp not in P:
        print(x+tmp)
        exit()
    tmp +=1

Submission status: Accepted

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

for i in range(2*n+1):
    a=x-i
    b=x+i

    if a not in p:
        m=a
        break
    if b not in p:
        m=b
        break
print(m)

Submission status: Accepted

Solution code:
from collections import defaultdict

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

plist = map(int, input().split())

pdict = defaultdict(int)

for p in plist:
    pdict[p] = 1



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

z = 1


while True:
    if pdict[x - z] == 0:
        print(x - z)
        exit(0)
    if pdict[x + z] == 0:
        print(x + z)
        exit(0)
    z += 1

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
p=list(map(int,input().split()))
if n!=0:
    for i in range((max(p)+3)**2):
        num=x+i in p
        num2=x-i in p
        if num2==False:
            ans=x-i
            break
        if num==False:
            ans=x+i
            break
else:
    ans=x
print(ans)

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
A = list(map(int, input().split()))
for i in range(110):
  s = X - i
  t = X + i
  if s not in A:
    print(s)
    exit()
  if t not in A:
    print(t)
    exit()

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

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

for i in range(N+2):
    if not (X-i in p):
        print(X-i)
        exit()
    if not (X+i in p):
        print(X+i)
        exit()

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    X, N = map(int, input().split())
    if N == 0:
        print(X)
        exit()
    else:
        P = set(map(int, input().split()))
    for i in range(100):
        x2 = X - i
        if x2 not in P:
            print(x2)
            exit()
        x1 = X + i
        if x1 not in P:
            print(x1)
            exit()

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
sys.setrecursionlimit(10**7)
from pprint import pprint as pp
from pprint import pformat as pf
# @pysnooper.snoop()
#import pysnooper # debug

import math
#from sortedcontainers import SortedList, SortedDict, SortedSet # no in atcoder
import bisect

def solve(x, s):
    d = 0
    while d < 200: #TODO
        v = x - d
        if v not in s:
            return v
        v = x + d
        if v not in s:
            return v
        d += 1
    raise RuntimeError


if __name__ == '__main__':
    x, n = list(map(int, input().split()))
    if n == 0:
        print(x)
    else:
        s = set(map(int, input().split()))
        ans = solve(x, s)
        print(ans)


    #print('\33[32m' + 'end' + '\033[0m') # debug

Submission status: Accepted

Solution code:
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

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

ans = 0
d = 1 << 28
for i in range(200):
    if i not in A and abs(X - i) < d:
        ans = i
        d = abs(X - i)

print(ans)

Submission status: Accepted

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    X, N = map(int, input().split())
    P = list(map(int, input().split()))
    ans = float("inf")
    ans_m = float("inf")
    for i in range(-10, 110):
        if i not in P:
            if abs(X-i) < ans_m:
                ans_m = abs(X-i)
                ans = i
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import bisect
MOD = 10**9+7

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

def ii():
    return int(input())

def main():
    X, N = mi()
    p = list(mi())
    i = 0
    while True:
        if not X-i in p:
            print(X-i)
            return
        if not X+i in p:
            print(X+i)
            return
        i += 1

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
P=sorted(list(map(int,input().split())))
if n==0:print(x);exit()
ans=10**9
add=0
point=-1
for i in range(-100,200):
    if i==P[add]:
        if add!=n-1:add +=1
        continue
    else:
        if abs(i-x)<ans:
            point=i
            ans=abs(i-x)
print(point)

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
if n == 0:
    print(x)
    exit()
S = set(map(int,input().split()))
for i in range(300):
    y = x-i
    if not y in S:
        print(y)
        break
    z = x+i
    if not z in S:
        print(z)
        break

Submission status: Accepted

Solution code:
X,N = map(int,input().split())
if N > 0:
  P = input().split()
  P = [int(x) for x in P]
else:
    P = []

ans = 101
s = 101-X
for i in range(101)[::-1]:
  a = abs(i - X)
  if a <= s:
    if not(i in P):
      ans = i
      s = a

print(ans)

Submission status: Accepted

Solution code:
import numpy as np

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

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

qq = set(range(102))

cand = np.array(sorted(list(qq-pp)))

print(cand[abs(cand - x).argmin()])

Submission status: Accepted

Solution code:
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    _LI = lambda : [-int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())
    SI = lambda : sys.stdin.readline().rstrip()
    DD = ((1,0),(0,1),(-1,0),(0,-1))

    X, N = LI()
    p = LI()

    sa = 1000000
    ans = 0
    for i in range(102):
        if abs(i-X) < sa and (not i in p):
            sa = abs(i-X)
            ans = i
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from sys import stdin
from decimal import Decimal

def main():

    input = stdin.readline

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

    ans = X

    if ans not in P:
        print(ans)
        return


    for i in range(1,100):
        if ans - i not in P:
            print(ans - i)
            return
        elif ans + i not in P:
            print(ans + i)
            return

    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from __future__ import print_function
import sys


if sys.subversion[0] == "PyPy":
    import io, atexit

    sys.stdout = io.BytesIO()
    atexit.register(lambda: sys.__stdout__.write(sys.stdout.getvalue()))

    sys.stdin = io.BytesIO(sys.stdin.read())
    input = lambda: sys.stdin.readline().rstrip()
RS = raw_input
RA = lambda x=int: map(x, RS().split())
RN = lambda x=int: x(RS())


def solve():
    high = x
    low = x
    while(1):
        if low not in p:
            print(low)
            return
        if high not in p:
            print(high)
            return
        low -= 1
        high +=1






x, n  = RA()
if n:
    p = set(RA())
else:
    p = set()
solve()