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

if x in P:
    f = 0
    d = 0
    ans1 = x
    while f == 0:
        d += 1
        ans1 -= 1
        if ans1 in P:
            pass
        else:
            f = 1

    f = 0
    d2 = 0
    ans2 = x
    while f == 0:
        d2 += 1
        ans2 += 1
        if  ans2 in P:
            pass
        else:
            f = 1

    if d <= d2:
        print(ans1)
    else:
        print(ans2)
else:
    print(x)

Submission status: Accepted

Solution code:
x = list(map(lambda x:int(x), input().split()))
X = x[0]
N = x[1]
p = []
if N != 0:
  p = list(map(lambda x:int(x), input().split()))

near = [False]*102

#print(near)
#print(near[200])

for i in p:
  near[i] = True
  
for i in range(0,100):
  if not near[X-i]:
    print(X-i)
    break
  elif not near[X+i]:
    print(X+i)
    break

Submission status: Accepted

Solution code:

import sys, io, os, re
import bisect
from pprint import pprint
from math import sin, cos, pi, radians, sqrt, floor
from copy import copy, deepcopy
from collections import deque
from fractions import gcd
from functools import reduce
from itertools import groupby

n1 = lambda: int(sys.stdin.readline().strip())
nn = lambda: list(map(int, sys.stdin.readline().strip().split()))
f1 = lambda: float(sys.stdin.readline().strip())
fn = lambda: list(map(float, sys.stdin.readline().strip().split()))
s1 = lambda: sys.stdin.readline().strip()
sn = lambda: list(sys.stdin.readline().strip().split())
nl = lambda n: [n1() for _ in range(n)]
fl = lambda n: [f1() for _ in range(n)]
sl = lambda n: [s1() for _ in range(n)]
nm = lambda n: [nn() for _ in range(n)]
fm = lambda n: [fn() for _ in range(n)]
sm = lambda n: [sn() for _ in range(n)]

def array1(n): return [0] * n
def array2(n, m): return [[0] * m for x in range(n)]
def array3(n, m, l): return [[[0] * l for y in xrange(m)] for x in xrange(n)]

X, N = nn()
P = nn()

if N == 0:
    print(X)
else:
    d = 999
    ans = -1

    for i in range(102):
        if (i in P):
            continue

        t = abs(X - i)
        if t < d:
            d = t
            ans = 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()))
    if not X in P:
        print(X)
    else:
        for j in range(2*N):
            if not (X-j) in P:
                print(X-j)
                break
            if not (X+j) in P:
                print(X+j)
                break

Submission status: Accepted

Solution code:
import sys
X,N=map(int, sys.stdin.readline().split())
P=map(int, sys.stdin.readline().split())

L=[ 0 for _ in range(202) ]

for p in P:
    L[p]=1

kyori=float("inf")
ans=None
for i,x in enumerate(L):
    if x==0:
        new_kyori=abs(i-X)
        if new_kyori<kyori:
            ans=i
            kyori=new_kyori
print ans

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
if n == 0:
    p = []
a = 0
b = 0
if n != 0:
    p = list(map(int,input().split()))
#print(p)
i = 0
while True:
    if x-i in p:
        i += 1
    else:
        a = x-i
        break
i = 0
while True:
    if x+i in p:
        i += 1
    else:
        b = x+i
        break
if abs(x-a)>abs(x-b):
    print(b)
if abs(x-a)<=abs(x-b):
    print(a)

Submission status: Accepted

Solution code:
X,N=map(int,input().split())
if N!=0:
	P=set(map(int,input().split()))
else:
	P=set()
ans=0
for i in range(1,X+1):
	if i not in P:
		ans=i
for i in range(X+1,2*X-ans):
	if i not in P:
		ans = i
		break
print(ans)

Submission status: Accepted

Solution code:
from bisect import bisect

x, n = map(int, input().split())
ls = list(map(int, input().split()))
mx = [True] * 101
for i in ls:
	mx[i - 1] = False
r = x - 1
ans1 = 101
ans2 = 0
while r < 100:
	if mx[r]:
		ans1 = r + 1
		break
	r += 1
l = x - 1
while l >= 0:
	if mx[l]:
		ans2 = l + 1
		break
	l -= 1

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

