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:
from bisect import bisect

X, N = [int(n) for n in input().split()]
if N==0:
    print(X)
else:
    P = sorted([int(n) for n in input().split()])
    if X not in P:
        print(X)
        exit()
    idx = bisect(P, X)
    ans_r = 101
    ans_l = 0
    for i in range(P[idx-1], 101):
        if i not in P:
            ans_r = i
            break
    for j in range(1, P[idx-1]):
        if j not in P:
            ans_l = j
    if abs(X-ans_l) == abs(ans_r-X):
        print(min([ans_l, ans_r]))
    else:
        print(ans_l if abs(X-ans_l) < abs(ans_r-X) else ans_r)

Submission status: Accepted

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

for i in range(0,102):
    if (i in p):
        continue
    else:
        tmp=(x-i)**2
        if tmp<ans:
            ans=tmp
            c=i
print(c)

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
if n==0:
    print(x)
    exit()
elif n==100:
    if abs(-1-x)<=abs(101-x):
        print(0)
    else:
        print(101)
    exit()
List=list(map(int,input().split()))
num=list(range(0,102))
min_num=1000000000
for i in range(len(List)):
    if num.count(List[i])>=1:
        num.remove(List[i])
for i in range(len(num)):
    if (abs(num[i]-x)<abs(min_num-x)) or (abs(num[i]-x)==abs(min_num-x) and num[i]<min_num):
        min_num=num[i]
print(min_num)

Submission status: Accepted

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

table = [0 for i in range(102)]
for i in p:
    table[i] = 1

mx = 10000
ans = mx
dis = mx
for i in range(len(table)):
    idx = 101-i
    if (table[idx] == 0) and (dis >= abs(idx-x)):
        ans = idx
        dis = abs(idx-x)
print(ans)

Submission status: Accepted

Solution code:
c,x = map(int,input().split())
if not x:
    print(c)
    exit()
a = list(map(int,input().split()))
s = list(range(0,105))
for i in a:
    s.remove(i)

diffB = 99999
n = 9999

for i in s:
    if diffB > abs(c-i):
        diffB = abs(c-i)
        n = i
print(n)

Submission status: Accepted

Solution code:
import sys

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

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

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

for i in range(1000):
    m = X - ((i//2 +1) * (-1)**i)
    if m not in p:
        print(m)
        break

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
p = list(map(int,input().split()))
ans = []
i = 1
if x not in p:
  print(x)
else:
  while len(ans)==0:
    if x+i not in p and x-i not in p:
      ans.append(x+i)
      ans.append(x-i)
    elif x+i not in p:
      ans.append(x+i)
    elif x-i not in p:
      ans.append(x-i)
    else:
      i+=1
  print(min(ans))

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin

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

x, n= na()
p = na()
a = x
b = x
for i in range(100):
  if (b in p) == False:
    print(b)
    break
  elif (a in p) == False:
    print(a)
    break
  else:
    a = a+1
    b = b-1

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

Submission status: Accepted

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

kouho = list(range(-200, 200))


for i in range(len(p)):
  if p[i] != x:
    del kouho[kouho.index(p[i])]

kouho_num = kouho.index(x)
right = kouho_num + 1
left = kouho_num - 1

if (x not in p):
  print(x)
elif abs(kouho[right] - kouho[kouho_num]) > abs(kouho[kouho_num] - kouho[left]):
  print(kouho[left])
elif abs(kouho[right] - kouho[kouho_num]) == abs(kouho[kouho_num] - kouho[left]):
  print(kouho[left])
else:
  print(kouho[right])

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
x,n=map(int,input().split())
if n==0:
    print(x)
else:
    p=list(map(int,input().split()))
    d=0
    while True:
        if x-d in p:
            if x+d in p:
                d+=1
            else:
                a=x+d
                break
        else:
            a=x-d
            break
    print(a)

Submission status: Accepted

Solution code:
X,N = map(int, input().split())
array = list(map(int, input().split()))
ans_l = [X]


x  = (N % 2)
if x == 0:
    n = N // 2
else:
    n = N // 2 + 1
i = 1

while i <= n:
    ans_l.append(X - i)
    ans_l.append(X + i)
    i += 1
l = len(array)

for j in range(l):
    try:
        ans_l.remove(array[j])
    except ValueError:
        pass
print(ans_l[0])

Submission status: Accepted

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

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

    p_ = [abs(x - n) for n in p]

    m_p_ = p_.index(min(p_))

    start = p[m_p_]

    for v in range(100):
        a = start - v - 1
        b = start + v + 1
        if (a not in p) and (b in p):
            ans = a
            break

        elif (a in p) and (b not in p):
            ans = b
            break
            
        elif (a not in p) and (b not in p):
            if a > b:
                ans = b
                break
            else:
                ans = a
                break
                
else:
    ans = x
    
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

if N == 0: print(X)
else:
    p.sort()
    if X in p:
        index = p.index(X)
        c = 1
        while True:
            if index - c >= 0 and p[index - c] != X - c:
                print(X - c)
                break
            elif index - c < 0:
                print(X - c)
                break
            elif index + c >= N:
                print(X + c)
                break
            elif index + c < N and p[index + c] != X + c:
                print(X + c)
                break
            else:
                c += 1

    else: print(X)

Submission status: Accepted

Solution code:
X,N = map(int,input().split())
p = list(map(int,input().split()))
xp = X
xm = X
for i in range(101):
  if (xp not in p) and (xm not in p):
    print(min(xp,xm))
    break
  if xp not in p:
    print(xp)
    break
  if xm not in p:
    print(xm)
    break
  xp += 1
  xm -= 1

Submission status: Accepted

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

m=100
a=x
for i in range(-101,201):
    if i not in p:
        z=abs(i-x)
        if m>z:
            m=z
            a=i

print(a)

Submission status: Accepted

Solution code:
import sys
import math
def I():return int(sys.stdin.readline().replace("\n",""))
def I2():return map(int,sys.stdin.readline().replace("\n","").split())
def S():return str(sys.stdin.readline().replace("\n",""))
def L():return list(sys.stdin.readline().replace("\n",""))
def Intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split()))

