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:
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率

def input(): return sys.stdin.readline()[:-1]
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    #N = int(input())
    X,N = map(int, input().split())
    if N==0:
        _=input()
        print(X)
        return 
    A = list(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    
    A.sort()
    a=A

    i=bisect_left(A,X)
    
    if i==len(A):
        print(X)
        return 
    if A[i]!=X:
        print(X)
        return
    
    j=i-1
    cur=X
    amin=min(A)-1
    while j>=0:
        if abs(a[j]-cur)<2:
            cur=a[j]
            j-=1
            continue
        else:
            amin=cur-1
            break
    j=i+1
    amax=max(A)+1
    cur=X
    while j<=len(A)-1:

        if abs(a[j]-cur)<2:
            cur=a[j]
            j+=1
            continue
        else:
            amax=cur+1
            break
    
    if abs(amin-X)<=abs(amax-X):
        print(amin)
    else:
        print(amax)
    
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
p = list(map(int, input().split()))
l = []
if len(p) == 0:
    print(X)
    exit()
for i in range(-1000, 1000):
    if not i in p:
        l.append(i)

ans_n = 1000
ans = 0
for i in range(-1000, 1000):
    if ans_n > abs(X-l[i]):
        ans_n = abs(X-l[i])
        ans = l[i]

print(ans)

Submission status: Accepted

Solution code:
#C
x,n = map(int,input().split())
p = list(map(int,input().split()))
tmp = 1000
a = [i for i in range(0,150)]



p_dif = set(a) - set(p)
#print(p_dif)

for i in p_dif:
    if tmp > abs(i-x):
        tmp = abs(i-x)
        result = i
        
        
print(result)

Submission status: Accepted

Solution code:
#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())

def resolve():
    it = map(int, sys.stdin.read().split())
    X, N = next(it), next(it)

    if N == 0:
        print(X)
        return
    P = set(next(it) for i in range(N))

    if not X in P:
        print(X)
        return

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

    print(ans)



if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

ps = []
anti_Ps = []
if N != 0:
  ps = input()
  anti_Ps = [int(i) for i in ps.split()]
Ps = [int(i) for i in range(-100, 200) if i not in anti_Ps]

most_like_p = 1000
for p in Ps:
  if abs(p-X) == abs(most_like_p - X):
    most_like_p = min(p, most_like_p)
  elif abs(p-X) < abs(most_like_p - X):
    most_like_p = p

print(most_like_p)

Submission status: Accepted

Solution code:
X,N=map(int,input().split())
if N==0:
  print(X)
else:
  p=set(map(int,input().split()))
  i=-1
  for j in range(102):
    if abs(X-j)<abs(X-i) and not(j in p):
      i=j
  print(i)

Submission status: Accepted

Solution code:
X, N = (int(s) for s in input().rstrip().split())
if N == 0:
  nums = []
else:
  nums = [int(s) for s in input().rstrip().split()]

def find(nums, X):
  if not nums:
    return X
  if X not in nums:
    return X
  for i in range(1, X + 1):
    X_plus = X + i
    X_minus = X - i
    
    if X_minus not in nums:
      return X_minus
    if X_plus not in nums:
      return X_plus

print(find(nums, X))

Submission status: Accepted

Solution code:
X,N=map(int,input().split())
P=sorted(list(map(int,input().split())))
t=0
for i in range(0,102):
    if i not in P:
        if abs(X-t)>abs(X-i):
            t=i
print(t)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
p = list(map(int,input().split()))
p1 = [i for i in range(0,102)]
for i in p:
    if i in p1:
        p1.remove(i)
ans = 1000
al = []
for i in p1:
    if ans >= abs(i-x):
        ans = min(abs(i-x),ans)
        al.append(i)

if len(al) == 0:
    if x < 50:
        print(0)
    else:
        print(101)
elif len(al) > 1:
    if abs(al[-1]-x) == abs(al[-2]-x):
        print(al[-2])
    else:
        print(al[-1])
else:
    print(al[-1])

Submission status: Accepted

Solution code:
#map(int,input().split())
#int(x) for x in input().split()
#for _ in range(int(input())):
k,n=map(int,input().split())
p=[int(x) for x in input().split()]
if n==0:
	print(k)
else:
	diff=500
	ans=0
	for i in range(0,105):
		if i not in p:
			if diff>abs(k-i):
				diff=abs(k-i)
				ans=i
	print(ans)

Submission status: Accepted

Solution code:
from collections import deque
import sys
x,n = map(int,input().split())
p = []
if n != 0:
    p = list(map(int, input().split()))
tmp1 = x
if tmp1 not in p:
    print(tmp1)
    sys.exit()
i = 1
while True:
    tmp1 = x - i
    tmp2 = x + i
    if tmp1 not in p:
        print(tmp1)
        sys.exit()
    if tmp2 not in p:
        print(tmp2)
        sys.exit()
    i += 1

Submission status: Accepted

Solution code:
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

X,N = LI()
p = LI()

p.sort()
v = 0
while True:
    pl = bisect_left(p,X-v)
    if pl >= N or p[pl] != X-v:
        print(X-v)
        exit()
    pl = bisect_left(p,X+v)
    if pl >= N or p[pl] != X+v:
        print(X+v)
        exit()
    v += 1

Submission status: Accepted

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

Submission status: Accepted

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

mindiff = 1000
minval = None
for i in range(0, 101+1):
    diff = abs(X- i)
    if i not in P and diff < mindiff:
        mindiff = diff
        minval = i
print(minval)

Submission status: Accepted

Solution code:
import sys
from math import ceil, floor, sqrt, sin, cos, pi
from itertools import accumulate, permutations, combinations
from fractions import gcd # 最大公約数
from collections import deque, Counter
from operator import itemgetter
from heapq import heappop,heappush
sys.setrecursionlimit(10**7)
def lcm(x, y): return ((x * y) // gcd(x, y)) # 最小公倍数
# list(map(int, input().split()))

x, n = map(int, input().split())
p = list(map(int, input().split()))
i = 0
while True:
    if not (x - i) in p:
        print(x - i)
        sys.exit()
    elif not (x + i) in p:
        print(x + i)
        sys.exit()
    i += 1

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	C
# CreatedDate:  2020-06-14 21:12:01 +0900
# LastModified: 2020-06-14 21:21:36 +0900
#


import os
import sys
#import numpy as np
#import pandas as pd


def main():
    x,n = map(int,input().split())
    p = list(map(int,input().split()))    
    if n==0:
        print(x)
        return
 
    for i in range(0,200):
        if not x-i in p:
            print(x-i)
            return 
        if not x+i in p:
            print(x+i)
            return
            


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
"""
    こんにちは。これはクシャルです
    
    Author : thekushalghosh (クシャル)
    Team   : CodeDiggers
 
    I prefer Python language over the C++ language :p :D
        
    Visit my website : thekushalghosh.github.io
"""
import sys,math,cmath,time
start_time = time.time()
##########################################################################
################# ---- THE ACTUAL CODE STARTS BELOW ---- #################

def solve():
    x,n = invr()
    a = inlt()
    a.sort()
    if x not in a:
        print(x)
        return
    q = []
    for i in range(len(a)):
        q.append(abs(x - a[i]))
    q.sort()
    w = counter(q)
    qw = -1
    for i in range(1,len(a)):
        if q[i] - q[i - 1] > 1:
            qw = q[i - 1] + 1
            break
        if w[q[i]] == 1:
            qw = q[i]
            break
    if qw != -1:
        if x - qw not in a:
            print(x - qw)
        else:
            print(x + qw)
    else:
        print(x - max(q) - 1)
            
################## ---- THE ACTUAL CODE ENDS ABOVE ---- ##################
##########################################################################
 
def main():
    global tt
    if not ONLINE_JUDGE:
        sys.stdin = open("input.txt","r")
        sys.stdout = open("output.txt","w")
    t = 1
    for tt in range(t):
        solve()
    if not ONLINE_JUDGE:
        print("Time Elapsed :",time.time() - start_time,"seconds")
        sys.stdout.close()
    
#---------------------- USER DEFINED INPUT FUNCTIONS ----------------------#
def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    return(input().strip())
def invr():
    return(map(int,input().split()))
 
#------------------ USER DEFINED PROGRAMMING FUNCTIONS ------------------#
def counter(a):
    q = [0] * (max(a) + 1)
    for i in range(len(a)):
        q[a[i]] = q[a[i]] + 1
    return(q)
 
def string_counter(a):
    q = [0] * 26
    for i in range(len(a)):
        q[ord(a[i]) - 97] = q[ord(a[i]) - 97] + 1
    return(q)

def power_two(n):
    if n == 1:
        return(True)
    sttr = str(n)
    len_str = len(sttr)
    sttr = list(sttr)
    num = 0
    if (len_str == 1 and sttr[len_str - 1] == '1'): 
        return(False)
    while (len_str != 1 or sttr[len_str - 1] != '1'):
        if ((ord(sttr[len_str - 1]) - ord('0')) % 2 == 1):
            return(False)
        j = 0; 
        for i in range(len_str):  
            num = num * 10 + (ord(sttr[i]) - ord('0')); 
            if (num < 2): 
                if (i != 0):  
                    sttr[j] = '0'
                    j += 1
                continue
  
            sttr[j] = chr((num // 2) + ord('0'))
            j += 1; 
            num = (num) - (num // 2) * 2
        len_str = j
    return(True)

def getLeftmostBit(n): 
    m = 0
    while (n > 1) : 
        n = n >> 1
        m += 1
    return(m)
def getNextLeftmostBit(n, m) : 
    temp = 1 << m 
    while (n < temp) : 
        temp = temp >> 1
        m -= 1
    return m
def bitcounter(n) :
    m = getLeftmostBit(n) 
    return _countSetBits(n, m) 
def _countSetBits(n, m) :
    if (n == 0) : 
        return 0
    m = getNextLeftmostBit(n, m)
    if (n == (1 << (m + 1)) - 1) : 
        return ((m + 1) * (1 << m))
    n = n - (1 << m)
    return (n + 1) + bitcounter(n) + m * (1 << (m - 1)) 

def log_two(n): 
    return(math.log(n) / math.log(2))

#-----------------------------------------------------------------------#
        
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
    input = sys.stdin.readline
    
main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
A = list(map(int, input().split()))
loki = 0
while loki >= 0:
    if A.count(X - loki) == 0:
        print(X - loki)
        loki = -1
    elif A.count(X + loki) == 0:
        print(X + loki)
        loki = -1
    else:
        loki += 1

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


cnt=1
a=0
b=0

for i in range(101):
  #print(x-i)
  #print(x+i)
  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:
# abc170_c.py
X , N = map(int,input().split())
P = list(map(int,input().split()))
ans = (X,0)
for i in range(1010):
    if P.count(i)==0:
        # print(abs(X-i),i,X,ans)
        if ans[0] > abs(X-i):
            ans = (abs(X-i),i)
print(ans[1])

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
if n != 0:
  a = list(map(int,input().split()))
else:
  print(x)
  exit(0)
b = [0]*100
c = [0]*100
for i in range(n):
  if a[i]-x > 0:
    b[a[i]-x] += 1
  elif a[i] -x <0:
    c[abs(a[i]-x)] += 1
  else:
    b[0]+=1
    c[0]+=1
for i in range(100):
  if b[i] == 0 and c[i] == 0:
    print(x-i)
    exit(0)
  elif b[i] == 0:
    print(x+i)
    exit(0)
  elif c[i] == 0:
    print(x-i)
    exit(0)

Submission status: Accepted

Solution code:
X,N = map(int, input().split())		# 5 7 2
A =        list( map(int, input().split()) )	# 1 2 3 4 5 ...

A.sort()


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

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


l = r = X
while True:
  l -= 1
  if not l in A:
    ans = l
    break

  r += 1
  if not r in A:
    ans = r
    break

print(ans)

Submission status: Accepted

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

p = list(map(int, input().split()))
if len(p) == 0:
    print(x)
    exit(0)
for abs in range(n+1):
    if (x - abs) not in p:
        print(x-abs)
        exit(0)
    elif (x + abs) not in p:
        print(x+abs)
        exit(0)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def binarySearch (arr, l, r, x): 
  
    # Check base case 
    if r >= l: 
  
        mid = l + (r - l) // 2
  
        # If element is present at the middle itself 
        if arr[mid] == x: 
            return mid 
          
        # If element is smaller than mid, then it  
        # can only be present in left subarray 
        elif arr[mid] > x: 
            return binarySearch(arr, l, mid-1, x) 
  
        # Else the element can only be present  
        # in right subarray 
        else: 
            return binarySearch(arr, mid + 1, r, x) 
  
    else: 
        # Element is not present in the array 
        return -1

l=list(map(int, input().split(' ')))

find=l[0]
n=l[1]

if n==0:
    print(find)
else:
    l=list(map(int, input().split(' ')))
    l=sorted(l)

    a=find
    b=find
    
    while True:
        if binarySearch(l, 0, n-1, b)==-1:
            print(b)
            break
        elif binarySearch(l, 0, n-1, a)==-1:
            print(a)
            break
        else:
            a+=1
            b-=1

Submission status: Accepted

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

Submission status: Accepted

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

P.sort()

result = 0
for i in range(0, 101):
    if X - i not in P:
        result = X - i
        break
    if X + i not in P:
        result = X + i
        break

print(result)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
if n == 0:
    print(x)
    exit()
for i in range(101):
    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)
  exit()
p_list = list(map(int, input().split()))
ref_list = [i for i in range(0, 102)]
res = 0
val_abs = 1000
for i in ref_list:
  if i not in p_list:
    val = abs(x - i)
    if val < val_abs:
      val_abs = val
      res = i
print(res)

Submission status: Accepted

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

sp = set(p)
ans = -200
for i in range(-100, 102):
    if abs(x-i) <= abs(x-ans) and not i in sp:
        if abs(x-i)==abs(x-ans):
            ans = min(ans, i)
        else:
            ans = i
print(ans)

Submission status: Accepted

Solution code:
x, n = [int(i) for i in input().split()]
flag = [0 for i in range(105)]
if (n != 0):
    p = [int(i) for i in input().split()]

    for i in p:
        flag[i] = 1



for i in range(100):
    if x-i >=0:
        if flag[x-i] == 0:
            ans = x-i
            break
    else:
        ans = -1
        break

    if flag[x+i] == 0:
        ans = x+i
        break
    
print(ans)

Submission status: Accepted

Solution code:
x, n = map(int,input().split())
p = list(map(int,input().split()))
a = 0
b = 0
for i in range(100):
    a = x - i
    b = x + i
    if p.count(a) == 0:
        print(x - i)
        exit()
    else:
        if p.count(b) == 0:
            print(x + i)
            exit()

Submission status: Accepted

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

if N == 0:
    print(X)
else:
    p = list(map(int, input().split()))
    nums = {i for i in range(0, 102)}
    nothings = nums - set(p)
    differences = {}
    for i in nothings:
        difference = abs(X - i)
        if difference in differences:
            differences[difference].append(i)
        else:
            differences[difference] = [i]
    ans = sorted(differences.items())
    print(min(ans[0][1]))

Submission status: Accepted

Solution code:
import math

x, n = map(int, input().split(" "))
ps = input()
if ps == "":
    print(x)
    exit()
ps = sorted(list(map(int, ps.split(" "))))

if not x in ps or len(ps) == 0:
    print(x)
    exit()

g = 1
while True:
    if not (x - g in ps):
        print(x - g)
        exit()
    if not (x + g in ps):
        print(x + g)
        exit()
    g += 1
    if g == 101:
        print(0)
        exit()

Submission status: Accepted

Solution code:
import itertools,sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
X,N = LI()
p = set(LI())
ans,distance = 0,float('INF')
for x in range(-202,202)[::-1]:
    if x in p:
        continue
    now_distance = abs(X-x)
    if now_distance<=distance:
        ans = x
        distance = now_distance
print(ans)

Submission status: Accepted

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

i = 0
x = 0
while True:
  delta1 = X - i
  delta2 = X + i
  if((delta1 in p)==False):
    x = delta1
    print(x)
    sys.exit()
  elif((delta2 in p)==False):
    x = delta2
    print(x)
    sys.exit()
  i += 1

Submission status: Accepted

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

all_set = set(range(102))
diff_set = all_set - P

min_value = -1
min_diff = 100
for e in diff_set:
    difference = abs(x - e)
    if difference < min_diff:
        min_value = e
        min_diff = difference
print(min_value)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
# x, y, z = map(int, input().split())
arr = list(map(int, input().split()))
# sm = sum(arr)
# m = max(arr)
# s = input()
b = 1000
p = -1
if n == 0:
	print(x)
else:
	for i in range(-101,102):
		if abs(x-i) < b and i not in arr:
			p = i
			b = abs(x-i)
	print(p)

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
arr=[int(x) for x in input().split()]
i,j=(x-50),(x+50)
min=10**9
z=x
for t in range(i,j+1):
    if abs(t-x)<min and t not in arr:
        z=t
        min=abs(t-x)
print(z)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import copy
n, k = map(int, input().split())
a = list(map(int, input().split()))
N_min = copy.copy(n)
N_max = copy.copy(n)

while True:
    if not(N_min in a):
        print(N_min)
        break
    if not(N_max in a):
        print(N_max)
        break
    N_min -= 1
    N_max += 1

Submission status: Accepted

Solution code:
x,n = [int(x) for x in input().split()]
arr = set([int(x) for x in input().split()])
# arr.sort()

if n == 0:
    print(x)
elif x < min(arr):
    print(x)
elif x > max(arr):
    print(x)
elif not x in arr:
    print(x)
else:
    res = -1
    min_diff = 8491654891598
    for i in range(-1,102):
        if i in arr:
            continue
        # min_diff = min(min_diff, abs(x - i))
        if abs(x - i) < min_diff:
            min_diff  = abs(x - i)
            res = i
    print(res)

Submission status: Accepted

Solution code:

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

ans = x

min_num = 10**9
for i in range(-200,301):
    if p.count(i) == 0:
        if min_num > abs(x-i):
            min_num = 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(N//2 + 2):
    A = X - i
    if A not in P:
        print(A)
        exit() 
    B = X + i
    if B not in P:
        print(B)
        exit()

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
p = list(input().split())
p = [int(p[i]) for i in range(N)]
ans = float('inf')
dif = float('inf')

for i in range(0, 102):
    if i not in p and abs(i - X) < dif:
        ans = i
        dif = abs(i-X)

print(ans)

Submission status: Accepted

Solution code:
import sys
from collections import deque
si = sys.stdin.readline


def main():
    l = [int(e) for e in si().split()]
    pn = set()
    if l[1] != 0:
        pn = set(int(e) for e in si().split())

    d = 0
    x = l[0]
    if x not in pn:
        print(x)
    else:
        while True:
            d += 1
            if x-d not in pn:
                print(x-d)
                break
            if x+d not in pn:
                print(x+d)
                break


if __name__ == '__main__':
    main()

Submission status: Accepted

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


def main():
    X, N = map(int,input().split())
    p = list(map(int,input().split()))
    p_new = [i - X for i in p]
    num = 0
    while num in p_new and -num in p_new:
        num += 1
    if X - num in p:
        print(X + num)
    else:
        print(X - num)

    
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import numpy as np

XN=np.array(input().split(" "),dtype=np.int32)
X=XN[0]
N=XN[1]

if(N==0):
    print(X)
else:
    p=np.array(input().split(" "),dtype=np.int32)
    p=np.sort(p)
    ABS=0
    results=[]
    length=0
    while(True):
        upper=X+ABS
        lower=X-ABS
        
        if(upper in p):
            pass
        else:
            results.append(upper)
            length+=1
        if(lower in p):
            pass
        else:
            results.append(lower)
            length+=1
        
        if(length>0):
            break
        ABS+=1
    print(min(results))

Submission status: Accepted

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

if N == 0:
    P = []
else:
    P = [int(x) for x in input().split()]

for i in range(100):
    q = X - i
    if q not in P:
        print(q)
        break
    q = X + i
    if q not in P:
        print(q)
        break

Submission status: Accepted

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

check = [0 for i in range(110)]
for i in range(N):
    check[P[i]-1] = 1
    
dx_ls = [1000 for i in range(110)]
ans = []
for i in range(110):
    if check[i] == 0:
        dx_ls[i] = abs(X-(i+1))
            
dx_min = min(dx_ls)
for i in range(110):
    if dx_ls[i] == dx_min:
        ans.append(i+1)
        
ans_plus = min(ans)

if abs(ans_plus-X) >= abs(X - 0):
    print(0)
else:
    print(ans_plus)

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
*P, = map(int, input().split())
l = set([i for i in range(-200, 200)]) - set(P)
m = 100000000
ans = 0
for i in l:
    if abs(i-X) < m:
        ans = i
        m =abs(i - X)
print(ans)

Submission status: Accepted

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

X,N = list(map(int, input().rstrip().split()))
p_list = list(map(int, input().rstrip().split()))
#-----

p_set = set(p_list)
delta = 0

while True:
    for d in [-delta, delta]:
        n = X + d
        
        if n in p_set:
            continue
        else:
            print(n)
            sys.exit()
    
    delta += 1

Submission status: Accepted

Solution code:
import sys
X, N = map(int, input().split())
p = list(map(int, input().split()))
P = set(p)
a = 1000
c = -101
if N == 0:
    print(X)
    sys.exit()
if X not in P:
    print(X)
    sys.exit()
for i in range(-1, 102):
    if i in P:
        continue
    if abs(i - X) == a:
        c = min(c, i)
    elif abs(i - X) < a:
        c = i
        a = abs(i - X)
print(c)

Submission status: Accepted

Solution code:
x,n=map(int,input().split(" "))
if n==0:
  print(x)
else:
  line=list(map(int,input().split(" ")))
  a=0
  b=0
  while a==0:
    if x-b not in line:
      min=x-b
      a=1
    elif x+b not in line:
      min=x+b
      a=1
    else:
      b=b+1
  print(min)

Submission status: Accepted

Solution code:

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

for i in range(103):
    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:
    print(x)

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

Submission status: Accepted

Solution code:
# Contest No.: ABC170
# Problem No.: C
# Solver:      JEMINI
# Date:        20200614

import sys
import heapq

def main():
    x, n = map(int, input().split()) 
    nums = list(map(int, sys.stdin.readline().split()))
    if x not in nums:
        print(x)
        return
    
    #nums.sort()
    ans = None
    diff = 1
    while True:
        if x - diff not in nums:
            ans = x - diff
            break
        elif x + diff not in nums:
            ans = x + diff
            break
        diff += 1

    print(ans)
        
        
    
    return

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
XN = [int(x) for x in input().split()]
p = [int(x) for x in input().split()]
tmp=100
tmp_i=0
for i in range(102):
  if not i in p:
    if abs(XN[0]-i)<tmp:
      tmp=abs(XN[0]-i)
      tmp_i=i
print(tmp_i)

"""
10 5
4 7 10 6 5
"""

Submission status: Accepted

Solution code:
x,n=list(map(int,input().split()))
if(n==0):
    print(x)
else:
    p=list(map(int,input().split()))
    mini=min(p)-1
    maxi=max(p)+1

    m=abs(maxi-x)
    val=maxi
    i=maxi
    while(i>=mini):
        if(i in p):
            pass
        else:
            
            
            if(abs(i-x)<=m):
                m=abs(i-x)
                val=i
        i-=1        

    print(val)

# x,y=list(map(int,input().split()))

# t=y/2-x
# c=x-t

# if(t<0 or c<0 or abs(t)!=t or abs(c)!=c):
#   print("No")
# else:
#   print("Yes")

Submission status: Accepted

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

flag = 0
if N == 0:
    print(X)
else:
    X1 = X
    X2 = X
    ans = []
    while flag ==0:
        
        if not(X1 in p):
            ans.append(X1)
            flag = 1
        if not(X2 in p):
            ans.append(X2)
            flag = 1
        if flag == 1:
            print(min(ans))
            
        else:
            X1-= 1
            X2+= 1