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 = list(map(int,input().split()))
if N == 0:
  print(X)
  exit()
P = sorted(list(map(int,input().split())))
ans1 = P[0] - 1
ans2 = P[-1] + 1
isx = 0
for i in range(1,N):
  if (P[i]-X) > 0:
    if not isx:
      ans1 = X
      break
    else:
      break
  if P[i-1] != (P[i]-1):
    ans1 = P[i] -1
  if P[i] == X:
    isx = 1
    break

for i in range(1,N+1):
  if (P[-i]-X) < 0:
    if not isx:
      ans1 = X
      break
    else:
      break
  if P[-i+1] != (P[-i]+1):
    ans2 = P[-i] + 1
  if P[-i] == X:
    isx = 1
    break

if not isx:
  print(X)
  exit()

aa1 = abs(X-ans1)
aa2 = abs(X-ans2)
if aa1 == aa2:
  print(ans1)
elif aa1 > aa2:
  print(ans2)
else:
  print(ans1)

Submission status: Accepted

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


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

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
a = [int(i) for i in input().split()]
b = [0]*200
for i in range(200):
    b[i] = i
for i in range(len(a)):
    b.remove(a[i])
min = 1000000
ans=0
for i in range(len(b)):
    dist = abs(b[i] - x)
    if min > dist:
        min = dist
        ans = b[i]
print(ans)

Submission status: Accepted

Solution code:
R = lambda: map(int, raw_input().split())
X, N = R()
s = set(R())

for i in xrange(1000):
    if X - i not in s:
        print X - i
        break
    if X + i not in s:
        print X + i
        break

Submission status: Accepted

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

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


a = list(range(-1,102))

for i in lis:
    a.remove(i)

ans = 10000    
tans = 0
for j in a:
    tmp = abs(j-x)
    if tmp < ans:
        tans = j
        ans = tmp
        
print(tans)

Submission status: Accepted

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

over = x
under = x

while True:
  if over in p and under in p:
    over +=1
    under -=1
    continue
  elif under in p:
    ans = over
    break
  else:
    ans = under
    break
    
print(ans)

Submission status: Accepted

Solution code:

x,n = list(map(int, input().split()))
p = list(map(int, input().split()))
p.sort()
#print(p)
memo1 = [0]*100
memo2 = [0]*100
a,b = 1000,1000
if n == 0:
    print(x)
    exit()
for i in range(100):
    memo1[i] = abs(i-x)
    memo2[i] = abs(i+x)
    if memo1[i] not in p:
        a = memo1[i]
        i1 = i
        break
    elif memo2[i] not in p:
        b = memo2[i]
        i2 = i
        break
if a<=b:
    print(a)
else:
    print(b)

Submission status: Accepted

Solution code:
import sys

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


for i in range(x+1):
    s = x-i
    t = x+i
    
    if s in p and t in p:
        continue
    
    elif s in p and t not in p :
        print(t)
        sys.exit()
    
    else :
        print(s)
        sys.exit()

Submission status: Accepted

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

if x not in dic:
    print(x)
else:
    for i in range(1, 101):
        a=x-i
        b=x+i
        if a not in dic and b not in dic:
            print(min(a,b))
            exit()
        if a not in dic:
            print(a)
            exit()
        if b not in dic:
            print(b)
            exit()

Submission status: Accepted

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

Xm = X
Xp = X
status = True

while status:
    if Xm not in p:
        print(Xm)
        status = False
    elif Xp not in p:
        print(Xp)
        status = False
    Xm -= 1
    Xp += 1

Submission status: Accepted

Solution code:


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

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

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

result = 0

if X not in P:
  result = X
else:
  diff = 1
  flag = True
  while flag:
    if (X - diff) not in P:
      result = X - diff
      break
    if (X + diff) not in P:
      result = X + diff
      break
    diff += 1
    
print(result)

Submission status: Accepted

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

P = list(map(int, input().split()))
candidates = [i for i in range(102)]

