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

i=j=x

while i in l:
    i += 1
while j in l:
    j -= 1

if abs(x-i) < abs(x-j):
    print(i)
else:
    print(j)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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))
    break
  elif (X + i) not in p:
    print((X + i))
    break
  i += 1

Submission status: Accepted

Solution code:
from collections import defaultdict

x,n = map(int,input().split())
if n==0:
    print(x)
else:
    dd = defaultdict(int)
    arr = list(map(int,input().split()))
    for i in range(len(arr)):
        dd[x-arr[i]]+=1

    for i in range(101):
        if dd[i]==0:
            print(x-i)
            break
        elif dd[-i]==0:
            print(x+i)
            break

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p_l = list(map(int, input().split()))
p_l.sort()
if p_l == [] :
    print(x)
else :
    ans = [x, x]
    while True :
        if ans[0] not in p_l :
            print(ans[0])
            break
        elif ans[1] not in p_l :
            print(ans[1])
            break
        else :
            ans[0] -= 1
            ans[1] += 1

Submission status: Accepted

Solution code:
from bisect import bisect_left

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


if N == 0:
    print(X)

else:
    plist.sort()
    not_plist = [x for x in range(plist[0]-1, plist[-1]+2, 1)  if x not in plist]
    idx = bisect_left(not_plist, X)

    if idx == 0:
        print(X)

    elif idx == len(not_plist):
        print(X)

    else:
        left = X - not_plist[idx-1]
        right = not_plist[idx] - X
        if left <= right:
            print(not_plist[idx-1])
        else:
            print(not_plist[idx])

Submission status: Accepted

Solution code:
def solve(x, n, nums):
	if not nums or x not in nums:
		return x
	a = x - 1
	b = x + 1
	while True:
		if a not in nums:
			return a
		if b not in nums:
			return b
		a -= 1
		b += 1

x, n = map(int, input().split())
A = None
if n > 0:
	A = set(list(map(int, input().split())))
print(solve(x, n, A))

Submission status: Accepted

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

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

i = 1
while True:
    low_x = x - i
    if low_x not in p_list:
        print(low_x)
        break
    
    high_x = x + i
    if high_x not in p_list:
        print(high_x)
        break

    i += 1

Submission status: Accepted

Solution code:
#cited from ppunchi
X, N = map(int, input().split())
p = list(map(int, input().split()))
l = X - 1
r = X + 1
if not X in p:
    print(X)
    exit()
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:
import numpy as np
X, N = map(int, input().split())
if N == 0:
    print(X)
else:
    l = list(map(int, input().split()))
    app = [x for x in range(X - int(N / 2) - 1, X + int(N / 2) + 1) if x not in l]
    print(app[np.argmin([abs(x - X) for x in app])])

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
try:
	p_li = list(map(int, input().split()))
except:
	print(x)
	exit()

for i in range(100000):
	
	if not((x - i) in p_li):
		print(x - i)
		break
	
	if not((x + i) in p_li):
		print(x + i)
		break

Submission status: Accepted

Solution code:
if __name__=="__main__":
    X,N = list(map(int,input().split()))
    p = list(map(int,input().split()))
    for i in range(X+1):
        for j in [-1,1]:
            a = X + i*j
            if not (a in p):
                print(a)
                exit(0)

Submission status: Accepted

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

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

mi = 1000
ans = x
for i in range(105):
    for j in range(n):
        if p[j] == i:
            break
        if j == n - 1:
            if abs(x - i) < mi:
                mi = abs(x - i)
                ans = i
print(ans)

Submission status: Accepted

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

for i in range(101):
  xl = x - i
  xr = x + i
  if xl not in P:
    print(xl)
    break
  if xr not in P:
    print(xr)
    break

Submission status: Accepted

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

array=list(map(int,input().split()))
P=[]
for i in array:
    P.append(i)

if not X in P:
    best=X
else:
    i=1
    while True:
        if not X-i in P:
            best=X-i
            break
        if not X+i in P:
            best=X+i
            break
        i+=1

print(best)

Submission status: Accepted

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

for i in range(102):
  xl = x - i
  xr = x + i
  if xl not in P:
    print(xl)
    break
  elif xr not in P:
    print(xr)
    break

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
liste=[int(x) for x in input().split()]
roger = x

while True:
    if liste.count(x)==0:
        print(x)
        break
    if liste.count(roger)==0:
        print(roger)
        break

    x -=1
    roger+=1