Submission status: Accepted

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

    more = X
    less = X

    if X not in numbers:
        print(X)
    else:
        while (True):
            more += 1
            less -= 1

            if less not in numbers:
                print(less)
                break

            if more not in numbers:
                print(more)
                break

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
X,N = map(int,input().split())
P = list(map(int,input().split()))
if N==0:print(X); exit()
diff = float('inf')
ans = X
A = {}
for p in P:
    A[p] = 1
s = X
while True:
    if s not in A:
        diff = s-X
        ans = s
        break
    else:
        s += 1
s = X
while True:
    if s not in A:
        if X-s<=diff:
            ans = s
        break
    else:
        s -= 1 
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

from itertools import count
def test():
    x, n = map(int, input().split())
    p = [int(i) for i in input().split()]
    for i in count():
        if x - i not in p:
            print(x - i)
            break
        if x + i not in p:
            print(x + i)
            break

test()

Submission status: Accepted

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

i = 0
loop = True
while loop:
	for j in range(-1*i, i+1):
		if x+j not in p:
			ans = x+j
			loop = False 
			break

	i += 1


print(ans)

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
p = sorted(list(map(int, input().split())))
if N == 0:
    print(X)
    exit()
for i in range(N):
    if X <= p[i]:
        for j in range(X+1):
            if not X-j in p[:i+1]:
                print(X-j)
                exit()
            elif j != 0 and not X+j in p[i+1:]:
                print(X+j)
                exit()
        print(0)
        exit()

Submission status: Accepted

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

L = [0] * 301

for i in P:
    L[i + 100] = 1

for i in range(100):
    if L[-i+ X +100] == 0:
        print(X - i)
        break
    if L[i+X+100] == 0:
        print(X+i)
        break

Submission status: Accepted

Solution code:
XN = input().split()

X = int(XN[0])
N = int(XN[1])

ps = input().split()
p = []

for i in range(N):
    p.append(int(ps[i]))

ans = X
ansisfound = False

if X not in p:
    ansisfound = False

for i in range(len(p)+1):
    if ansisfound:
        break
    if X + i not in p:
        ans = X + i
        ansisfound = True
    if X - i not in p:
        ans = X - i
        ansisfound = True

print(ans)

Submission status: Accepted

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


min= 100

p.sort()

for i in range(-200, 201):
  if (i not in p ) and len(p) > 0:
    a = abs(i-X)
    if a<min:
      min=a
      ans = i
print(ans)

Submission status: Accepted

Solution code:
ans=0
X,N=map(int,input().split())
p=list(map(int,input().split()))
for i in range(102):
    if i in p:
        p.remove(i)
    else:
        p.append(i)
for i in range(102-N):
    if abs(X-p[i])<abs(X-ans):
        ans=p[i]
print(ans)

Submission status: Accepted

Solution code:
import math
x,n = map(int,input().split())
p = [0]*n
if n != 0:
	p = list(map(int,input().split()))
X = x
y = x
while x in p:
	x += 1
while y in p: 
	y -= 1
if x-X >= X-y:
	print(y)
else:
	print(x)

Submission status: Accepted

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

Submission status: Accepted

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

i = 0

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

Submission status: Accepted

Solution code:
line = list(map(int,input().split()))
N = line[0]
M = line[1]
i=0
if M==0:
    print(N)
else:
    numbers = list(map(int,input().split()))
    while True:
        if bool(N-i in numbers)==0:
            print(N-i)
            break
        elif bool(N+i in numbers)==0:
            print(N+i)
            break
        i+=1

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(101):
  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:
X, N = map(int, input().split())
P = list(map(int, input().split()))

Y = X
Z = X
ans = 0
while True:
    if Y not in P:
        ans = Y
        break
    elif Z not in P:
        ans = Z
        break
    else:
        Y -= 1
        Z += 1

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()))
t = [i for i in range(0,102)]

p.sort()
diff = list(set(t) ^ set(p))

for i in range(len(diff)):
  diff[i] -= x

ans = diff[0]
for i in range(1,len(diff)):
  if abs(ans) > abs(diff[i]):
    ans = diff[i]
    
ans += x
print(ans)

Submission status: Accepted