x,n = I2()
if n != 0:
    p = Intl()
else:
    p = []
p.sort()
if not x in p:
    print(x)
else:
    b,e = 0,n-1
    r = []
    s = []
    for i in range(min(p)-1,max(p)+2):
        if i not in p:
            r.append(i)
            s.append(abs(x-i))
    print(r[s.index(min(s))])

Submission status: Accepted

Solution code:
import sys

x, n = map(int, input().split())
p = list(map(int, input().split()))
flag = [False]*102
for i in p:
    flag[i] = True
for j in range(0, 102):
    l = max(0, x-j)
    r = min(101, x+j)
    if not flag[l]:
        print(l)
        sys.exit()
    if not flag[r]:
        print(r)
        sys.exit()

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
ans = x
mn = 10 ** 18
for i in range(-201, 201):
    if i not in p:
        if abs(x-i) < mn:
            mn = abs(x-i)
            ans = i
print(ans)

Submission status: Accepted

Solution code:
import sys

X,N=map(int,input().split())
if N==0:
  print(X)
  sys.exit()
lis=[int(_) for _ in input().split()]
for i in range(200):
  s=X-i
  u=X+i
  if not(s in lis):
    print(s)
    sys.exit()
  if not (u in lis):
    print(u)
    sys.exit()

Submission status: Accepted

Solution code:
from bisect import bisect
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    X, N = map(int, input().split())
    P = list(map(int, input().split()))

    if not N:
        print(X)
        return

    nums = []
    for i in range(min(P) - 1, max(P) + 2):
        if i not in P:
            nums.append(i)
    i = bisect(nums, X)
    if abs(nums[i] - X) < abs(nums[i-1] - X):
        print(nums[i])
    else:
        print(nums[i-1])


main()

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
if N == 0:
    print(X)
else:
    l = list(map(int, input().split()))
    m = [i for i in range(102)]
    s = list(set(m) - set(l))
    answer_list = []
    for i in s:
        if i <= X:
            answer_list.append(X - i)
        else:
            answer_list.append(i - X)
    answer = min(answer_list)
    if X - answer in s:
        print(X - answer)
    else:
        print(X + answer)

Submission status: Accepted

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

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

cnt = 0
while True:
    if cnt == 0 and x not in list_:
        print(x)
        break

    if x - cnt not in list_:
        print(x - cnt)
        break

    if x + cnt not in list_:
        print(x + cnt)
        break

    cnt += 1

Submission status: Accepted

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


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