Submission status: Accepted

Solution code:
X, N = map(int,input().split())
P = list(map(int,input().split()))
Q =[]
for i in range(-1,102):
    Q.append(i)
A = list(set(Q) - set(P))
min = 200
ans = 1000
for i in range(len(A)):
    if abs(X - A[i]) < min:
        min = X - A[i]
        ans = A[i]
print(ans)

Submission status: Accepted

Solution code:
mod = int(1e9+7)
def add(a, b):
    c = a + b
    if c >= mod:
        c -= mod
    return c

def main():
    INF = 1e9+7
    
    x, n = map(int,raw_input().split())
    
    arr = map(int,raw_input().split())
    
    s = set(arr)
    
    ret = INF
    
    for num in range(102):
        if num not in s:
            diff = abs(num - x)
            ret_diff = abs(ret - x)
            if diff < ret_diff:
                ret = num
            elif diff == ret_diff and num < ret:
                ret = num
    
    print(ret)
    

main()

Submission status: Accepted

Solution code:
from sys import stdin,stdout
LI=lambda:list(map(int,input().split()))
MAP=lambda:map(int,input().split())
IN=lambda:int(input())
S=lambda:input()
import math
from collections import Counter,defaultdict


x,n=MAP()
if n==0:
    print(x)
    exit()
a=LI()
l=-1;r=-1
for i in range(101):
    if x-i not in a:
        l=x-i
        break
for i in range(101):
    if x+i not in a:
        r=x+i
        break
if abs(r-x)>=abs(l-x):
    print(l)
else:
    print(r)

Submission status: Accepted

Solution code:
from sys import stdin,stdout
LI=lambda:list(map(int,input().split()))
MAP=lambda:map(int,input().split())
IN=lambda:int(input())
S=lambda:input()
import math
from collections import Counter,defaultdict


x,n=MAP()
if n==0:
    print(x)
    exit()
a=LI()
l=-1;r=-1
for i in range(1000):
    if x-i not in a:
        l=x-i
        break
for i in range(1,101):
    if x+i not in a:
        r=x+i
        break
if abs(r-x)>=abs(l-x):
    print(l)
else:
    print(r)

Submission status: Accepted

Solution code:
import os
import sys
from atexit import register
from io import BytesIO
sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
sys.stdout = BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))
input = lambda: sys.stdin.readline().rstrip('\r\n')
raw_input = lambda: sys.stdin.readline().rstrip('\r\n')

x,n = (int(a) for a in input().split())
seq = set((int(i) for i in input().split()))
i = 0
while True:
    if x - i not in seq:
        ans = x-i
        break
    if x + i not in seq:
        ans = x + i
        break
    i += 1
print(ans)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
i, ans = 0, 0
a = 1
while a:
    if x not in p: print(x); break
    for i in range(max(p)+2):
        if x+i not in p:
            if x-i not in p:
                ans=x-i
                break
            ans=x+i
            break
        if x-i not in p:
            ans=x-i
            break
    print(ans)
    a = 0

Submission status: Accepted

Solution code:
import sys
x,n = map(int,input().split())
l = list(map(int,input().split()))
not_l,ans = [],[]
if not x in l:
	print(x)
	sys.exit()
l = sorted(l)
for i in range(0,max(l)+3):
	if not i in l:
		not_l.append(i)
for j in range(len(not_l)):
	ans.append([not_l[j],abs(not_l[j]-x)])
ans.sort(key=lambda x:x[1])
print(ans[0][0])

Submission status: Accepted

Solution code:
def main():
  X,N = list(map(int, input().split()))
  P = list(map(int, input().split()))
  #allowed elements
  Q = set([i for i in range(0,101+1)])
  for p in P:
    Q.remove(p)
  Q = sorted(Q)
  # distance from X
  D = [abs(q-X) for q in Q]
  # find smallest minimizer
  minD = min(D)
  for d,q in zip(D,Q):
    if d==minD:
      break
  print(q)
    
if __name__=='__main__':
  main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:

from collections import Counter
a,b=list(map(int,input().split()))
m=list(map(int,input().split()))
#m.sort()
c=[]
for i in range(b):
    c.append(abs(m[i]-a))
c=Counter(c)

if b>0:
    i=0
    while i<=b:
        if i not in c:
            print(a-i)
            break
        
        elif c[i]<2 and i!=0:
            if a-i in m:
                print(i+a)
            else:
                print(-i+a)
            break
        i+=1
