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:
x,n=map(int,input().split())
s=sorted(list(map(int, input().split())))
a=x
b=x
if n==0:
    print(x)
    exit()
for i in range(n+100):
    if not (a in s):
        print(a)
        exit()
    if not (b in s):
        print(b)
        exit()
    a-=1
    b+=1

Submission status: Accepted

Solution code:
X,N = map(int,input().split())
p = list(map(int,input().split()))
a,b = [],[]
cnt = 0
for i in range(0,100):
    if X + cnt not in p:
        a.append(X + cnt)
    if X - cnt not in p:
        b.append(X - cnt)
    cnt += 1
A = a[0]-X
B = X-b[0]
if A < B:
    print(a[0])
else:
    print(b[0])

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
if n != 0:
  l = list(map(int,input().split()))
else:
  l = []

m = 1e9
ans = None
for i in range(101,-2,-1):
  if i in l:
    continue
  if abs(x-i) <= m:
    m = abs(x-i)
    ans = i
print(ans)

Submission status: Accepted

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

p = set(_p)

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

Submission status: Accepted

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

for i in range(101):
    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:
  print(X)
else:
  p=list(map(int,input().split()))
  for i in range(100):
    if X+i not in p:
      if X-i not in p:
        print(X-i)
        break
      print(X+i)
      break
    if X-i not in p:
      print(X-i)
      break

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
p=sorted(list(map(int,input().split())))
if n==0:
    print(x)
    exit()
q=[0]*(p[-1]+2)
for i in range(n):
    q[p[i]]=1
ans=(1000000,-1)
for i in range(p[-1]+2):
    if q[i]==0:
        if ans[0]>abs(i-x):
            ans=(abs(i-x),i)
print(ans[1])

Submission status: Accepted

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

chk=[0 for _ in range(109)]

for i in range(N):
    p=P[i]
    chk[p]=1
ans=10**7
res=-1
for x in range(-1,109):
    if x==-1:
        val=abs(X-x)
    else:
        if chk[x]==1:
            continue
        val=abs(X-x)
    if val<ans:
        ans=val
        res=x

print(res)

Submission status: Accepted

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

for i in range(101):
    if x-i not in pli:
        print(x-i)
        break
    if x+i not in pli:
        print(x+i)
        break

Submission status: Accepted

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

val=0
while True:
    Xa = X - val
    Xb = X + val

    if Xa in p:
        pass
    else:
        print(Xa)
        exit()

    if Xb in p:
        pass
    else:
        print(Xb)
        exit()

    val+=1

Submission status: Accepted

Solution code:
def main():
    x,n = map(int,input().split())
    p_s = list(map(int,input().split()))
    for i in range(101):
        #print(x-i,x+i)

        if (x-i) not in p_s:

            answer = x - i
            break
        if (x + i) not in p_s:
            #print("hit!",x+i)
            answer = x + i
            break
    print(answer)



if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

res = -1
sa = 1000000
for i in range(-2001,2001):
    if i not in p:
        if abs(i-X) < sa:
            res = i
            sa = abs(i-X)

print(res)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
if N == 0:
    print(X)
else:
    P = list(map(int, input().split()))
    P = set(P)
    ans = 0
    i = 0
    while ans == 0:
        Xa = X-i
        Xb = X+i
        if Xa not in P:
            ans = Xa
            break
        if Xb not in P:
            ans = Xb
        i += 1
    print(ans)

Submission status: Accepted

Solution code:
import itertools
import copy
from collections import deque
import heapq
x,n = map(int,input().split())
if n == 0:
    print(x)
    exit()
p = list(map(int,input().split()))
check = {key:0 for key in p}
mi = copy.deepcopy(x)
ma = copy.deepcopy(x)
while True:
    if not mi in check:
        print(mi)
        exit()
    if not ma in check:
        print(ma)
        exit()
    mi -= 1
    ma += 1