ans = 1000
min_diff = 1000
for c in candidates:
    if c in P:
        continue
    diff = abs(X - c)
    if diff < min_diff:
        ans = c
        min_diff = diff

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

for i in range(1, 10**9):
    if x-i not in p:
        print(x-i)
        break
    if x+i not in p:
        print(x+i)
        break

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
p=list(map(int,input().split()))
p.sort()
ans=300
for i in range(-100,200):
    if p.count(i)==0:
        if abs(ans-x)>abs(i-x):
            ans=i
print(ans)

Submission status: Accepted

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

diffs = dict()
for i in range(100 + 2):
    diffs[i] = abs(x - i)
for p in p_list:
    diffs[p] = float('inf')

min_diff = float('inf')
min_num = float('inf')
for i in range(100 + 2):
    if min_diff > diffs[i]:
        min_diff = diffs[i]
        min_num = i
print(min_num)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

if x in p:
    y = x - 1
    while y in p:
        y -= 1
    z = x + 1
    while z in p:
        z += 1
    # print(y,z)
    if(abs(y-x) == abs(z-x)):
        print(y)
    elif(abs(y-x) > abs(z-x)):
        print(z)
    else:
        print(y)
else:
    print(x)
# print(x,n)
# print(p)

Submission status: Accepted

Solution code:
X, N = map(int,input().split())
if N==0:
    print(X)
else:
    P = list(map(int,input().split()))
    P.sort()
    Q = [i-1 for i in range(-10,111)]
    for a in P:
        Q.remove(a)
    Q1 = [abs(b - X) for b in Q]
    print(Q[Q1.index(min(Q1))])

Submission status: Accepted

Solution code:
def resolve():
    import sys
    input = sys.stdin.readline
    # 整数 1 つ
    # n = int(input())
    # 整数複数個
    x, n = map(int, input().split())
    # 整数 N 個 (改行区切り)
    # N = [int(input()) for i in range(N)]
    # 整数 N 個 (スペース区切り)
    # N = list(map(int, input().split()))
    # 整数 (縦 H 横 W の行列)
    # A = [list(map(int, input().split())) for i in range(H)]

    if n == 0:
        print(x)
    else:
        P = list(map(int, input().split()))
        P.sort()
        #B = [i for i in range(102)]

        if x not in P:
            print(x)
        else:
            xindex = P.index(x)

            for j in range(1,100):
                if xindex - j >= 0:
                    if P[xindex - j] != x-j:
                        print(x-j)
                        break
                else:
                    print(x-j)
                    break
                if xindex + j <= n-1:
                    if P[xindex + j] != x+j:
                        print(x+j)
                        break
                else:
                    print(x+j)
                    break

resolve()

Submission status: Accepted

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

a,b=x,x

ans=0
while ans==0:
  if n==0:
    ans=x
  elif x not in lis:
    ans=x
  else:
    a=a-1
    b=b+1
    if a not in lis:
      ans=a
      break
    if b not in lis:
      ans=b

print(ans)

Submission status: Accepted

Solution code:
# coding=UTF-8
from collections import deque
from operator import itemgetter
from bisect import bisect_left, bisect
import itertools
import sys
import math
import numpy as np
import time
sys.setrecursionlimit(10**6)
input = sys.stdin.readline


def main():
    x, n = map(int, input().split())
    p = list(map(int, input().split()))
    if n == 0 or x not in p:
        print(x)
    else:
        for i in range(200):
            num1 = x-i
            num2 = x+i
            if num1 not in p and num2 not in p:
                print(min(num1, num2))
                break
            elif num1 not in p:
                print(num1)
                break
            elif num2 not in p:
                print(num2)
                break


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

for i in range(1,51,1):
  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:
# -*- coding: utf-8 -*-

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

flag = True
i = 0

while flag:
  if x - i not in num_list:
    ans = x - i
    break
  elif x + i not in num_list:
    ans = x + i
    break
  i += 1

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import math

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