Solution code:
x,n= map(int,input().split())
if n!=0:
    p=list(map(int,input().split()))
    p.sort()
    i=0
    while p[i]<x:
        i+=1
    if p[i]!=x:
        print(x)
    else:
        l=x-1
        h=x+1
        j=i-1
        k=i+1
        while  j>=0 and l==p[j]:
            j-=1
            l-=1
        if j==-1:
            l=p[0]-1
        while k<n and h==p[k] :
            k+=1
            h+=1
        if k==-1:
            h=p[k]-1
        if x-l<=h-x:
            print(l)
        else:
            print(h)
else:
    print(x)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
a = 0
b = 0
j = 0
while True:
    a = 0
    b = 0
    for i in range(n):
        if x-j == p[i]:
            a = 1
        if x+j == p[i]:
            b = 1
    if a == 0 and b == 0:
        print (x-j)
        break
    elif a == 0 and b == 1:
        print (x-j)
        break
    elif a == 1 and b == 0:
        print (x+j)
        break
    else:
        j = j+1
        continue

Submission status: Accepted

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

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

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

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

set = {i for i in range(x - 100, x + 100)}
for i in li:
    if i in set:
        set.remove(i)

min = 1000
for i in set:
    if abs(x - i) < min:
        min = abs(x - i)
        ans = i
print(ans)

Submission status: Accepted

Solution code:
X,N = [int(x) for x in input().split()]
p = [int(x) for x in input().split()]
if(N==0):
    print(X)
    exit()


min = 101


for i in range(101,-1,-1):
    # print("i",abs(X-i),"min",min)
    if(not (i in p) and abs(i-X) <=abs(X-min)):
        min = i
        # print("IN *******i=",i,min)


print(min)

Submission status: Accepted

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

    A = [int(i) for i in input().split()]
    C = [False] * 102
    for v in A:
        C[v] = True

    d = 1000000
    ans = 0
    for i in range(102):
        if C[i] == False:
            if d > abs(X - i):
                d = abs(X - i)
                ans = i

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
num, n = map(int,input().split())
givenlist = set(list(map(int,input().split())))
numlist = set([i for i in range(-1,102)]) - givenlist
min = 1000
for i in list(numlist):
    if abs(num-i) <= min:
        min = abs(num-i)

if num - min in numlist:
    print(num - min)
else:
    print(num + min)

Submission status: Accepted

Solution code:
# 別変数の整数複数個
X, N = [int(x) for x in input().strip().split(" ")]
if N == 0:
    P = []
else:
    P = sorted([int(x) for x in input().strip().split(" ")])

x1, x2 = X, X
while True:
    if x1 not in P:
        print(x1)
        break
    if x2 not in P:
        print(x2)
        break
    x1, x2 = x1 - 1, x2 + 1

Submission status: Accepted

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

for i in range(-105,105):
    if i not in p:
        if abs(x-i) < abs(close-x):
            close = i
        elif abs(x-i) == abs(close-x):
            close = min(close, i)

# print(i)
print(close)

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
P  = list(map(int,input().split()))
ans = 0
neko = float("inf")
for i in range(-100,102):
    if i in P:
        continue
    if neko > abs(i - x):
        neko = abs(i - x)
        ans = i
print(ans)

Submission status: Accepted

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

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

ans = [X, X]

judge = [0, 0]
while judge[0] == 0 and judge[1] == 0:
  if p.count(ans[0]) == 0:
    judge[0] = 1
    print(ans[0])
    break
  elif p.count(ans[1]) == 0:
    judge[1] = 1
    print(ans[1])
    break
  else:
    ans[0] -= 1
    ans[1] += 1

Submission status: Accepted

Solution code:
x,n = map(int, input().split())
p = input().split()
for i in range(len(p)):
    p[i] = int(p[i])
index = 0
while True:
    if p == []:
        print(x)
        break
    try:
        a = p.index(x-index)
    except ValueError:
        print(x-index)
        break

    try:
        b = p.index(x+index)
    except ValueError:
        print(x+index)
        break

    index += 1

Submission status: Accepted

Solution code:
def calc():
    x, n, *p = map(int, open(0).read().split())
    h = set(p)
    for i in range(0, n+1):
        a = x - i
        b = x + i
        if a not in h:
            return a
        if b not in h:
            return b
    return x

print(calc())

Submission status: Accepted

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

Submission status: Accepted