Submission status: Accepted

Solution code:
def solve():
    ret = -1
    diff = float('inf')
    for i in range(102):
        if i in p:
            continue
        if abs(X - i) < diff:
            ret = i
            diff = abs(X - i)
    print(ret)

if __name__ == "__main__":
    X, N = map(int, input().split())
    p = set((map(int, input().split())))
    solve()

Submission status: Accepted

Solution code:
import sys

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

tmp1 = 201
tmp2 = 201

for i in range(0,100):
  if X-i not in p:
    tmp1 = X-i
  elif X+i not in p:
    tmp2 = X+i
  if tmp1 != 201 or tmp2 != 201:
    print(min(tmp1,tmp2))
    sys.exit()

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
p = list(map(int, input().split()))
a = [i for i in range(-1, 103)]
for P in p:
    a.remove(P)

ans = 101
d = 10000
for A in a:
    if d > abs(A-X):
        ans = A
        d = abs(A-X)


print(ans)

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
sw = 1
if n == 0:
    sw = 0
    ans = x
else:
    p = list(map(int,input().split()))
    y1 = x
    y2 = x
    ans = 0
    for i in range(n):
        if y1 in p and not(y2 in p):
            ans = y2
            break
        elif y2 in p and not(y1 in p) :
            ans = y1
            break
        elif y1 in p and y2 in p:
            y1 -= 1
            y2 += 1
        else:
            ans = min(y1,y2)
            break
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()))

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import collections
import itertools as it
import math
#import numpy as np
 
#  = input()
#  = int(input())
x, n  = map(int, input().split())
p  = list(map(int, input().split()))
#  = [int(input()) for i in range(N)]
#
# c = collections.Counter()

li = []
for i in range(-1000, 1001):
    if not i in p:
        li.append(i)

ans = 1000
min_ = 1000
for i, l in enumerate(li[::-1]):
    if min_ >= abs(x - l):
        min_ = abs(x - l)
        ans = l

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8