if N==0:
    p = []
else:
    p = list(map(int, input().split()))

p = sorted(p)

for i in range(100):
    if X-i not in p:
        print(X-i)
        quit()

    if X+i not in p:
        print(X+i)
        quit()

Submission status: Accepted

Solution code:
# C

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

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

ans = X

for i in range(200):
  temp1 = X - i
  temp2 = X + i
  if not temp1 in P:
    ans = temp1
    break
  elif not temp2 in P:
    ans = temp2
    break

print(ans)

Submission status: Accepted

Solution code:
X ,N = map(int,input().split())
P = list(map(int,input().split()))
if N == 0:
    print(X)
    exit(0)
A = list(range(0,102))
ans = 0
mins = 100


for a in A:
    if a not in P:
        if abs(a-X) < mins:
            mins = abs(a-X)
if (X - mins) not in P:
    print(X-mins)
else:
    print(X+mins)

Submission status: Accepted

Solution code:
import sys

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

x, n, *p = map(int, read().split())

min_d = 1000000

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

for i in range(110):
    if i in p:
        continue
    d = abs(x - i)
    if d < min_d:
        min_d = d
        ans = i

print(ans)

Submission status: Accepted

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

ls = sorted(ls)
d = 10**3
ans = 0
for i in range(ls[0]-1,ls[-1]+2):
  if i in ls:
    continue
  if d>abs(i-x):
    d = abs(i-x)
    ans = i
print(ans)

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
n=list(map(int,input().split()))
n.sort
if(x not in n):
    print(x)
    exit()
finder=n.index(x)
i=1
while(True):
    if(x-i not in n):
        print(x-i)
        exit()
    if(x+i not in n):
        print(x+i)
        exit()
    i=i+1

Submission status: Accepted

Solution code:
import sys
X, N = map(int,input().split())
if N == 0:
  print(X)
  sys.exit()
p = set(map(int,input().split()))
for i in range(51):
  a = X - i
  if not(a in p):
    print(a)
    sys.exit()
  a = X + i
  if not(a in p):
    print(a)
    sys.exit()

Submission status: Accepted

Solution code:
import sys

data = sys.stdin
data_list = data.readlines()
data_1 = data_list[0].strip("\n").split(" ")
data_2 = data_list[1].strip("\n").split(" ")
i = 0

if data_1[1] == "0":
  print(data_1[0])
else:
  while True:
    if int(data_1[0]) - i >= 0:
      ans = int(data_1[0]) - i
      if str(ans) not in data_2:
        print(ans)
        break
    ans = int(data_1[0]) + i
    if str(ans) not in data_2:
      print(ans)
      break
    i += 1

Submission status: Accepted

Solution code:
X, num = [int(i) for i in input().split(" ")]

 
if num == 0:
  print(X)
else:
  l = [int(i) for i in input().split(" ")]
  for i in range(num):
    if X-i not in l:
      print(X-i)
      exit()
    elif X+i not in l:
      print(X+i)
      exit()
  print(X-num)

Submission status: Accepted

Solution code:
X,N=map(int,input().split())
hazusu=list(map(int,input().split()))
kouho=100
ans=0
for i in reversed(range(-2,102)):
    if i in hazusu:
        continue
    d=abs(X-i)
    if d<=kouho:
        kouho=d
        ans=i
print(ans)

Submission status: Accepted

Solution code:
from math import *
x,n=map(int,input().split())
p=[]
if n>0:
	p=[int(i) for i in input().split()]
mn=float('inf')
ans=-1
for i in range(-1,102):
	if not i in p:
		if abs(x-i) < mn:
			ans=i
			mn=abs(x-i)
print(ans)

Submission status: Accepted

Solution code:
X,N=map(int,input().split())
P = list(map(int,input().split()))
value = float('inf')
if(N==0):
    print(X)
    exit()