Solution code:
X, N = [int(v) for v in input().strip().split(" ")]
ps = input().strip()

if str(X) not in ps:
    print(X)
else:
    ps = [int(v) for v in ps.split(" ")]
    ps = sorted(ps)

    pointer = None
    for i in range(len(ps)):
        if ps[i] == X:
            pointer = i

    pre = X
    left_best = ps[0] - 1
    for i in range(pointer - 1, -1, -1):
        now = ps[i]
        if pre - now > 1:
            left_best = pre - 1
            break
        else:
            pre = now

    pre = X
    right_best = ps[-1] + 1
    for i in range(pointer, len(ps)):
        now = ps[i]
        if now - pre > 1:
            right_best = pre + 1
            break
        else:
            pre = now

    if abs(left_best - X) <= abs(right_best - X):
        print(left_best)
    else:
        print(right_best)

Submission status: Accepted

Solution code:
a=input().split()
x=int(a[0])
n=int(a[1])

if n==0:
  print(x)
else:
  b=input().split()
  il=[]
  for y in b:
    il.append(int(y))

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

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
v = 0
while True:
	if x-v not in p:
		print(x-v)
		break
	elif x+v not in p:
		print(x+v)
		break

	v += 1

Submission status: Accepted

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

    e_min=1000
    r=[]
    for i in range(100):
        if (x-i in p):
            pass
        else:
            print(x-i)
            break
        if (x+i in p):
            pass
        else:
            print(x+i)
            break
else:
    print(x)

Submission status: Accepted

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


if N == 0:
    print(X)
else:
    P = list(map(int,input().split()))
    i = 0
    while(True):
        # print(X-i)
        if X-i not in P:
            print(X-i)
            break
        elif X+i not in P:
            print(X+i)
            break
        if i > 120:
            break
        i +=1

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
s = list(map(int,input().split()))
if s==[]:
    print(x)
    exit()    
s.sort()
sa = 10**9
for i in range(102):
    if i in s:
        continue
    if sa > abs(x-i):
        sa = abs(x-i)
        ans = i
print(ans)

Submission status: Accepted

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

    if P.count(X)== 0:
        print(X)
    else:
        hi = 0
        lo = 0
        i = 1
        j = 1
        while lo == 0:
            a = X-i
            if P.count(a)==0:
                lo += 1
            else:
                i += 1
                
            
        while hi == 0:
            a =X+j 
            if P.count(a)==0:
                hi += 1
            else:
                j += 1 
                
            
        if i > j:
            print(X+j)
        elif i<j:
            print(X-i)
        else:
            print(X-i)

Submission status: Accepted

Solution code:
# coding: utf-8

import math
import re
import numpy as np
import copy


S = input().split(" ")
X = int(S[0])
N = int(S[1])

#初期値
ans = 0

#空行の場合
if N == 0:
    ans = X

else:
    pn = [int(i) for i in input().split(" ")]

    #距離の最小値の初期値
    min_dist = 1000

    #大きい数字から全探索（超える場合のみ更新）
    for i in range(102):
        if not i in pn:
            dist = abs(X - i)
            if dist < min_dist:
                ans = i
                min_dist = dist

print(ans)

Submission status: Accepted

Solution code:
import sys
A,B = list(map(int, input().split()))
P = list(map(int, input().split()))
test = [-1,1]
for i in range(100):
    for j in test:
        if( ( A + i * j) in P) is False:
            print(A+i*j)
            sys.exit()

Submission status: Accepted

Solution code:
import numpy as np

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

ret = X

for i in range(100):
  if X-i not in plist:
    ret -= i
    break
  elif X+i not in plist:
    ret += i
    break

print( ret )

Submission status: Accepted

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

ans = x
for i in range(201):
    if x - i not in data:
        ans = x - i
        break

    if x + i not in data:
        ans = x + i
        break

print(ans)

Submission status: Accepted

Solution code:
x, n = map(int, input().split(" "))
if n != 0:
  p=list(map(int, input().split(" ")))
else:
  p=[]
lst = list(range(-1, x * 2 + 1))
for i in p:
  if i in lst:
    lst.remove(i)
for i in range(x + 2):
  if x - i in lst or x - i < 0:
    print(x - i)
    break
  elif x + i in lst:
    print(x + i)
    break