else:
    print(a)

Submission status: Accepted

Solution code:
X, N = map(int, input().split()) 
p = list(set(range(-100,150)).difference(map(int, input().split())))[::-1]

abs_num = abs(X - 150)
result = 100

for x in p:
  tmp_abs = abs(X - x)
  if tmp_abs <= abs_num:
    abs_num = tmp_abs
    result = x
    
print(result)

Submission status: Accepted

Solution code:
x,n = map(int, input().split())
st = set(list(map(int, input().split())))
incr = 0
ans = 0
while True:
    now = x - incr
    if now not in st:
        ans = now
        break
    now = x + incr
    if now not in st:
        ans = now
        break
    incr += 1
print(ans)

Submission status: Accepted

Solution code:
x,n = map(int, input().split())
lst = list(map(int, input().split()))[:n]
incr = 0
ans = 0
while True:
    found = True
    now = x-incr
    for ele in lst:
        if now == ele:
            found = False
    if found == True:
        ans = now
        break
    found = True
    now = x + incr
    for ele in lst:
        if now == ele:
            found = False
    if found == True:
        ans = now
        break
    incr = incr + 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

ans=0
for i in range(100):
  if X-i not in p:
    ans=X-i
    break
  elif X+i not in p:
    ans=X+i
    break

print(ans)

Submission status: Accepted

Solution code:
x,n = list(map(int,input().split()))
if n > 0:
  arr = list(map(int,input().split()))

ans = x
diff = 10**3

for i in range(101,-2,-1):
  if n > 0:
    if not i in arr:
      if abs(x-i) <= diff:
        diff = abs(x-i)
        ans = i
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
ii = lambda:int(input())
mi = lambda:list(map(int,input().split()))
ix = lambda x:list(input() for _ in range(x))
mix = lambda x:list(mi() for _ in range(x))
iix = lambda x:list(int(input()) for _ in range(x))
##########

def resolve():
    x,n = mi()
    p = mi()

    for d in range(x+1):
        for o in [-1,1]:
            val = x + o*d
            if val not in p:
                print(val)
                return

if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
from sys import exit
x, n = map(int, input().split())
if n == 0:
    print(x)
    exit()
np = {i for i in range(0, 102)} - set(map(int, input().split()))
t = len(np)
d = 100
for _ in range(t):
    i = np.pop()
    if d > abs(x - i):
        d = abs(x - i)
        ans = i
print(ans)

Submission status: Accepted

Solution code:
from sys import exit
x, n = map(int, input().split())
if n == 0:
    print(x)
    exit()
s = {i for i in range(0, 102)}
np = s - set(map(int, input().split()))
t = len(np)
d = 100
ans = 0
for _ in range(t):
    i = np.pop()
    if d > abs(x - i):
        d = abs(x - i)
        ans = i
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
data = stdin.readlines()

x = int(data[0].split()[0])
n = int(data[0].split()[1])
if n >= 1:
    p = [int(s) for s in data[1].split()]
else:
    p = []

if x in p:
    for i in range(1,100):
        if x-i in p:
            if x+i in p:
                continue
            else:
                print(x+i)
                break
        else:
            print(x-i)
            break
else:
    print(x)

Submission status: Accepted

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

if N==0:
  print(X)
else:
  P = list(map(int,input().split()))
  hash_p = [0]*102
  for i in P:
    hash_p[i] += 1
  for i in range(N+1):
    if hash_p[X-i]==0:
      print(X-i)
      break
    if hash_p[X+i]==0:
      print(X+i)
      break

Submission status: Accepted

Solution code:
import numpy as np
#from numba import njit

def getVar():
    return map(int, input().split())
def getArray():
    return np.array(list(map(int, input().split())))

(X,N) = getVar()
p = getArray()

if (len(p) == 0):
  print(X)
else:
  subp = p - X
  i = 0
  while (True):
    if (not -i in subp):
      print(X - i)
      break
    if (not i in subp):
      print(X + 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()))

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

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()
    if x+i not in P:
        print(x+i)
        exit()

Submission status: Accepted

Solution code:
import numpy as np

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

else:
    p = list(map(int, input().split()))
    main = set(np.arange(102))
    main = main - set(p)

    main1 = abs(np.array(list(main)))
    idx = abs(main1 - X).argmin()
    print(main1[idx])

Submission status: Accepted

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

dif = float("INF")
ans = 0