print(ans)

Submission status: Accepted

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

    for i in range(n+2):
        if x-i in p:
            if x+i in p:
                a =0
            else:
                print(x+i)
                exit(0) 
        else:
            print(x-i)
            exit(0)

Submission status: Accepted

Solution code:
import sys
X ,N = map(int,input().split())
p = list(map(int,input().split()))
min_dif = 10000
output = 10000
for i in range(10000):
  if (5000 - i in p) == False:
    if abs(X-(5000-i)) <= min_dif:
      min_dif = abs(X-(5000 - i))
      output =  5000 - i
print(output)

Submission status: Accepted

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

if n == 0:  
    p = input()
    print(x)
else:
    p = list(map(int, input().split()))
    max_p = max(p)
    ans = 0
    tmp = 1000

    for i in range(111):
        diff = abs(x - i)
        if i not in p and tmp > diff:
            ans = i
            tmp = diff

    print(ans)

Submission status: Accepted

Solution code:
list1= input().split(" ")
list2= input().split(" ")
X=int(list1[0])
N=int(list1[1])
plus_abs =1000
minus_abs=1000
result=0

for i in range(100):
    plus_abs=X+i
    minus_abs=X-i

    for j in range(N):
        if plus_abs == int(list2[j]):
           plus_abs=1000


    for k in range(N):
        if minus_abs == int(list2[k]):
            minus_abs=1000

    if plus_abs !=1000 or minus_abs!=1000:
        if plus_abs >= minus_abs:
            result = minus_abs
        else:
            result = plus_abs

        print(result)
        break

Submission status: Accepted

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

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

p.sort()

for i in range(p[0] - x, p[n - 1] + x):
    if (i not in p) and abs(x - i) < abs(ans - x):
        ans = i

print(ans)

Submission status: Accepted

Solution code:
X, N = [int(x) for x in input().split()]
l = [int(x) for x in input().split()]
if len(l) == 0:
    print(X)
elif X not in l:
    print(X)
else:
    for i in range(1, 1000):
        if X - i not in l:
            print(X - i)
            break
        elif X + i not in l:
            print(X + i)
            break

Submission status: Accepted

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

p = input()
if p:
    p =list(map(int,p.split(" ")))
    result = 1000
    a = 1000
    for i in range(-1, 102):
        if i in p:
            continue
        else:
            tmp = abs(i - x)
            if tmp < result:
                result = tmp
                a = i
            elif tmp == result:
                if i <= a:
                    a = i
    print(a)

else:
    print(x)

Submission status: Accepted

Solution code:
X = [int(i) for i in input().split()]
if X[1]==0:
    print(X[0])
else:
        
    P = [int(i) for i in input().split()]
    N=sorted(P)
    # print(N)
    s=0
    flag=0
    
    for i in range(100):
        if (X[0]-i) in N:
            s=1
        else:
            flag=1
            
        if (X[0]+i) in N:
            s=s+1
        else:
            if flag!=1:
                flag=2
        
        if flag==1:
            
            print(X[0]-i)
            break
    
        if flag==2:
            print(X[0]+i)
            break

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
if n == 0:
    print(x)
else:
    P = set(map(int, input().split()))
    if x not in P:
        print(x)
    else:
        ax = x
        while ax in P:
            ax += 1
        
        mx = x
        while mx in P:
            mx -= 1

        if abs(x-ax) < abs(x-mx):
            print(ax)
        else:
            print(mx)

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:
      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()))
  q=[i-X for i in p]
  qs=set(q)

  for i in range(N+1):
    if -i not in qs:
      print(X-i)
      break
    elif i not in qs:
      print(X+i)
      break

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
import bisect


def solve(X: int, N: int, p: "List[int]"):
    sortp = sorted(p)
    if(N == 0):
        print(X)
        exit()

    for i in range(100):
        # 左側
        l = X - i
        index = bisect.bisect_left(sortp,l)
        if(index == N or sortp[index] != l):
            print(l)
            exit()

        # 右側
        r = X + i
        index = bisect.bisect_left(sortp,r)
        if(index == N or sortp[index] != r):
            print(r)
            exit()

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    N = int(next(tokens))  # type: int
    p = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(X, N, p)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

for i in range(100):
    if ans not in p:
        print(ans)
        exit()
    plus += 1
    minus -= 1
    if minus not in p:
        print(minus)
        exit()
    elif plus not in p:
        print(plus)
        exit()