Submission status: Accepted

Solution code:

x,n = map(int, input().split())
if n != 0:
    num_list = list(map(int, input().split()))
    max_num = 100
else:
    num_list = []
    max_num = 10
flag = 0
for i in range(0,max_num):
    a = x - i
    b = x + i
    # print(a, b)
    if not(a in num_list):
        print(a)
        flag = 1
        break
    if not(b in num_list):
        print(b)
        flag = 1
        break
    if flag == 1:
        break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    x, n = map(int, input().split())
    if n >0:
        a = [int(i) for i in input().split()]
        listN = [i for i in range(-10,110)]
        diffList = list(set(listN) -set(a) )
        ans = 0
        diff = 100
        for i in diffList:
            now = 0
            if i>0:
                now = abs(i-x)
            else:
                now = abs(i)+abs(x)
            if diff > now:
                diff=now
                ans =i
        print(ans)
    else:
        print(x)

Submission status: Accepted

Solution code:
import itertools
import numpy as np

X, N = list(map(int, input().split(' ')))
ps = input()
if len(ps)!=0:
    ps = list(map(int, ps.split(' ')))

ps_sort = list(sorted(ps))
not_in_ps = np.array([[abs(i-X), i] for i in range(-1, 102) if i not in ps_sort])
print(not_in_ps[np.argmin(not_in_ps[:,0], 0), 1])

Submission status: Accepted

Solution code:
X,N = map(int, input().split())
if N ==0:
  print(X)
  exit() 
if N !=0:
  p = list(map(int, input().split()))
if p.count(X) == 0:
  print(X)
  exit()
for a in range(1000):
  if p.count(X-a) ==0:
    print(X-a)
    exit()
  elif p.count(X+a) ==0:
    print(X+a)
    exit()

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
P = [int(x) for x in input().split()]
cand = 1000
ans = -100
for t in range(-100, 121):
    if not(t in P):
        if abs(t-X) < cand:
            cand = abs(t-X)
            ans = t
print(ans)

Submission status: Accepted

Solution code:
import math

a = [int(i) for i in input().split()]
if a[1] != 0:
    b = [int(i) for i in input().split()]
else:
    b = []


suu = 0
hik=math.inf
tas=math.inf
while True:
    if a[0]-suu not in b:
        hik = a[0]-suu
        break
    
    if a[0]+suu not in b:
        tas = a[0]+suu
        break
    
    suu+=1

if tas == math.inf:
    print(hik)
else:
    print(tas)

Submission status: Accepted

Solution code:
import numpy as np
X,N = map(int,input().split())
a = 0
if N != 0:
    P = [int(i) for i in input().split()]
    for p in range(0,len(P)+1):
        if X-p not in P:
            print(X-p)
            break
        elif X+p not in P:
            print(X+p)
            break
else:
    print(X)

Submission status: Accepted

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


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

if not p:
    print(x)
    sys.exit()
    
for i in range(n+1):
    if x-i not in p:
        print(x-i)
        break
    elif x+i not in p:
        print(x+i)
        break
    else:
        continue

Submission status: Accepted

Solution code:
def main():
    X, N = map(int, input().split())
    p = list(map(int,input().split()))
    p.sort()
    p2 = []
    judge = 1000
    temp = 1000
    ans = 1000

    for i in range (-1,102):
        if i in p:
            continue
        else:
            p2.append(i)

    for j in p2:
        temp = abs(X - j)
        if temp < judge:
            judge = temp
            ans = j

    return ans

print(main())

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(-100,102):
    if i not in p and temp > abs(X - i):
        temp = abs(X-i)
        result = i
print(result)

Submission status: Accepted

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

la = list(range(102))

for i in l:
    la.remove(i)

ans = la[0]
d = 200
for i in la:
    if d > abs(i-x):
        d = abs(i-x)
        ans = i

print(ans)

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
if n!=0:
  li=list(map(int,input().split()))
  si=list(range(-10,130))

  for k in li:
    si.remove(k)
  li=si  
  li=sorted(li,reverse=True)
  sa=150
  ans=0
  for i in li:
    mi=abs(i-x)
    sa=min(mi,sa)
    if mi==sa:
      ans=i

  print(ans)
else:
  print(x)

Submission status: Accepted

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


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

Submission status: Accepted

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

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