ans_value= 101
for i in range(0,102):
    if (i not in P):
        if(abs(X-i)<value):
            value=abs(X-i)
            ans_value=i
print(ans_value)

Submission status: Accepted

Solution code:
lst1 = input().split()
lst2 = input().split()
key = int(lst1[0])
lst = []
for i in range(102):
    lst.append(i)
for i in lst2:
    lst.remove(int(i))
for i in range(len(lst)):
    if lst[i] > key:
        break
if lst[i] - key < key - lst[i-1]:
    print(lst[i])
else:
    print(lst[i-1])

Submission status: Accepted

Solution code:
import numpy as np

def resolve():
    x, n = map(int, input().split())
    if n == 0:
        print(x)
        return
    P = set(map(int, input().split()))
    if x not in P:
        print(x)
        return

    P_not = np.array(list(set(list(range(-1, 102))) - P))
    diff = np.abs(P_not - x)
    print(P_not[diff.argmin()])

resolve()

Submission status: Accepted

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

listP.sort()

minD = 200
val = 0
bef = None
for p in listP:
    if bef == None:
        bef = p
        minD = abs(p-1-x)
        val = p-1
    else:
        if p-1 == bef:
            pass
        else:
            if bef < x < p:
                minD = 0
                val = x
            elif x <= bef:
                if abs(bef+1-x) < minD:
                    minD = abs(bef+1-x)
                    val = bef+1
            else:
                if abs(p-1-x) < minD:
                    minD = abs(p-1-x)
                    val = p-1
        bef = p
if not x in listP:
    val = x
    minD = 0
elif val == 0:
    if abs(0-x) > abs(101-x):
        val = 101
        minD = abs(101-x)
    else:
        val = 0
        minD = abs(0-x)
elif bef!=None and abs(bef+1-x) < minD:
    val = bef+1

print(val)

Submission status: Accepted

Solution code:
X, N = [int(_) for _ in input().split()]
pn = [int(_) for _ in input().split()]
pn.sort()

pn_bar = [int(_) for _ in range(-100*2-1,100*2+1) if (_ not in pn)]

#print(pn_bar)


now_min = 10000
ans = 10000
for i in pn_bar:
    delta = abs(i - X)
    if(delta < now_min):
        ans = i
        now_min = delta
        
print(ans)

Submission status: Accepted

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

    x_up = x
    x_down = x

    while True:
        if x_down not in p:
            print(x_down)
            break
        elif x_up not in p:
            print(x_up)
            break

        x_up += 1
        x_down -= 1

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# C
X, N = map(int, input().split())
A = list(map(int, input().split()))
dct = {i: [] for i in range(101)}
for i in A:
    num = abs(X - i)
    dct[num].append(i)
for k,v in dct.items():
    if (k == 0):
        if (len(v) == 0):
            print(X)
            break
    elif (len(v) == 0):
        if (X >= k):
            print(X - k)
            break
        else:
            print(k - X)
            break
    elif (len(v) == 1):
        if (X - k == v[0]):
            print(X + k)
            break
        else:
            print(X - k)
            break

Submission status: Accepted

Solution code:
XN = input().split()
X = int(XN[0])
N = int(XN[1])
if N == 0:
    print(X)
    exit(0)
P = input().split()
pp=[int(s) for s in P]
if X not in pp:
    print(X)
    exit(0)

ans = []
flag = False
for i in range(N):
    if X - i - 1 not in pp:
        print(X - i - 1)
        exit(0)
    if X + i +1 not in pp:
        print(X + i + 1)
        exit(0)

Submission status: Accepted

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

if n != 0:
  ans = None
  for i in range(n + 1):
    if x - i not in p:
      ans = x - i
      break
    if x + i not in p:
      ans = x + i
      break
  if not ans is None:
    print(ans)
  else:
    print(x - n - 1)
else:
  print(x)

Submission status: Accepted

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

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

p.sort()
q = [i for i in range(0, 102) if i not in p]