Submission status: Accepted

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


def main():
    x, n = map(int, input().split())
    if n >= 1:
        p_set = set(map(int, input().split()))
    else:
        p_set = set()

    print(f(x, p_set))


def f(x, p_set):
    for i in range(101):
        if (x - i) not in p_set:
            return x - i
        elif (x + i) not in p_set:
            return x + i


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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

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

current_small = current_big = X

while True:
    if current_small not in P:
        print(current_small)
        break

    if current_big not in P:
        print(current_big)
        break

    current_small -= 1
    current_big += 1

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

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

l = [0] * 100

for p in P:
    l[p-1] = 1
    
i = 0
while 1:
    if X-i-1 < 0:
        print(0)
        exit()
    elif l[X-i-1] == 0:
        print(X-i)
        exit()
    elif X+i-1 >= 100:
        print(101)
        exit()
    elif l[X+i-1] == 0:
        print(X+i)
        exit()
    i+=1

Submission status: Accepted

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


def main():
    x,n = map(int,input().split())
    p = list(map(int,input().split()))
    a = x
    b = x
    if p == None:
        print(x)
    else:
        while a in p:
            a += 1
        while b in p:
            b -= 1
        if a - x < x - b:
            print(a)
        else:
            print(b)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

for i in range(1, 101):
    if (x+i not in p_list) and (x-i not in p_list):
        print(x-i)
        exit()
    elif x-i not in p_list:
        print(x-i)
        exit()
    elif x+i not in p_list:
        print(x+i)
        exit()
    else:
        continue

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

def main():
    x, n = map(int, input().rstrip().split())
    if n == 0:
        print(x)
        sys.exit()
    else:
        p = list(map(int, input().rstrip().split()))
        if x > max(p):
            print(x)
            sys.exit()
        else:
            p_x = set(range(102))
            p_temp = set(p)
            p_diff = p_x - p_temp
            p_temp = list(p_diff)
            p_temp = sorted(p_temp)
            p_dir = []

        for i in range(len(p_temp)):
            p_dir.append(abs(p_temp[i] - x))
        print(p_temp[p_dir.index(min(p_dir))])
  
if __name__ == "__main__":
    main()

Submission status: Accepted

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

ans=1000

for i in range(1,101):
    if abs(x-ans)>abs(x-i) and i not in p:
        ans=i

if x<=abs(x-ans):
    if x<=101-x:
        print(0)
    else:
        print(101)
else:
    if abs(x-ans)<=101-x:
        print(ans)
    else:
        print(101)

Submission status: Accepted

Solution code:
X, N = list(map(int,input().split()))
if N !=0:
  P = list(map(int,input().split()))
  ab = 100
  for i in range(-100,200):
    if i not in P:
      if abs(X-i)<ab:
        ab = abs(X-i)
        ans = i
  print(ans)
else:
  print(X)

Submission status: Accepted

Solution code:
def resolve():
    X, N = map(int, input().split())
    if N != 0:
        P = list(map(int, input().split()))
        S = []
        for _ in range(0, 102):
            if _ in P:
                continue
            else:
                S.append(_)
        if X in S:
            print(X)
        else:
            for i in range(1, 102):
                if X-i in S:
                    print(X-i)
                    exit()
                elif X+i in S:
                    print(X+i)
                    exit()
    else:
        print(X)
resolve()

Submission status: Accepted

Solution code:
import sys

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

p=sorted(p)
for i in range(100):
    flag1=0
    flag2=0
    for j in range(len(p)):
        if p[j]==X-i:
            flag1=1
        if p[j]==X+i:
            flag2=1
    if flag1==0:
        print(X-i)
        sys.exit()
    if flag2==0:
        print(X+i)
        sys.exit()

Submission status: Accepted

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

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

ans = 0

if N != 0 :
    for i in range(105):
        if p.count(i)==0 :
            if abs(X-i) < abs(X-ans) :
                ans = i
    print(ans)
else :
    print(X)

Submission status: Accepted

Solution code:
from sys import exit

def downsearch(X,list):
    if X not in list:
        return X
    else:
        return downsearch(X-1,list)

def upsearch(X,list):
    if X not in list:
        return X
    else:
        return upsearch(X+1,list)


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

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