for i in range(-200, 200):
    if(not i in p):
        if((abs(x-ans) > abs(x-i)) or(abs(x - ans) == abs(x - i) and i < ans)):
            ans = i

print(ans)

Submission status: Accepted

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

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

alist = list(range(-200,200))
for i in plist:
    alist.remove(i)

alist.sort()
alist.reverse()
ans = 0
count = 1000
for j in alist:
    if count >= abs(x - j):
        count = abs(x-j)
        ans = j

print(ans)

Submission status: Accepted

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

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

import numpy as np
p = np.array(list(map(int, input().split())))
p = p-X

for i in range(100):
  if i in p and -1*i in p:
    continue
  if -1*i not in p:
    print(X-i)
    break
  else:
    print(X+i)
    break

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
try:
  lst = list(map(int, input().split()))
except:
  lst = []
  
flg = 0
if x not in lst or lst == []:
  print(x)
else:
  for _ in range(1, 101):
    mx = max(x - _, 0)    
    mn = min(x + _, 101)
    if mx not in lst:
      print(mx)
      break
    elif mn not in lst:
      print(mn)
      break

Submission status: Accepted

Solution code:
X,N=map(int,input().split())
if N==0:
  print(X)
  exit()
n=list(map(int,input().split()))
if X<min(n) or X>max(n):
  print(X)
  exit()

key=min(n)-1
Key=max(n)+1
l=list(range(key,Key+1))
ll=[x for x in l if x not in n]
ll.append(X)
ll.sort()
i=ll.index(X)
if abs(X-ll[i-1])>abs(X-ll[i+1]):
  print(ll[i+1])
else:
  print(ll[i-1])

Submission status: Accepted

Solution code:
x,n = (int(x) for x in input().split())
la = list(map(int, input().split()))
lb = list(range(0,102))
li = list(filter(lambda y: y not in la, lb))
ld = [abs(x-a) for a in li]
s = ld.index(min(ld))
print(li[s])

Submission status: Accepted

Solution code:
import sys

x, n = map(int, sys.stdin.readline().split())
if not n:
    print(x)
    exit()

p = list(map(int, sys.stdin.readline().split()))

p.sort(key = lambda item: (abs(x-item), item))

if p[0] != x:
    print(x)
    exit()

# print(p)

j = 1
for i in range(1, 2 + n // 2):
    if j == n or p[j] != x - i:
        print(x - i)
        exit()
    j += 1

    if j == n or p[j] != x + i:
        print(x + i)
        exit()
    j += 1

print(x)

Submission status: Accepted

Solution code:
def solve():
    X, N = map(int, input().split())
    P = list(map(int, input().split()))
    ans = 0
    for i in range(101):
        if X-i not in P:
            ans = X-i
            break
        if X+i not in P:
            ans = X+i
            break
    return ans
print(solve())

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
lst = list(map(int,input().split()))
i = 0
j = 0
while True :
    if x + i not in lst or x + j not in lst :
        if x + j not in lst :
            print(x+j)
            break
        else :
            print(x+i)
            break
    i += 1
    j -= 1

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
h = list(map(int, input().split()))
ans = []
for i in range(0, N+1):
    if X+i not in h:
        ans.append(X+i)
    if X-i not in h:
        ans.append(X-i)
    if ans != []:
        break
print(min(ans))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
X, N = map(int, input().split())

if N == 0:
    print(X)
else:
    p_list = list(map(int, input().split()))
    ans_list = [X]
    for i in range(1, 51):
        ans_list.append(X - i)
        ans_list.append(X + i)

    for i in range(len(ans_list)):
        if p_list.count(ans_list[i]) == 0:
            print(ans_list[i])
            break

Submission status: Accepted

Solution code:
x,n = map(int, input().split())
p = list(map(int, input().split()))
mini = 1000
for i in range(-200,200):
    if not i in p:
        if mini>abs(x-i):
            ans = i
            mini=abs(x-i)
print(ans)

Submission status: Accepted

Solution code:
X,N = map(int,input().split())
if N == 0:
  print(X)
  exit()
A = list(map(int,input().split()))
for i in range(N*2):
  if (X - i) not in A:
    print(X-i)
    exit()
  elif (X + i ) not in A:
    print(X+i)
    exit()