diff = [0] * len(q)
for i in range(len(q)):
      diff[i] = abs(q[i] - x)

index = diff.index(min(diff))
print(q[index])

Submission status: Accepted

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

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

#if x in p == False:
    #print(x)


for i in range(101):
    if ((x-i) in p) == False:
        print(x-i)
        break
    elif ((x+i) in p) ==False:
        print(x+i)
        break

Submission status: Accepted

Solution code:
x,y = map(lambda x:int(x),input().split(" "))
if y==0:
    print(x)
else:
    input_list = list(map(lambda x:int(x),input().split(" ")))
    for i in range(y+2):
        if x-i not in input_list:
            print(x-i)
            break
        elif x+i not in input_list:
            print(x+i)
            break

Submission status: Accepted

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

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

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

ans = 999
for i in range(-1, 102):
    if not i in p_li:
        tmp = i

        if abs(x - ans) > abs(x - tmp):
            ans = i

print(ans)

Submission status: Accepted

Solution code:
import numpy as np

x, n = map(int, input().split())
arr = {i for i in range(102)}

for i in input().split():
    arr.remove(int(i))

arr = list(arr)

idx = np.abs(np.asarray(arr) - x).argmin()

print(arr[idx])

Submission status: Accepted

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

n_P = []

for i in range(1, 100):
    if i not in P:
        n_P.append(i)

n_P.append(0)
n_P.append(101)

n_P.sort()
INF = 10 ** 9
diff = INF
ans = INF

for p in n_P:
    if abs(X-p) < diff:
        diff = abs(X-p)
        ans = p

print(ans)

Submission status: Accepted

Solution code:
import os
import numpy as np

if os.path.exists('input.txt'):
    test_mode = True
else:
    test_mode = False

if test_mode:
    f = open('input.txt')
    
def get_input():
    if test_mode:
        return f.readline().rstrip()
    else:
        return input().rstrip()

def int_list(l):
    for i in range(len(l)):
        l[i] = int(l[i])
    
input_line = get_input().split()
X = int(input_line[0])
N = int(input_line[1])
p = get_input().split()
int_list(p)

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

if test_mode:
    f.close()

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
if n == 0:
    print(x)
else:
    arr = list(map(int, input().split()))
    
    target = x
    count = 1
    while True:
        if target not in arr:
            print(target)
            break
        if count % 2 != 0:
            target -= count
        else:
            target += count
        count += 1

Submission status: Accepted

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

P = []

for i in range(101):
    P.append(i)

for j in range(len(P)):
    if P[j] in p:
        P[j] = 101

l = []

for i in range(len(P)):
    y= abs(P[i] - X)
    l.append(y)

min = l[0]
ans = 0
sub = 101

for j in range(1, 101):
    if min > l[j]:
        min = l[j]
        ans = j
    elif min == l[j]:
        sub = j

if sub != 101:
    if P[ans] >P[sub]:
        print(P[sub])
    else:
        print(P[ans])
else:
    print(P[ans])

Submission status: Accepted

Solution code:
import numpy as np

a = list(map(int, input().split()))
if a[1] == 0:
    print(a[0])
else: 
    b = list(map(int, input().split()))
    c = list(set([i for i in range(200)]) - set(b))
    idx = np.abs(np.asarray(c) - a[0]).argmin()
    print(c[idx])

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()))
flaga = 0
flagb = 0

for i in range(100):
    a = X - i
    b = X + i
    if (a in P)== 0:
        flaga = 1
    if (b in P)== 0:
        flagb = 1
    if flaga ==1 or flagb ==1:
        break

if flaga ==1 and flagb ==1:
    print(min(a,b))
elif flaga ==1 and flagb ==0:
    print(a)
else:
    print(b)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
# スペース区切りの整数の入力
X, N = map(int, input().split())

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

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