import sys
import math
import collections
import itertools
import bisect
INF = 10 ** 13
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return x if y == 0 else gcd(y, x%y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def LS() : return input().split()
def RS(N) : return [input() for _ in range(N)]
def LRS(N) : return [input().split() for _ in range(N)]
def PL(L) : print(*L, sep="\n")
def YesNo(B) : print("Yes" if B else "No")
def YESNO(B) : print("YES" if B else "NO")

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

for i in range(1000):
    if not(X - i in P):
        print(X-i)
        break
    if not(X + i in P):
        print(X+i)
        break

Submission status: Accepted

Solution code:
x, n = [int(_) for _ in input().split(' ')]

if n == 0:
    print(x)
else:
    p = {int(_) for _ in input().split(' ')}

    answer = 0
    m = 102
    for i in range(102):
        if not(i in p) and abs(x - i) < m:
            answer = i
            m = abs(x - i)
    print(answer)

Submission status: Accepted

Solution code:
import bisect
x,n = map(int, input().split())
if (n==0):
    print(x)
    exit()
p = list(map(int, input().split()))
a = []
for i in range(102):
    if (i in p):
        continue
    a.append(i)
#print(a)


z = bisect.bisect_left(a,x)
if (z==0):
    print(a[0])
    exit()
elif (z==len(a)):
    print(a[-1])
    exit()
a1 = a[z]
a2 = a[z-1]
if (abs(a1-x) < abs(a2-x)):
    print(a1)
elif (abs(a1-x) > abs(a2-x)):
    print(a2)
else:
    print(a2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
if N == 0:
  print(X)
else:
  P = list(map(int, input().split()))
  for d in range(100):
    if X - d not in P:
      print(X - d)
      break
    if X + d not in P:
      print(X + d)
      break

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


def main():
    X, N = [int(i) for i in input().strip().split()]
    p_list = [int(i) for i in input().strip().split()]

    base = list()
    for i in range(-110, 110):
        if i not in p_list:
            base.append(i)

    dif = float("inf")
    ans = None
    for j in base:
        if abs(j - X) < dif:
            dif = abs(j-X)
            ans = j

    return ans


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

Submission status: Accepted

Solution code:
x, n = map(int,input().split())
li = list(map(int,input().split()))
ans = []

for i in range(n):
    ans.append(abs(li[i]-x))

ans.sort()
if 0 not in ans:
    print(x)
else:
    for i in range(1,1000):
        if ans.count(i) == 0:
            print(x-i)
            exit()
        elif ans.count(i) == 1:
            if x+i in li:
                print(x-i)
            else:
                print(x+i)
            exit()

Submission status: Accepted

Solution code:
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline
    ans=99999
    ansd=99999
    x,n=map(int, readline().rstrip().split())

    if n==0:
        print(x)
        return

    p=list(map(int, readline().rstrip().split()))
    for i in range(103):
        if i in p:
            continue
        d=abs(x-i)
        if d < ansd:
            ans=i
            ansd=d

    print(ans)
    #n=int(readline())
    #ss=readline().rstrip()
    #yn(1)

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------

Submission status: Accepted

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

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

if __name__ == "__main__":
    main()

Submission status: Accepted

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

while True:
    if not(X-init in p):
        print(X-init)
        break
    elif not(X+init in p):
        print(X+init)
        break
    init+=1

Submission status: Accepted

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

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

Submission status: Accepted

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

l=list(range(102))

for i in range(n):
  l.remove(p[i])

#print(l)
ans=0
dif=1000

for i in range(102-n):
  temp=abs(l[i]-x)
  if temp<dif:
    dif=temp
    ans=l[i]
print(ans)

Submission status: Accepted

Solution code:
## coding: UTF-8
X, N = map(int,input().split())
if(N > 0):
    P = list(map(int,input().split()))
else:
    p = input()


fresh = [True] * 102 #0~101
if(N > 0):
    for i in range(N):
        fresh[P[i]] = False #1-index

#print(fresh)

min_diff = 1000
ans = 0
l = []

for i in range(102):
    if(fresh[i]):
        l.append(abs(X-i))
    else:
        l.append(10000)
print(l.index(min(l)))



'''
for i in range(100):
    if(fresh[i]):
        #fresh[i] == True -> i+1が使われていないことを示す
        diff = abs(X - (i+1))
        if(min_diff )
'''

Submission status: Accepted

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

a = X
b = X
if X not in p:
    print(X)
    exit()
for i in range(1000):
    a -= 1
    b += 1
    if a not in p:
        print(a)
        break
    elif b not in p:
        print(b)
        break

Submission status: Accepted

Solution code:
x,n=list(map(int,input().split()))
import sys
if n==0:
  print(x)
  sys.exit()

p=list(map(int,input().split()))
for i in range(x,110):
  if 2*x-i not in p:
    print(2*x-i)
    sys.exit()
  if i not in p:
    print(i)
    sys.exit()

Submission status: Accepted

Solution code:
#!/usr/bin/env python
#pyrival orz
import os
import sys
from io import BytesIO, IOBase

"""
    for _ in range(int(input())):
    n,m=map(int,input().split())
    n=int(input())
    a = [int(x) for x in input().split()]
"""

def main():
    m,n=map(int,input().split())
    a = [int(x) for x in input().split()]
    ans=-(1<<30)
    for i in range(m-200,m+200):
        if i in a:
            continue
        if abs(i-m)>=abs(ans-m):
            continue
        ans=i
    print(ans)

# region fastio

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


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    X, N = list(map(int, input().split(' ')))
    if N == 0:
        P = input()
        print(X)
        return
    P = list(map(int, input().split(' ')))
    min_dist, ans = abs(X), 0
    for n in range(102):
        if n in P:
            continue
        if abs(X - n) < min_dist:
            min_dist = abs(X - n)
            ans = n
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
if n==0:
  print(x)
  exit()
P=set(list(map(int,input().split())))

diff= 1000
ans = 0
for i in range(102):
  if i in P: continue
  if abs(x-i)<diff:
    diff = abs(x-i)
    #print(diff,i)
    ans = i
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()))
l = [i for i in range(102)]
for i in p:
    l.remove(i)