for i in range(102):
    if i not in lst:
        if dif>abs(i-x):
            dif = abs(i-x)
            ans = i
        elif dif==abs(i-x):
            ans = min(ans,i)

print(ans)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = set(map(int, input().split()))
ans = -1
d = float("inf")

for i in range(101, -1, -1):
    if i in p: continue
    c = abs(x-i)
    if c <= d:
        ans = i
        d = c

print(ans)

Submission status: Accepted

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

try:
  p = set(map(int, input().split()))
  num = set(range(-100,201))
  mem = []

  ref = sorted(list(num - p))

  for item in ref:
    mem.append(abs(item - X))
  
  print(ref[mem.index(min(mem))])

except EOFError:
  print(X)

Submission status: Accepted

Solution code:
def main():
	a,b = map(int,input().split())
	h = list(map(int,input().split()))
	av = 0
	i = 1
	while av == 0:
		if b ==0:
			print(a)
			break
		elif a not in h:
			print(a)
			break
		plus = a+i
		minus = a-i
		if minus not in h:
			print(minus)
			av = 1
		elif plus not in h:
			print(plus)
			av = 1
		else:
			i += 1


if __name__ == '__main__':
	main()

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import sys
x, n = map(int, input().split())
if n == 0:
    print(x)
    sys.exit()
p = [int(x) for x in input().split()]


diff = 0
while(True):
    if not x + diff in p:
        print(x+diff)
        sys.exit()

    if diff < 0:
        diff *= -1
    else:  # 0以上
        diff *= -1
        diff -= 1

Submission status: Accepted

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

d, ans = 100000, -1
for i in range(-200, 200):
    if i in p:
        continue

    t = abs(i-x)
    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)
    exit()

p = list(map(int, input().split()))
for i in range(100):
    if not x-i in p:
        print(x-i)
        exit()
    elif not x+i in p:
        print(x+i)
        exit()

Submission status: Accepted

Solution code:
import numpy as np

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

p = np.array(list(map(int, input().split())))
for i in range(100):
    if not x-i in p:
        print(x-i)
        exit()
    elif not x+i in p:
        print(x+i)
        exit()

Submission status: Accepted

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

try:
  p = list(map(int,input().split()))
except EOFError:
  p = []

ab=10**18
ans=ab
for i in range(101):
  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())
nums = list(map(int, input().split()))

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

dif = 0

while True:
  if (x - dif) not in nums:
    print(x - dif)
    break
  if (x + dif) not in nums:
    print(x + dif)
    break
  dif += 1

Submission status: Accepted

Solution code:
x,n = input().split()
x=int(x)
lst=input().split()
diff = 200
for i in range(-1, 102):
    if str(i) not in lst and abs(i-x) < diff:
        diff = abs(i-x)
        ans = i
print(ans)

Submission status: Accepted

Solution code:
x,n=input().split()
x=int(x)
n=int(n)
lst=input().split()
for i in range(0,n):
    lst[i]=int(lst[i])
if n==0:
    print(x)
else:
    minv=min(lst)
    maxv=max(lst)
    dis=100000

    for i in range(minv-2,maxv+3):
        if(i not in lst and abs(i-x)<dis):
            dis=abs(i-x)
            clv=i
            
    print(clv)

Submission status: Accepted

Solution code:
x,n = input().split()
x=int(x)
list=input().split()
diff = 200
for i in range(-1, 102):
    if str(i) not in list and abs(i-x) < diff:
        diff = abs(i-x)
        ans = i
print(ans)

Submission status: Accepted

Solution code:
x,n = input().split()
x=int(x)
n=int(n)
list=input().split()
for i in range(0, len(list)):
    list[i] = int(list[i])
diff = 200
for i in range(-1, 102):
    if i not in list and abs(i-x) < diff:
        diff = abs(i-x)
        ans = i
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

