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:
inf = float('inf')
X,N = map(int,input().split())
p = list(map(int,input().split()))
ans = 101
diff = inf
for i in range(101,-1,-1):
    if i not in p:
        if diff >= abs(i-X):
            diff = abs(i-X)
            ans = i

print(ans)

Submission status: Accepted

Solution code:
X,N = map(int,input().split())
P = set(map(int,input().split()))
ans = 1001
diff = 1000
for i in range(102):
    if i in P:
        continue
    if abs(X-i) < diff:
        ans = i
        diff = abs(X-i)
print(ans)

Submission status: Accepted

Solution code:
X, N = map(int, input().split())  # 整数Xと, 長さN
P = set(map(int, input().split()))

ans = 1000
for i in range(-100, 1000):
    if abs(X-i) < abs(X-ans) and i not in P:
        ans = i
print(ans)

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
P = [int(i) for i in input().split()]
kouho=[int(i) for i in range(-200,200)]
List = []
ans = 10**9
for i in kouho:
    if i not in P:
        tmp = abs(x-i)
        if tmp<ans:
            ans = tmp
            List = [i]
        elif tmp == ans:
            List.append(i)
List.sort()
print(List[0])

Submission status: Accepted

Solution code:
# coding: utf-8
#import numpy as np
import re
import math
from collections import defaultdict
from collections import deque
import collections
from fractions import Fraction
import bisect
from queue import PriorityQueue
import itertools
from itertools import accumulate
from copy import deepcopy
import random
import time
import os
import sys
import datetime
from functools import lru_cache
from functools import reduce
readline=sys.stdin.readline
sys.setrecursionlimit(2000000)
alphabet="abcdefghijklmnopqrstuvwxyz"
numbers="0123456789"
mod=int(10**9+7)
inf=int(10**19)
class Edge():
    def __init__(self,x,y,val=1):
        self.x=x
        self.y=y
        self.val=val
class unionfind():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(n)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):
            self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def yn(b):
    if b:print("yes")
    else:print("no")
def Yn(b):
    if b:print("Yes")
    else:print("No")
def YN(b):
    if b:print("YES")
    else:print("NO")
def ispow(a,b):
    now=b
    while now<a:
        now*=b
    return now==a