a = 100
for i in l:
    a = min(a,abs(x-i))
for i in l:
    if abs(x-i) == a:
        print(i)
        exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x, n = list(map(int, input().split()))
if n == 0:
  print(x)
  quit()
p = list(map(int, input().split()))
ans = x
ans2 = x-1
while True:
  if not ans in p:
    print(ans)
    quit()
  ans += 1
  if not ans2 in p:
    print(ans2)
    quit()
  ans2 -= 1

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
left = 10**9
right = 10**9
i = x
while True:
    if not i in p:
        left = abs(i - x)
        break
    i -= 1
i = x
while True:
    if not i in p:
        right = abs(i - x)
        break
    i += 1
if left == right:
    print(x - left)
elif left < right:
    print(x - left)
else:
    print(x + right)

Submission status: Accepted

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

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

answer_numbers = [[1, 1] for i in range(101)]

for i in range(len(p_i)):
    if x - p_i[i] == 0:
        answer_numbers[0][0] = 0
        answer_numbers[0][1] = 0

    elif x - p_i[i] > 0:
        answer_numbers[abs(x-p_i[i])][0] = 0
    elif x - p_i[i] < 0:
        answer_numbers[abs(x-p_i[i])][1] = 0

for i in range(len(answer_numbers)):
    if not answer_numbers[i] == [0, 0]:
        if answer_numbers[i][0] == 1:
            print(x - i)
            break
        elif answer_numbers[i][1] == 1:
            print(x + i)
            break

Submission status: Accepted

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

value_num = X
value_NUM = X

while 1:
    if not(value_num in p):
        print(value_num)
        break

    if not(value_NUM in p):
        print(value_NUM)
        break

    # print(value_num)
    # print(value_NUM)

    value_num -= 1
    value_NUM += 1

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

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

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

DIFF = 200
ans = 200

for p in range(0, 102):
    if p in P:
        continue

    d = abs(X - p)

    if d == DIFF:
        ans = min(p, ans)
    elif d < DIFF:
        DIFF = d
        ans = p

print(ans)

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
if n != 0:
    P = list(map(int,input().split()))
else:
    P = []
tmp = 999
ans = 0
for i in range(-1,102):
    if tmp > abs(x-i):
        if not i in P:
            tmp = abs(x-i)
            ans = i
print(ans)

Submission status: Accepted

Solution code:
X,N = list(map(int,input().split()))
if N == 0:
  P = []
else:
  P = list(map(int,input().split()))
MIN = float('inf')
MINLIST = []
for i in range(-1000,1000):
    if i not in P and abs(X-i) <= MIN:
        if abs(X-i) == MIN:
            MINLIST.append(i)
        else:
            MIN = abs(X-i)
            MINLIST = [i]
print(min(MINLIST))

Submission status: Accepted

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

for i in range(200):
    if X-i not in P:
        print(X-i)
        exit()
    elif X+i not in P:
        print(X + i)
        exit()
    else:
        continue

print(X)

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
P = set(map(int, input().split()))
ans = 0
for i in range(102):
    if i in P:
        continue
    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 n == 0 :
        return x
    if x < 0 :
        return x-1
    elif x >= 102 :
        return x-1
    
    used = [False]*102
    for p in map(int, input().split(" ")):
        used[p]=True
    
    _min = float('inf')
    ans = 0
    for i in range(0, 102):
        if used[i] :
            continue
        if abs(i-x) < _min :
            _min = abs(i-x)
            ans = i
    
    return ans