## sec2
for i in range(101):
    if sum(P == X - i) == 0:
        print(X - i)
        exit(0)
    if sum(P == X + i) == 0:
        print(X + i)
        exit(0)

Submission status: Accepted

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

if n == 0:
    # input()
    print(x)
else:
    l = list(map(int, input().split()))
    l.sort()
    small = x
    large = x
    while small in l and large in l:
        small -= 1
        large += 1
    if small in l:
        print(large)
    elif large in l:
        print(small)
    elif x - small > large - x:
        print(large)
    else:
        print(small)

Submission status: Accepted

Solution code:
from sys import stdin

A = list(map(int,stdin.readline().split()))
B = list(map(int,stdin.readline().split()))
C = [x for x in range(-10,110)]
C = set(C)
B = set(B)
C = C.difference(B)
C = list(C)
X=A[0]
N=A[1]
record=200
number=1000
K=0

if N==0:
    print(X)
    K=1

for t in C:
    diff=abs(t-X)
    if diff<record:
        record=diff
        number=t
    elif diff==record:
        number=min(number,t)

if K==0:
   print(number)

Submission status: Accepted

Solution code:
import sys
#sys.exit()
#sorted( ,reverse=True)
#N = int(input())
X, N = map(int, input().split())
P = list(map(int, input().split()))


if N ==0:
    print(X)
    sys.exit()
    
if X not in P:
    print(X)
    sys.exit()
cnt= 1
while True:
    #print(X-cnt,X+cnt)
    if (X -cnt) not in P:
        print(X-cnt)
        sys.exit()
    elif (X+cnt) not in P:
        print(X+cnt)
        sys.exit()
    cnt += 1  

#A = [int(input()) for _ in range(N)]

#cnt = 0
#cnt += 1



#print(N)
#print(S,T)
#print(A)
#print('Yes')
#print('No')
#print(cnt)

Submission status: Accepted

Solution code:
X,N = map(int, input().split())
p = [int(x) for x in input().split()]

exist = 0
ans = -1

if N == 0:
    ans = X

for i in range(100):
    LX = X - i
    exist = 0
    for j in range(N):
        if LX == p[j]:
             exist = 1
    if exist == 0:
        ans = LX
        break

    HX = X + i
    exist = 0
    for k in range(N):
        if HX == p[k]:
            exist = 1
    if exist == 0:
        ans = HX
        break

print(ans)

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
 
if n != 0:
    p = list(map(int,input().split()))
 
s = []
 
for i in range(-1,102):
    s.append(i)
    
if n != 0:
    for i in p:
        s.remove(i)
 
if n == 0:
    print(x)
else:
    if x in s:
        print(x)
    elif x<s[0]:
        print(s[0])
    elif x>s[-1]:
        print(s[-1])
    else:
        for i in range(len(s)-1):
            if s[i]<=x<=s[i+1]:
                if abs(x-s[i])<abs(x-s[i+1]):
                    print(s[i])
                elif abs(x-s[i])==abs(x-s[i+1]):
                    print(s[i])
                else:
                    print(s[i+1])
                break

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
plist = [int(i) for i in input().split()]

x = 0
hx = -1
while True:
    px = x
    nx = -x
    if X + nx not in plist: 
        hx = nx
        break
    if X + px not in plist:
        hx = px
        break
    x += 1
print(X+hx)

Submission status: Accepted

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

l.sort()

if x not in l:
    print(x)
    exit()
else:
    a = l.index(x)

if a == n-1:
    if l[a-1] == x-1:
        print(x+1)
        exit()
    else:
        print(x-1)
        exit()
elif a == 0:
    print(x-1)
    exit()
    
p=a-1
f=a+1
while p >= 0 and f <= n-1:
    if l[p] < x-(a-p):
        print(x-(a-p))
        exit()
    elif l[f] > x+(f-a):
        print(x+(f-a))
        exit()
    p -= 1
    f += 1

if p == -1:
    print(l[0]-1)
elif f == n:
    print(l[-1]+1)