def getbin(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def getfacs(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod_>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def nextcomb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:return num
def getprimes(n):
    if n==0:return []
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    ret=[]
    for a in range(n+1):
        if(A[a]):ret.append(a)
    return ret
def isprime(num):
    if(num<=1):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def ifelse(bbool,ret1,ret2):
    if bbool:return ret1
    else:return  ret2
def join(A,c=" "):
    n=len(A)
    A=list(map(str,A))
    return c.join(A)
def factorize(n):
    b = 2
    ret=defaultdict(int)
    while b * b <= n:
        while n % b == 0:
            n //= b
            ret[b]+=1
        b+=1
    if n > 1:ret[n]+=1
    return ret
def pm(x):
    return x//abs(x)
def inputintlist(): 
    return list(map(int,input().split()))
def inputfloatlist(): 
    return list(map(float,input().split()))
def tozero(A):
    ret=[None]*len(A)
    for a in range(len(A)):
        ret[a]=A[a]-1
    return ret
def istanchouzouka(A):
    f=True
    prev=min(A)-1
    for a in A:
        if prev>=a:
            f=False
        prev=a
    return f
def istanchouhigensyou(A):
    f=True
    prev=min(A)-1
    for a in A:
        if prev>a:
            f=False
        prev=a
    return f
def getallsum(A):
    s=sum(A)
    dp=defaultdict(int)
    dp[0]=1
    for a in range(0,len(A)):
        for b in range(s,-1,-1):
            if b-A[a]>=0:
                dp[b]+=dp[b-A[a]]
    return dp
def yuukoutomukou(edges):
    ret=deepcopy(edges)
    for edge in edges:
        if not edge.x==edge.y:
            ret.append(Edge(edge.y,edge.x,edge.val))
    return ret
def dijkstra(edges,V,start):
    mincost=[inf]*V
    G=[[] for a in range(V)]
    for edge in edges:
        G[edge.x].append([edge.val,edge.y])
    Q=PriorityQueue()
    Q.put([0,start])#[cost,x]
    while not Q.empty():
        nowcost,nowx=Q.get()
        if mincost[nowx]==inf:
            mincost[nowx]=nowcost
            for cost,y in G[nowx]:
                newcost=nowcost+cost
                Q.put([newcost,y])
    return mincost
def warshallfloyd(edges,V):
    mincost=[[inf for b in range(V)] for a in range(V)]
    for a in range(V):mincost[a][a]=0
    for edge in edges:
        mincost[edge.x][edge.y]=min(mincost[edge.x][edge.y],edge.val)#x→yが複数ある場合のためにmin()する
    for k in range(V):
        for s in range(V):
            for t in range(V):
                if mincost[s][k]==inf or mincost[k][t]==inf:continue
                mincost[s][t]=min(mincost[s][t],mincost[s][k]+mincost[k][t])
    return mincost
def bellemanford(edges,V,start):
    mincost=[inf]*V
    mincost[start]=0
    for _ in range(V):
        for edge in edges:
            if mincost[edge.x]==inf:continue
            mincost[edge.y]=min(mincost[edge.y],mincost[edge.x]+edge.val)
    return mincost
def getmd(x1,y1,x2,y2):
    return abs(x1-x2)+abs(y1-y2)
def geted(x1,y1,x2,y2):
    return math.sqrt((x1-x2)**2+(y1-y2)**2)
class fordfulkerson():
    def __init__(self,edges,V,s,t):
        self.V=V
        self.used=[False]*V
        self.G=[[] for a in range(V)]
        self.s=s
        self.t=t
        for edge in edges:
            self.G[edge.x].append({"x":edge.x,"y":edge.y,"cap":edge.val,"rev":len(self.G[edge.y])})
            self.G[edge.y].append({"x":edge.y,"y":edge.x,"cap":0,"rev":len(self.G[edge.x])-1})
    def dfs(self,v,t,f=inf):
        if v==t:return f
        self.used[v]=True
        for a in range(len(self.G[v])):
            x=self.G[v][a]["x"]
            y=self.G[v][a]["y"]
            cap=self.G[v][a]["cap"]
            rev=self.G[y][self.G[x][a]["rev"]]
            if self.used[y] or cap==0:continue
            f2=self.dfs(y,t,min(f,cap))
            if f2>0:
                self.G[v][a]["cap"]-=f2
                rev["cap"]+=f2
                return f2
        return 0
    def maxflow(self):
        flow=0
        while True:
            self.used=[False]*V
            zouka=self.dfs(self.s,self.t)
            if zouka==0:break
            flow+=zouka
        return flow
def heron(a,b,c):
    s=(a+b+c)/2
    S=s(s-a)(s-b)(a-c)
    S=math.sqrt(S)
    return S
def getAreaOfTriangle(x1,y1,x2,y2,x3,y3):
    a=geted(x1,y1,x2,y2)
    b=geted(x2,y2,x3,y3)
    c=geted(x3,y3,x1,y1)
    return heron(a,b,c)






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

X,N=inputintlist()
P=inputintlist()
nums=set(list(range(-100,200)))
minabs=inf
minnum=inf
for p in P:
    nums.remove(p)
for a in nums:
    if abs(a-X)<minabs:
        minabs=abs(a-X)
        minnum=a
    elif abs(a-X)==minabs:
        if minnum>a:
            minnum=a
print(minnum)

Submission status: Accepted

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

d_min = 300
i_ans = 300
for i in range(100+1,-100-1,-1):
    if i not in p:
        if abs(x-i) <= d_min:
            d_min = min(d_min,abs(x-i))
            i_ans = i

print(i_ans)

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
# from fractions import gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    X, N = MAP()

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

    P = LIST()

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
ans = 0
m = float('inf')
for i in range(102):
    if i in p:
        continue
    else:
        if abs(x - i) < m:
            ans = i
            m = abs(x - i)
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
x,n = [int(j) for j in input().split()]
l = set([int(j) for j in input().split()])
ans1 = x+n
for i in range(x, x+n):
    if i not in l:
        ans1 = i
        break
for i in range(x, -1, -1):
    if i not in l:
        ans2 = i
        break
if abs(ans1-x)<abs(ans2-x):
    print(ans1)
else:
    print(ans2)

Submission status: Accepted

Solution code:
from collections import Counter
def main():
    X,N = map(int, input().split())
    p = list(map(int, input().split()))
    counter = Counter(p)
    gap = 0
    while 1:
        if counter.get(X-gap,0)==0:
            print(X-gap)
            return
        elif counter.get(X+gap,0)==0:
            print(X+gap)
            return
        else:
            gap+=1


main()

Submission status: Accepted

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

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

ans, min_diff = None, float('inf')
for n in range(102):
    if n in P:
        continue

    diff = abs(X - n)
    if diff < min_diff:
        min_diff = diff
        ans = n

print(ans)

Submission status: Accepted

Solution code:
import sys

if __name__ == "__main__":
    X, N = [int(x) for x in input().split(" ")]
    if N == 0:
        print(X)
        sys.exit(0)
    P = set([int(x) for x in input().split(" ")])
    for diff in range(10 ** 3):
        if (X - diff) not in P:
            print(X - diff)
            sys.exit(0)
        if (X + diff) not in P:
            print(X + diff)
            sys.exit(0)

Submission status: Accepted

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

if x not in p:
  print(x)
  exit()
l = x - 1
r = x + 1

while True:
  if l not in p:
    print(l)
    exit()
  if r not in p:
    print(r)
    exit()
  l -= 1
  r += 1

Submission status: Accepted

Solution code:
x, n, *lst = map(int, open(0).read().split())
for i in range(x + 1):
  if x - i not in lst:
    print(x - i)
    quit()
  if x + i not in lst:
    print(x + i)
    quit()

Submission status: Accepted

Solution code:
# C

X,N=map(int,input().split())
p=list(map(int,input().split()))
q=[]
for i in range(0,102):
    if i not in p:
        q.append(i)
R=len(q)
M= [ [ q[i],abs(q[i]-X)] for i in range(R)]
#print(M)
M.sort(key=lambda x:x[0])
M.sort(key=lambda x:x[1])
print(M[0][0])

Submission status: Accepted

Solution code:
# import sys
# import math #sqrt,gcd,pi
# import decimal
# import queue # queue
# import bisect
# import heapq # priolity-queue
# import time
# from itertools import product,permutations,\
#     combinations,combinations_with_replacement
# 重複あり順列、順列、組み合わせ、重複あり組み合わせ
# import collections # deque
# from operator import itemgetter,mul
# from fractions import Fraction
# from functools import reduce

mod = int(1e9+7)
# mod = 998244353
INF = 1<<50

def readInt():
    return list(map(int,input().split()))

def main():
    x,n = readInt()
    if not n:
        print(x)
        return
    p = readInt()
    p.sort()
    res_min = 0
    for i in range(100):
        if x-i not in p:
            res_min = max(x-i,res_min)
    res_max = INF
    for i in range(100):
        if x+i not in p:
            res_max = min(x+i,res_max)
    if (x-res_min)<=(res_max-x):
        print(res_min)
    else:
        print(res_max)
    return

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    import sys
    sys.setrecursionlimit(10**9)
    input = sys.stdin.readline

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

    P = list(map(int, input().split()))
    check = 0
    while True:
        if not X-check in P:
            print(X-check)
            return
        if not X+check in P:
            print(X+check)
            return
        check += 1    

main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
"""    Arnab Chanda    """

from collections import defaultdict, deque
from itertools import permutations
from sys import stdin,stdout
from bisect import bisect_left, bisect_right
from copy import deepcopy
import heapq

int_input=lambda : int(stdin.readline())
string_input=lambda : stdin.readline().split()
multi_int_input =lambda : map(int, stdin.readline().split())
multi_input = lambda : stdin.readline().split()
list_input=lambda : list(map(int,stdin.readline().split()))
string_list_input=lambda: list(string_input())
MOD = pow(10,9)+7


x, n = multi_int_input()

arr = list_input()

arr = set(arr)

a = 0

while(True):
    l = x - a
    r = x + a

    if (l not in arr):
        print(l)
        break
    elif (r not in arr):
        print(r)
        break

    a+=1

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
if n==0:
    print(x)
    exit()
p=list(map(int,input().split()))
for i in range(200):
    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(map(int, input().split()))
xp = x
xm = x
for i in range(n+1):
    if not xm in p:
        print(xm)
        exit()
    if not xp in p:
        print(xp)
        exit()
    xp += 1
    xm -= 1

Submission status: Accepted

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

for i in range(100):
    if not X + i in P:
        p = X + i
        break

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

if abs(X-p) == abs(X-q):
    print(q)
elif abs(X-p) > abs(X-q):
    print(q)
else:
    print(p)

Submission status: Accepted

Solution code:
nums = set(range(-200, 200))

X, N = map(int, input().split())
p = set(map(int, input().split()))
dist = 10**9
ans = 10**9

for k in sorted(nums - p):
    if abs(X - k) < dist:
        ans = k
        dist = abs(X - k)
print(ans)

Submission status: Accepted

Solution code:
def solve(X, P):
    if X not in P:
        return X
    l = X
    while l in P:
        l -= 1
    r = X
    while r in P:
        r += 1
    return min(l, r, key=lambda x: (abs(x - X), x))


def main():
    X, N = map(int, input().split())
    P = [int(p) for p in input().split()]
    print(solve(X, P))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
inf = float('inf')


def resolve():
    x, n = map(int, input().split())
    if n == 0:
        print(x)
        return
    p = list(map(int, input().split()))

    ans = inf
    score = inf
    for i in range(-1, 102):
        tmp = abs(x - i)
        if score > tmp and i not in p:
            ans = i
            score = tmp
    print(ans)

if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
from bisect import bisect_left as bl
ox, n = map(int, input().split())
if n == 0:
    print(ox)
    exit()
a = list(map(int, input().split()))
a.sort()
x = ox
i = bl(a, x)
while i < n and a[i] == x:
    i += 1
    x += 1
up = x
x = ox
i = bl(a, x)
while i >= 0 and a[i] == x:
    i -= 1
    x -= 1
down = x
if up-ox < ox-down:
    print(up)
else:
    print(down)

Submission status: Accepted

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

if N == 0:
  print(X)
else:
  P = sorted(list(map(int, input().split())))
  ans = X
  for i in range(101):
    if X - i not in P:
      ans = X - i
      break
    else:
      if X + i not in P:
        ans = X + i
        break
      
  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()
else:
    sa = 1
    while True:
        if X - sa not in p:
            print(X - sa)
            exit()
        elif X + sa not in p:
            print(X + sa)
            exit()
        sa += 1

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
num=list(map(int,input().split()))
mini=1000
ans=x
for i in range(102,-1,-1):
    if i in num:
        continue
    if abs(x-i)<=mini:
        mini=abs(x-i)
        ans=i
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
from sys import setrecursionlimit
from collections import Counter, deque, defaultdict
from math import floor, ceil
from bisect import bisect_left
from itertools import combinations
setrecursionlimit(100000)

INF = int(1e10)
MOD = int(1e9 + 7)

def main():
    from builtins import int, map
    X, N = map(int, input().split())
    P = list(map(int, input().split()))
    # X = 100
    # N = 100
    # P = list(range(1, 101, 1))

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

    sel_X = -1
    diff_X = float("inf")
    for x in range(-200, 200, 1):
        if x in P:
            continue
        if abs(x - X) < diff_X:
            sel_X = x
            diff_X = abs(x - X)
    print(sel_X)



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
x, n = list(map(int, input().split()))
if n == 0:
    print(x)
    exit()
else:
    p = list(map(int, input().split()))
list_ = [i for i in range(-1, max(p) + 2)]
res = -1
for i in list_:
    if i in p:
        pass
    else:
        if abs(i - x) < abs(res - x):
            res = i
print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
X,N = map(int,input().split())
if(N != 0):
 P = list(map(int,input().split()))
 ans_l = []
 ans = float('inf')
 for j in range(102):
   if(j in P):
      continue
   else:
      if(abs(ans-X)>abs(j-X)):
        ans = j
else:
  ans = X     
  
print(ans)

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
p = set(map(int, (input().split())))
i = 1
while True:
    j = ((i%2)*2-1) * (i//2)
    # print(j)
    if X+j not in p:
        ans = X+j
        break
    i += 1
print(ans)

Submission status: Accepted

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

  for i in range(0,101):
    check=x-i
    if not check in p:
      print(check)
      break
    check=x+i
    if not check in p:
      print(check)
      break

if n==0:
  print(x)

Submission status: Accepted

Solution code:
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

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

dist_min = 1000000
ans = 10000
for i in range(-10, 110):
    if i in P:
        continue
    else:
        dist = abs(X-i)
        # print(i, dist)
        if dist_min>dist:
            dist_min = dist
            ans = i
print(ans)

Submission status: Accepted

Solution code:
X, N = map(int,input().split())
P = set(map(int,input().split()))
tmp = 101
for i in range(-100,110):
    if i in P:
        continue
    elif tmp > abs(X-i):
        tmp = abs(X-i)
        ans = i
print(ans)

Submission status: Accepted

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

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

diff = 1
while True:
    if X - diff not in ps:
        print(X - diff)
        exit()
    elif X + diff not in ps:
        print(X + diff)
        exit()
    diff += 1

Submission status: Accepted

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

ans1 = X
ans2 = X

while True:

    if not ans1 in P:
        print(ans1)
        exit()
    if not ans2 in P:
        print(ans2)
        exit()
    ans1 -= 1
    ans2 += 1

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math as mt
#import numpy as np

def ro(n):
  return mt.floor(mt.sqrt(n))
def ya():
  print("Yes")
  return
def na():
  print("No")
  return


x,n=map(int,input().split())
if n>0:
  lis=list(map(int,input().split()))
  lis.sort()
#n=int(input())
#s=input()
kai=1

while 1:
  if n==0:
    break
  if not x in lis:
    break
  x-=kai
  kai+=1
  if not x in lis:
    break
  x+=kai
  kai+=1
print(x)

Submission status: Accepted

Solution code:
import numpy as np

x, n = list(map(int, input().split()))
ps = list(map(int, input().split()))
cand = [i for i in range(-2, 110) if i not in ps]
abs_cand = [abs(x - c - 0.1) for c in cand]

print(cand[np.array(abs_cand).argmin()])

Submission status: Accepted

Solution code:

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

for i in range(100):

  if X-i in P:
    pass
  else:
    print(X-i)
    break

  if X+i in P:
    pass
  else:
    print(X+i)
    break

Submission status: Accepted

Solution code:
X,N = map(int,input().split())
if N==0:
  print(X)
else:
  p = list(map(int,input().split()))
  if X in p:
    p.remove(X)
    ans = 0
    for i in range(1,100):
      a = X+i
      b = X-i
      if b in p:
        p.remove(b)
      else:
        ans = b
        break

      if a in p:
        p.remove(a)
      else:
        ans = a
        break

    print(ans)
  else:
    print(X)

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
p = list(map(int,input().split()))
ans = x
for i in range(300):
    if ans in p:
        ans += (-1)**(i+1)*(i+1)
    else:
        print(ans)
        break

Submission status: Accepted

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

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

tmp = 1

if X not in PList or N == 0:
    print(X)

else:
    while 'true':
        if X - tmp not in PList:
            print(X - tmp)
            break
        elif X + tmp not in PList:
            print(X + tmp)
            break
        else:
            tmp += 1

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
X, N = map(int, input().split())
# 文字列の入力
#s = input()
#開業されたN個要素を受け付ける
p_list = list(map(int, input().split()))

ans = -1

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

print(ans)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
if n > 0:
  p = sorted(list(map(int, input().split())))
  if not x in p:
    print(x)
  else:
    ans = 0
    m = 1000
    for i in range(0, 102):
      if not i in p:
        d = abs(x-i)
        if d < m:
          m = d
          ans = i
    print(ans)
else:
  print(x)

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
a =  set(map(int, input().split()))
l,r = x,x
while l in a:
    l-=1
while r in a:
    r+=1
if x-l<=r-x:
    print(l)
else:
    print(r)

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
P = set(map(int, input().split()))
i = 0
while True:
    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,*p = map(int, open(0).read().split())
ps = set(p)
if X not in ps:
    print(X)
else:
    for i in range(1,101):
        if X - i not in ps:
            print(X-i)
            break
        if X + i not in ps:
            print(X+i)
            break

Submission status: Accepted

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

def main():
    X, N = map(int, input().split())
    A = set(map(int, input().split()))

    for i in range(1000):
        if not X-i in A:
            print(X-i)
            break
        elif not X+i in A:
            print(X+i)
            break

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy


if __name__ == "__main__":
    x,n = map(int,input().split())
    p = set(list(map(int,input().split())))
    ans = 10000000000
    for i in range(-1000,1001):
        if i in p:
            continue
        else:
            d = abs(x-i)
            if d < ans:
               ans = d
               check = i 
    print(check)

Submission status: Accepted

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

ans = 0
mini = 1000
for i in range(-1000, 1000):
    if not i in p:
        if abs(X - i) < mini:
            mini = abs(X - i)
            ans = i
print(ans)

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
p = list(map(int,input().split()))
p = set(p)
i = 0
while True:
    ans1 = x+i
    ans2 = x-i
    if ans1 not in p and ans2 not in p:
        print(min(ans1,ans2))
        exit()
    elif ans1 not in p:
        print(ans1)
        exit()
    elif ans2 not in p:
        print(ans2)
        exit()
    else:
        i += 1
        continue

Submission status: Accepted

Solution code:
def main():
    X, N = map(int, input().split())
    P = list(map(int, input().split())) if N else []

    ans = X

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

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)


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


if __name__ == '__main__':
    main(sys.stdin.readline, print)

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()))
p.sort()

num = 0
ans = 10 ** 9
for i in range(102):
	if num < len(p) and i == p[num]:
		num += 1
		continue
	if ans > abs(x-i):
		ans = abs(x-i)
		res = i

print(res)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    x, N = map(int, readline().split())

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

    P = set([int(i) for i in readline().split()])

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



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys

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

# print(sorted(P))

now = 0
while 1:
    if X - now not in P:
        print(X - now)
        sys.exit()
    elif X + now not in P:
        print(X + now)
        sys.exit()
    now += 1