print(solve())

Submission status: Accepted

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

d = 0
while True:
    for sgn in [-1, 1]:
        x = X + sgn * d
        if x not in p:
            break
    else:
        d += 1
        continue
    break
print(x)

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
if n > 0:
  a = list(map(int,input().split()))
else:
  a = []
a = set(a)
ans = x
for i in range(100):
  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:
x,n=map(int,input().split())
if n==0:
  print(x)
  exit()
P=list(map(int,input().split()))
for i in range(200):
  if x-i not in P:
    print(x-i)
    exit()
  elif x+i not in P:
    print(x+i)
    exit()

Submission status: Accepted

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

    nums = [i for i in range(-200, 200)]

    for i in range(N):
        nums.remove(p[i])
        
    min_diff = 1000
    min_index = 1000

    for i in range(len(nums)):
        if abs(X - nums[i]) < min_diff or (abs(X - nums[i]) == min_diff and nums[min_index] > nums[i]):
            min_diff = abs(X-nums[i])
            min_index = i

    print(nums[min_index])


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
X, n = map(int, input().strip().split())
if not n:
    print(X)
    exit()

L = list(map(int, input().strip().split()))
dist=0
while True:
    if X-dist not in L:
        ans=X-dist
        break
    elif X+dist not in L:
        ans=X+dist
        break
    dist+=1
print(ans)

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
p = list(map(int,input().split()))
cnt = 0
sop = sorted(p)
for i in range (len(sop)):
    sop[i] -= x
while True:
    if -cnt not in sop:
        print(x-cnt)
        break
    elif cnt not in sop:
        print(x+cnt)
        break
    else:
        cnt +=1

Submission status: Accepted

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

Submission status: Accepted

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

i=0

while True:
    if X-i in A and X+i in A:
        i+=1
    elif X-i in A:
        print(X+i)
        exit()
    else:
        print(X-i)
        exit()

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
if n==0:
  print(x)
else:
  a=list(map(int,input().split()))
  tmp=1000
  for i in reversed(range(-1,102)):
    if i not in a:
      if tmp >= abs(i-x):
        tmp=abs(i-x)
        ans=i
  print(ans)

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
p=list(map(int,input().split()))
t=0
while t<=100:
    if x-t not in p:
        print(x-t)
        exit()
    if x+t not in p:
        print(x+t)
        exit()
    t += 1

Submission status: Accepted

Solution code:
target = input().split()
target = [int(i) for i in target]
try:
  arr = input().split()
  arr = [int(i) for i in arr]
except:
  arr = []

if len(arr)==0:
  print(target[0])
else:
  i=0
  while(1):
    if target[0]-i in arr and target[0]+i in arr:
      i+=1
    elif target[0]-i not in arr:
      print(target[0]-i)
      break
    elif target[0]+i not in arr:
      print(target[0]+i)
      break

Submission status: Accepted

Solution code:
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


# 処理内容
def main():
    X, N = map(int, input().split())
    p = list(map(int, input().split()))

    ans = X
    tmp = INF
    for n in range(X, 102):
        if abs(X-n) < tmp and not n in p:
            ans = n
            tmp = abs(X-n)
            break
    for n in reversed(range(-1, X)):
        if abs(X-n) <= tmp and not n in p:
            ans = n
            break
    
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

sa = float("inf")
ans = 0
for i in range(105, -5, -1):
    if sa >= abs(x - i) and (i not in p):
        ans = i
        sa = abs(x - i)
print(ans)

Submission status: Accepted

Solution code:
X,N = list(map(int, input().split()))
if(N==0):
  print(X)
else:
  p = list(map(int, input().split()))
  now1 = X
  now2 = X
  while(1):
    if(now1 not in p):
      print(now1)
      break
    elif(now2 not in p):
      print(now2)
      break
    now1 -= 1
    now2 += 1

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict, Counter, namedtuple, deque
import itertools
import functools
import bisect
import heapq
import math
# from fractions import gcd