Submission status: Accepted

Solution code:
X,N = map(int,input().split())
arr = list(map(int,input().split()))
if X not in arr:
    print(X)
    exit()
sx = X+1
mx = X-1
ans = []
while 1:
    if sx not in arr:
        ans.append(sx)
        break
    sx += 1
while 1:
    if mx not in arr:
        ans.append(mx)
        break
    mx -= 1
if abs(ans[0]-X) < abs(ans[1]-X):
    print(ans[0])
elif abs(ans[0]-X) < abs(ans[1]-X):
    print(ans[1])
else:
    print(min(ans))

Submission status: Accepted

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

import bisect as bis
p.sort()
now = x
k = 1

for i in range(150):
    pm = k * (-1)**k
    index = bis.bisect_left(p, now)
    if index < len(p) and p[index] == now:
        now += pm
        k += 1
    else:
        print(now)
        break

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
s = list(map(int, input().split()))
for j in range(n):
    s[j] = s[j] - x

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

Submission status: Accepted

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

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

import sys
if n == 0:
    print(x)
else:
    sa_min = 1000000
    for i in range(-110, 210):
        if i not in p_list:
            if sa_min > abs(i - x):
                sa_min = abs(i - x)
                ans = i
    print(ans)

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()))
jud=[0 for i in range(102)]
for i in p:
  jud[i]=1
if jud[x]==0:
  print(x)
  sys.exit()
diff=1
while 1:
  if x >= diff and jud[x-diff]==0:
    print(x-diff)
    break
  if x + diff < 102 and jud[x+diff]==0:
    print(x+diff)
    break
  diff+=1

Submission status: Accepted

Solution code:
def gen(X):
    x = X
    yield x
    d = 1
    while True:
        yield X - d
        yield X + d
        d += 1
def main():
    X, N = map(int, input().split())
    P = set(map(int, input().split()))

    for x in gen(X):
        if x not in P:
            print(x)
            return

if __name__ == '__main__':
    main()

Submission status: Accepted

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

li = []


for i in range(-101, 201):
    if not i in p:
        li.append(i)

zzz = float('inf')

for i in li:
    if zzz > abs(x - i):
        zzz = abs(x - i)
        ans = i


print(ans)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
q = []
cnt = 1000
ans = 0

for i in range(0,102):
    if not i in p:
        q.append(i)
        
for i in q:
    if cnt > abs(x-i):
        ans = i
        cnt = 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(1000):
    if x-i in p:
        pass
    else:
        print(x-i)
        break
    if x+i in p:
        pass
    else:
        print(x+i)
        break

Submission status: Accepted

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

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

for i in range(x+1):
    if i+x not in PS and x-i not in PS:
        print(min(i+x, x-i))
        break
    elif i+x not in PS:
        print(i+x)
        break
    elif x-i not in PS:
        print(x-i)
        break

Submission status: Accepted

Solution code:
import numpy as np
x,n = map(int, input().split())
if n != 0:
    p = list(map(int, input().split()))
if n == 0:
    print(x)
    exit()
ll = np.ones(1)*(-1)
for i in range(102):
    ll = np.append(ll,int(i))
    
for j in p:
    ll= ll[~(ll == j)]

if len(ll) == 0:
    print(x)
    exit()
# print(ll)

a = np.zeros(len(ll))
for i in range(len(ll)):
    a[i]=abs(x-ll[i])
# print(ll)
print(int(ll[np.argmin(a)]))

Submission status: Accepted

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

for i in range(n):
    P[i]=abs(P[i]-x)
P.sort()
count = -1
for i in range(n):
    if (i+1)//2 == P[i]:
        continue
    else:
        count=(i+1)//2
        break

if n%2==0 and count==-1:
    count=n//2
elif n%2==1 and count==-1:
    count=(n+1)//2

if n==0:
    print(x)
elif x-count in Q:
    print(x+count)
else:
    print(x-count)