plist = [int(x) for x in input().split()]

d = downsearch(X,plist)
u = upsearch(X,plist)

if abs(X-d) <= abs(X-u):
    print(d)
else:
    print(u)

Submission status: Accepted

Solution code:
X,N = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]
nlist = [0 for i in range(105)] 
for i in p:
    nlist[i]=1
for i in range(max(X+1,100-X+1)):
    
    if X-i>=0:
        if nlist[X-i] == 0:
            result = X-i
            break
    if X+i<=101:
        if nlist[X+i] == 0:
            result = X+i
            break
print(result)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
p=list(map(int,input().split()))
ans=1e9
for i in range(x+1000):
  if i in p:
    continue
  ans=min(ans,abs(x-i))

if x-ans in p:
  print(x+ans)
else:
  print(x-ans)

Submission status: Accepted

Solution code:
# coding: utf-8

X,N = map(int, input().split())
if N==0:
    print(X)
    quit()
PList=list(map(int, input().split()))
List=[]
for k in range(102):
    List.append(k)

i=0
while i<N:
    if PList[i] in List:
        List[List.index(PList[i])]=100000
    i+=1

#print(List)


ANS=1000
j=0
KOTAE=1000
while j<102:
    if List[j]!=100000:
        SA=abs(X-List[j])
        if SA<ANS:
            ANS=SA
            #print("ands",ANS)
            KOTAE=List[j]
            #print(KOTAE)
        #print(ANS)
    j+=1
print(KOTAE)

Submission status: Accepted

Solution code:
X, N = list(map(int, input().split()))
if(N == 0):
  print(X)
  exit()
p = list(map(int, input().split()))
a = [num for num in range(-1001, 1001)]
diff = list(set(a) - set(p))
diff.sort(reverse=True)
ans = 10**10
for i in diff:
  if(abs(ans - X) >= abs(i - X)):
    ans = i
print(ans)

Submission status: Accepted

Solution code:
def main():
    import sys
    def input():
        return sys.stdin.readline()[:-1]
    A=list(map(int,input().split()))
    p=list(map(int,input().split()))
    if A[1]==0:
        print(A[0])
        sys.exit()
    X=A[0]
    N=A[1]
    for i in range(N+100):
        X1=X-i
        X2=X+i
        if X1 not in p:
            print(X1)
            sys.exit()
        if X2 not in p:
            print(X2)
            sys.exit()
    

    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
x,n = map(int,input().split())
if(n == 0):
  print(x)
  sys.exit()
l = [int(v) for v in input().split()]
fl2 = False
for k in range(n):
  if(l[k] == x):
    fl2 = True
if (fl2 == False):
  print(x)
  sys.exit()
x1 = x
x2 = x
for i in range(n):
  flg1 = True
  flg2 = True
  ans1 = x1 - 1
  ans2 = x2 + 1
  for m in range(n):
    if(l[m] == ans1):
      x1 = x1 - 1
      flg1 = False
  if (flg1 == True):
    print(ans1)
    sys.exit()
  for o in range(n):
    if(l[o] == ans2):
      x2 = x2 + 1
      flg2 = False
  if (flg2 == True):
    print(ans2)
    sys.exit()

Submission status: Accepted

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

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

for i in range(150):
  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())
if n != 0:
    p = list(map(int, input().split()))
    if x in p:
        for i in range(-1000, 1001):
            if i == -1000:
                mini = i
            if i in p:
                pass
            else:
                if abs(x - mini) > abs(x - i):
                    mini = i
                elif abs(x - mini) == abs(x - i):
                    mini = min(mini, i)
        else:
            print(mini)
    else:
        print(x)
else:
    print(x)

Submission status: Accepted

Solution code:
import math
x,n=map(int,input().split())
if n==0:
  p=[]
else:
  p=list(map(int,input().split()))
p_sort=sorted(p)
result={}
for i in range(100+2):
  if not i in p_sort:
    result[i]=abs(x-i)
print(min(result, key=result.get))

Submission status: Accepted

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

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

    arr.sort()
    mn = arr[0]
    mx = arr[-1]
    if x > mx :
        print(x)
    elif x  <mn  :
        print(x)
    else:
        c = 1e5
        d = {}
        res = 0 
        for i in range(n) :
            d[arr[i]]= 1
        for i in range(mn-1 , mx+2):
            if not d.get(i , 0 ) :
                if abs(i - x)  <c :
                    res  = i
                    c = abs(i -x)

        print(res)