MOD = 10 ** 9 + 7
# MOD = 998244353
# sys.setrecursionlimit(10**8)

x, n = map(int, input().split())
A = set(map(int, input().split()))
P = [i for i in range(102) if i not in A]
min_dif = (-1, float("inf"))
for i in range(len(P)):
    if abs(x-P[i]) < min_dif[1]:
        min_dif = (P[i], abs(x-P[i]))

print(min_dif[0])

Submission status: Accepted

Solution code:
X, N = [int(i) for i in input().split()]
if N==0:
    print(X)
    quit()
P = list(set(range(-10, 110)) - {int(i) for i in input().split()})
# X = 10
# P = list(set(range(-10, 110)) - set(range(1, 101)))

P.sort()

D = [abs(P[i]-X) for i in range(len(P))]

print(P[D.index(min(D))])

Submission status: Accepted

Solution code:

def main():
  x, n = map(int, input().split())
  arr = set(map(int, input().split()))

  i = 0
  while True:
    if x - i not in arr:
      print(x - i)
      return

    if x + i not in arr:
      print(x + i)
      return

    i += 1



main()

Submission status: Accepted

Solution code:
import sys
import math
import collections
import decimal
import itertools
from collections import deque
from functools import reduce
import heapq
#n = int(input())
x, n = map(int, sys.stdin.readline().split())
#s = input()
p = list(map(int, sys.stdin.readline().split()))

r = []
for i in range(1000):
    r.append(-500+i)

for i in range(n):
    r.remove(p[i])
    
ans = []
q = 10 ** 8
for i in range(len(r)):
    if abs(r[i] - x) < q:
        q = abs(r[i] - x)

for i in range(len(r)):
    if q == abs(r[i] - x):
        ans.append(r[i])


    
print(min(ans))

Submission status: Accepted

Solution code:
target_x, n = map(int,input().split())
p_ls = list(map(int, input().split()))
p_ls.sort()

min_diff = float('inf')
ans_maybe = []
for i in range(102):
    if min_diff > abs(target_x-i):
        if i not in p_ls:
            min_diff = abs(target_x-i)
            ans_maybe = []
            ans_maybe.append(i)
    elif min_diff == abs(target_x-i):
        if i not in p_ls:
            ans_maybe.append(i)
print(min(ans_maybe))

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
if n:
    p = list(map(int,input().split()))
else:
    p = []
p = set(p)
pp = set([item for item in range(0,105) if item not in p])
v = 3000
ans = -1
for item in pp:
    if v>abs(x-item):
        v = abs(x-item)
        ans = item
print(ans)

Submission status: Accepted

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

t=100000
ans=0
for i in range(102):
    if i in p:
        continue
    elif t>abs(i-x):
        t=abs(i-x)
        ans=i

print(ans)

Submission status: Accepted

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

minSa = 500
ans = -501

for i in range(-500, 501):
    if i in p:
        continue
    else:
        sa = abs(i - x)
        if sa < minSa:
            minSa = sa
            ans = i

print(ans)

Submission status: Accepted

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

    for i in range(-1,102):
        if(i not in p):
            e = abs(i - X)
            if e < ans:
                ans = e
                ans1 = i
    print(ans1)
else:
    print(X)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
banned = set()
if n:
    banned |= set(map(int, input().split()))
l = x
r = x
while l in banned and r in banned:
    l -= 1
    r += 1

if l not in banned:
    print(l)
elif r not in banned:
    print(r)

Submission status: Accepted

Solution code:
import bisect
x,n = map(int,input().split())
p = list(map(int,input().split()))
lis = []
for i in range(110,-50,-1):
    if i not in p:
        lis.append(i)
m = 10000
ans = 0
for i in lis:
    if abs(x-i)<=m:
        m = abs(x-i)
        ans = i

print(ans)