for i in range(n//2 +2):
    if x-i not in s:
        print(x-i)
        exit(0)
    if x+i not in s:
        print(x+i)
        exit(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
lst = []
if n > 0:
  lst = list(map(int, input().split()))
a = 100
b = 0

for i in range(0, 102):
  if i in lst:
    continue

  if a > abs(x-i):
    a = abs(x-i)
    b = i

print(b)

Submission status: Accepted

Solution code:
def main():
    x, n = map(int, input().rstrip().split(' '))
    if n == 0:
        print(x)
        return
    p = list(map(int, input().rstrip().split(' ')))
    if x not in p:
        print(x)
        return
    for i in range(1, 101):
        j, k = x - i, x + i
        # print(j, k)
        if j not in p:
            print(j)
            return
        if k not in p:
            print(k)
            return
    
    

if __name__ == '__main__':
    main()

Submission status: Accepted

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

for i in range(x+1):
    for d in [-1,1]:
        a=x+i*d
        if not a in p:
            print(a)
            exit()

Submission status: Accepted

Solution code:
#!/usr/bin/python3
import sys
input = lambda: sys.stdin.readline().strip()
x, n = [int(x) for x in input().split()]
p = [int(x) for x in input().split()]
for i in reversed(range(0, x + 1)):
    if i not in p:
        lt = i
        break
for i in range(x + 1, 102):
    if i not in p:
        gt = i
        break
print(lt if abs(lt - x) <= abs(gt - x) else gt)

Submission status: Accepted

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

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

Submission status: Accepted

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

for i in range(x+1):
    for j in [-1, +1]:
        num = x+i*j
        if num not in p:
            print(num)
            exit()

Submission status: Accepted

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

ans = x
if ans in lst:
    pass
else:
    print(ans)
    exit()

left,right = ans-1,ans+1

while True:
    if left in lst and right in lst:
        left -=1
        right += 1

    elif left in lst:
        print(right)
        exit()

    else:
        print(left)
        exit()

Submission status: Accepted

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

min_value = 101
v = 0

if X in lst:
  for i in range(200):
    if not (i in lst):
      if abs(X - i) < min_value:
        min_value = abs(X - i)
        v = i
else:
  v = X
       

print(v)

Submission status: Accepted

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

minv=101
v=0

if X in P:
  for i in range(200):
    if not(i in P):
      if abs(X-i) < minv:
        minv=abs(X-i)
        v=i
else:
  v=X
       

print(v)

Submission status: Accepted

Solution code:
s=[]
x,n=map(int,input().split())
if n==0:
  print(x)
  exit()
  
s=list(map(int,input().split()))
slist=sorted(s)
out=0
for i in range(0,1000):
  out=0
  for j in range(n):
    if slist[j]==x-i:
      out=1
  if out !=1:
   print(x-i)
   exit()
  out=0
  for k in range(n):
    if slist[k]==x+i:
      out=1
  if out !=1:
    print(x+i)
    exit()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# atcoder 
# Türkler var mı?
# Herkese memnün oldum
import sys

iimr = lambda: map(int, sys.stdin.readline().rstrip().split())
readline = sys.stdin.readline
sys.setrecursionlimit(10 ** 8)


def 関数(x, n, p_liste):
    if n == 0:
        return x
    
    if x not in p_liste:
        return x
    chikai = x-1
    plus = x + 1

    for _ in range(0,101):
        #print(p_liste)
        if chikai not in p_liste:
            return chikai
        elif plus not in p_liste:
            return plus
        else: 
            plus += 1
            chikai -= 1
    return "問題"

def çözmek():
    X,N = map(int,sys.stdin.readline().split())
    P_liste = list(map(int, sys.stdin.readline().split()))

   
    res = []
    res.append(関数(X,N,P_liste))
    print(*res, sep="\n")

if __name__ == "__main__":
    çözmek()

Submission status: Accepted

Solution code:
import sys
X, N = map(int, input().split())
p = list(map(int, input().split()))
for d in range(X + 1):
    for s in [-1, +1]:
        a = X + s * d
        if p.count(a) == 0:
            print(a)
            sys.exit(0)

Submission status: Accepted

Solution code:
X, N = map(int, input().split(' '))
if N != 0:
    P_n = list(map(int, input().split(' ')))

    for i in range(X, 150):
        if i not in set(P_n):
            min_1 = i
            break
    for i in range(X, -150, -1):
        if i not in set(P_n):
            min_2 = i
            break
    if abs(min_1-X) == abs(min_2-X):
        print(min(min_1, min_2))
    elif abs(min_1-X) < abs(min_2-X):
        print(min_1)
    else:
        print(min_2)
else:
    print(X)

Submission status: Accepted

Solution code:
N,M = list(map(int,input().split()))
A = list(map(int,input().split()))
  
for i in range(100):
  if N-i not in A:
    print(N-i)
    exit()
  elif N+i not in A and N+i!=N-i:
    print(N+i)
    exit()

Submission status: Accepted

Solution code:
x,n = map(int, input().split())
p = set(map(int, input().split()))
ans = set(range(102))
ans = sorted(list(ans - p))
now = 110
a = 0
for i in ans:
  if abs(x-i) < now:
    a = i
    now = abs(x-i)
print(a)

Submission status: Accepted

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

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

n=set(n for n in range(-100,102))

pd=list(n-p)

min1=1000

for i in range(len(pd)):
    if abs(pd[i]-x)<abs(min1-x):
        min1=pd[i]
    elif abs(pd[i]-x)==abs(min1-x):
        min1=min(pd[i],min1)
print(min1)

Submission status: Accepted

Solution code:
x,n = map(int, input().split())
seisuu_list = list(map(int, input().split()))
seisuu_list.sort()
if seisuu_list == []:
    print(x)
#print(seisuu_list)

for i in range(1,n+1):
    if i%2 != 0:
        i = -1*i
    #print(i)
    if x in seisuu_list:
        x += i
        if x in seisuu_list:
            continue
        else:
            print(x)
            exit()
    else:
        print(x)
        break

Submission status: Accepted

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

for i in range(0, x+100):
    for j in [-1, 1]:
        temp = x + (i*j)
        if ps.count(temp) == 0:
            ans = temp
            break
    else:
        continue
    break


print(ans)

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
A = []
if N != 0:
  A = list(map(int, input().split()))
dp = [abs(X-i) for i in range(102)]
for i in range(N):
  dp[A[i]] = int(1e18)
m = int(1e18)
M = 102
for i in range(102, 0, -1):
  if m >= dp[i-1]:
    m = dp[i-1]
    M = i - 1
print(M)

Submission status: Accepted

Solution code:
import math
X,N = map(int, input().split())
p = list(map(int, input().split()))
i = 0
while 1:
    if (X-i in p) == False:
        print(X-i)
        break
    elif (X+i in p) == False:
        print(X+i)
        break
    i += 1

Submission status: Accepted

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


m = 100
ans=100

for i in  range(0,103):
    if(i in p):
        continue

    elif(abs(i-x) < m):
        m = abs(i-x)
        ans = i

print(ans)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
ps = list(map(int, input().split()))
pss = [i for i in range(-1000, 1000)]
ps = list(filter(lambda i: i not in ps, pss))
ans = x

for i, p in enumerate(ps):
    temp = abs(x-p)
    if i == 0:
        mins = temp
        ans = p
    else:
        if mins > temp:
            mins = temp
            ans = p
        elif mins == temp:
            if ans > p:
                ans = p

print(ans)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
lst = list(map(int, input().split()))
is_exist = [False] * 120
for i in lst:
    is_exist[i] = True
ans = 0
diff = 0
while True:
    if is_exist[x - diff] == False:
        ans = x - diff
        break
    elif is_exist[x + diff] == False:
        ans = x + diff
        break
    diff += 1
print(ans)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
try:
  list_P = [int(p) for p in input().split()]
  list_not_P = [x for x in range(102) if not x in list_P]
  list_abs = [abs(x - i) for i in list_not_P]
  Index = list_abs.index(min(list_abs))
  print(list_not_P[Index])
except EOFError:
  print(x)

Submission status: Accepted

Solution code:
X,N = map(int,input().split())
l = list(map(int,input().split()))
n_l = sorted(l)

for i in range(100):
  if not X-i in n_l:
      print(X-i)
      break
  elif not X+i in n_l:
      print(X+i)
      break
  pass

Submission status: Accepted

Solution code:
x,n= map(int,input().split(' '))
if n!=0:
    arr= list(map(int,input().split(' ')))
    for j in range(x+1):
        for i in range(-1,2):
            if arr.count(x+i*j)==0:
                print(x+i*j)
                exit(0)
else:
    print(x)

Submission status: Accepted

Solution code:
x,n=[int(i) for i in input().split()]
arr=[int(i) for i in input().split()]
ele=set()
for i in arr:
    ele.add(i)
left=x
rigth=x
while True:
    if rigth not in ele and left not in ele:
        print(min(rigth,left))
        break
    if left not in ele:
        print(left)
        break
    if rigth not in ele:
        print(rigth)
        break
    left-=1
    rigth+=1

Submission status: Accepted

Solution code:
x,n= map(int,input().split())
p = set(map(int,input().split()))
for i in range(101):
   a,b = x-i,x+i
   if a not in p:
      print(a)
      break
   if b not in p:
      print(b)
      break