Submission status: Accepted

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

ans = 0

big_x = x
sml_x = x

for i in range(100):
    
    if sml_x not in p_lst:
        ans = sml_x
        # print("0")
        break
    elif big_x not in p_lst:
        ans = big_x
        # print("1")
        break
    # else:
    #     continue
    big_x += 1
    sml_x -= 1
print(ans)

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
p = list(map(int,input().split()))
sa = []
num = []
for i in range(-110,110):
    if i in p:
        continue
    sa.append(abs(x-i))
    num.append(i)

print(num[sa.index(min(sa))])

Submission status: Accepted

Solution code:
import sys


def int1(x): return int(x) - 1
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def mi1(): return map(int1, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def lli(rows_number): return [li() for _ in range(rows_number)]


if __name__ == "__main__":
    x, n = mi()
    if n == 0:
        print(x)
        exit()
    p_l = li()
    a = list(range(0, 1000))
    for p in p_l:
        a.remove(p)
    ans = 0
    min_dif = 10000
    for i in a:
        dif = abs(i-x)
        if dif < min_dif:
            min_dif = dif
            ans = i
    print(ans)

Submission status: Accepted

Solution code:
def i():
	return int(input())
def i2():
	return map(int,input().split())
def s():
	return str(input())
def l():
	return list(input())
def intl():
	return list(int(k) for k in input().split())

x,n = i2()
p = intl()

m = 100
ls = [int(i) for i in range(-200,200)]
for i in range(n):
	ls.remove(p[i])
for j in range(len(ls)):
	if abs(x - ls[j]) < m :
		m = abs(x - ls[j])
		ans = ls[j]
print(ans)

Submission status: Accepted

Solution code:
import math
X, N = map(int, input().split())
p_list = list(map(int, input().split()))

if N == 0 or not X in p_list:
    print(X)
else:
    for i in range(1,100):
        if not X-i in p_list:
            print(X-i)
            break
        elif not X+i in p_list:
            print(X+i)
            break

Submission status: Accepted

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

int_x = int(d[0])
int_n = int(d[1])




ans = 100000
tmp = abs(int_x - ans)
for i in range(102):
  if tmp > abs(int_x - i):
    if not i in p:
      ans = i
      tmp = abs(int_x - ans)
  

# if len(p) == 0:
#   ans = int_x

print(ans)

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
p=list(map(int,input().split()))
mins=103
ans=0
for i in range(102):
    d=0
    c=abs(x-i)
    for j in range(n):
        if p[j]==i:
            d=1
        else:
            op=0
    if d==0:
        if c<mins:
            mins=c
            ans=i
        else:
            op=0
print(ans)

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
if (N == 0):
  print(X)
else:
  nums = list(map(int, input().split()))
    
  nums.sort()
  low = nums[0]
  high = nums[-1]
  minDiff = 100000000
  minNum = -1
  for i in range(-10, 110):
    if i in nums:
      continue
    else:
      Dif = abs(X-i)
    if (Dif < minDiff):
      minDiff = Dif
      minNum=i
  print(minNum)

Submission status: Accepted

Solution code:
import sys

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

if (X in p) == False:
    print(X)
    sys.exit()

for i in range(N+1):
    if (X - i in p) == False:
        print(X - i)
        sys.exit()
    elif (X + i in p) == False:
        print(X+i)
        sys.exit()

Submission status: Accepted

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

i = 0
j = 0
flag = 0
while True:
    if(X - i in p):
        i += 1
    else:
        flag = 1
        break
    if(X + j in p):
        j += 1
    else:
        flag = 2
        break
if(flag == 1):
    print(X - i)
elif(flag == 2):
    print(X + j)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
num_list = list(map(int, input().split()))
dif = 100000
o_list = []

if len(num_list) == 0:
    print(x)
    exit()
#
# for i in range(1, max(num_list)):
#     if i not in num_list:
#         o_list.append(i)

for i in range(-1000, 1000):
    if i not in num_list:
        o_list.append(i)

o_list.sort(reverse=True)

for num in o_list:
    if abs(x - num) <= dif:
        # if x not in num_list:
        dif = abs(x -num)
        ans = num

print(ans)