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:
def LI():return list(map(int,input().split()))
def MI():return map(int,open(0).read().split())
def I():return int(input())
def yes():print("Yes")
def no():print("No")

# from collections import deque, Counter
# from heapq import heappop, heappush
INF=float("inf")
# import math
# pi=math.pi

# import numpy as np
x,n=LI()
if n==0:
    print(x)
    exit()
p=LI()
p.sort()

ans=-1
tmp=INF
for i in range(-100,200):
    if i in p:continue
    k=abs(i-x)
    if k<tmp:
        tmp=k
        ans=i
    # print(i,k,ans)
print(ans)

Submission status: Accepted

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

  i=0
  while True:
    koho1=x-i
    koho2=x+i
    if not (koho1 in p_list):
      ans=koho1
      break
    if not (koho2 in p_list):
      ans=koho2
      break
    i=i+1
  print(ans)

Submission status: Accepted

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

    # if (X not in P_set) :
    #     print(X)
    #     return

    distance = 0
    while(True) :
        ck = X - distance
        if (ck not in P_set) :
            print(ck)
            return
        
        ck = X + distance
        if (ck not in P_set) :
            print(ck)
            return
        
        distance += 1

main()

Submission status: Accepted

Solution code:
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(500000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

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

now=0
for i in range(102):
    if i not in p:
        if abs(x-now)>abs(x-i):
            now=i
    # print(i)
print(now)

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

S_ans = X
L_ans = X

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

Submission status: Accepted

Solution code:
import sys

def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))
def RN(N): return [input().strip() for i in range(N)]


def main():
    X, N = MI()
    p = LI()
    W = X
    Y = X


    while True:

        if (W not in p)and (Y not in p):
            ans = W
            break
        elif (W not in p) and (Y in p):
            ans = W
            break
        elif (W in p) and (Y not in p):
            ans = Y
            break
        W -= 1
        Y += 1 
    print(ans)


    
    print()

if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
#!python3.8
# -*- coding: utf-8 -*-
# abc170/abc170_c
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    X, N = i2nn()
    if N == 0:
        print(X)
        return
    p = set(i2nn())
    for i in range(101):
        if X - i not in p:
            print(X - i)
            return
        if X + i not in p:
            print(X + i)
            return

    return

main()

Submission status: Accepted

Solution code:
import bisect

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

Pst = set(Ps)

ab = 200
tmp = 200
rlt = -1
for i in range(102):
  if i in Pst:
    continue
  else:
    tmp = abs(i-X)
    if ab > tmp:
      ab = tmp
      rlt = i
      
print(rlt)

Submission status: Accepted

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

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

p=sorted(p)

dist=10*9
ans=102
for i in range(102,-2,-1):
    if abs(x-i)<=dist and i not in p:
        dist = abs(x-i)
        ans = i
        if i<=ans:
            ans = i
        

print(ans)

Submission status: Accepted

Solution code:
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
from collections import Counter
import queue
import copy
import bisect
import heapq
import itertools


#sys.setrecursionlimit(10**7)
#N, Q = map(int, input().split())
#G = [list(input()) for i in range(H)]
#INF = V * 10001
#A = [int(i) for i in input().split()]
#AB = [list(map(int, input().split())) for _ in range(K)]

X,N = map(int,input().split())
p = [str(i) for i in input().split()]
ans = 0
flag = 1


for i in range(100):
  if(str(X-i) in p):
    pass
  else:
    ans = X-i
    break
  if(str(X+i) in p):
    pass
  else:
    ans = X+i
    break

print(ans)

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

count = 1
while True:
    minus = X - count
    if minus not in P:
        print(minus)
        exit()

    plus = X + count
    if plus not in P:
        print(plus)
        exit()

    count += 1

Submission status: Accepted

Solution code:
#C
X,N = map(int, input().split())
P = list(map(int, input().split()))
for i in range(0,110):
    if X-i not in P:
        print(X-i)
        break
    elif X+i not in P:
        print(X+i)
        break

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
if n==0:
  print(x)
else:
  p=list(map(int,input().split()))
  p.sort()
  ans=0
  on=1
  dif=1
  if x in p:
    now=p.index(x)
    while on==1:
      if now-dif<0:
        ans=x-dif
        on=0
      elif p[now-dif]!=x-dif:
        ans=x-dif
        on=0
      elif now+dif==n:
        ans=x+dif  
        on=0
      elif p[now+dif]!=x+dif:
        ans=x+dif
        on=0
      else:
        dif+=1
    print(ans)
  else:
    print(x)

Submission status: Accepted

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

def check(l, m):
    flag = True
    for i in l:
        if i == m:
            flag = False
            break
    return flag

if check(p, s):
    print(s)
    exit()
if check(p, t):
    print(t)
    exit()

while True:
    s = s - 1
    t = t + 1
    # print(s, t)
    if check(p, s):
        print(s)
        exit()
    if check(p, t):
        print(t)
        exit()

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
p=list(map(int,input().split()))
a=[0 for i in range(102)]
for i in range(n):
    a[p[i]]+=1
k=0
while True:
    if a[x-k]==0:
        print(x-k)
        break
    
    if a[x+k]==0:
        print(x+k)
        break
    k+=1

Submission status: Accepted

Solution code:
def main():
    x, n = [int(e) for e in input().split()]
    P = set([int(e) for e in input().split()])

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

    d = 1
    while True:
        a = x - d
        if a not in P:
            print(a)
            exit()

        a = x + d
        if a not in P:
            print(a)
            exit()

        d += 1


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
if N != 0:
    P = [int(i) for i in input().split()]
else:
    P = []
m = float("inf")
ans = 0
l = set(range(-1000, 1001)) - set(P)
for p in sorted(l):
    d = abs(p-X)

    if d < m:
        m = d
        ans = p

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
X, N = map(int,input().split())
p = list(map(int,input().split()))
hoge = {}
for i in p:
    hoge[i] = 1

m = X
while m in hoge:
    m -= 1
p = X
while p in hoge:
    p += 1
if p-X < X-m:
    print(p)
else:
    print(m)

Submission status: Accepted

Solution code:
def main():
    X, N = map(int, input().split())
    P = list(map(int, input().split()))
    P.sort()
    ans = 10000
    value = 100000
    for i in range(-1000,1000):
        if i in P:
            continue
        if ans > abs(X - i):
            ans = abs(X-i)
            value = i

    print(value)
            




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()))
s=x-1
b=x+1
if x not in p:
	print(x)
else:
	while True:
		if s not in p:
			print(s)
			exit()
		s-=1
		if b not in p:
			print(b)
			exit()
		b+=1

Submission status: Accepted

Solution code:
x, n, *p = map(int, open(0).read().split())
ans1 = x
while ans1 in p:
    ans1 += 1
ans2 = x
while ans2 in p:
    ans2 -= 1

if abs(ans2-x) < abs(ans1-x):
    print(ans2)
elif abs(ans2-x) > abs(ans1 - x):
    print(ans1)
else:
    print(min(ans1,ans2))

Submission status: Accepted

Solution code:
import sys, os, math, bisect, itertools, collections, heapq, queue
from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict

# import fractions

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    X, N = il()
    P = il()

    ret = 0
    s = MAX
    for n in range(-101, 102):
        if n not in P and abs(X-n) < s:
            s = abs(X-n)
            ret = n
    print(ret)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
X,N = map(int,input().split())
if N != 0:
    P = list(map(int,input().split()))
if N == 0:
    P = [3.2]
judge = P[0]
if X not in P:
    print(X)
plusminus = 0
if X in P:
    while True:
        plusminus +=1
        if X-plusminus not in P:
            
            print (X-plusminus)
            break
        elif X+plusminus not in P:
            print(X+plusminus)
            break

Submission status: Accepted

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

import sys
if n==0:
    print(x)
    sys.exit()
p=list(map(int,input().split()))
if x not in p:
    print(x)
    sys.exit()
min=x
max=x

while True:
    min-=1
    max+=1
    if min not in p:
        ans=min
        break
    if max not in p:
        ans=max
        break
print(ans)

Submission status: Accepted

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

p.sort()
def main():
    l = [True for _ in range(100)]
    for x in p:
        l[x-1] = False
    diff = 0
    while True:
        if X-1 -diff < 0:
            print(0)
            return
        elif l[X-1 -diff]:
            print(X -diff)
            return
        elif X-1 +diff >= 100:
            print(101)
            return
        elif l[X-1 +diff]:
            print(X +diff)
            return
        diff += 1

main()

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())
if N == 0:
  print(X)
  exit()
p = list(map(int, input().split()))
ans = -float('inf')
d = float('inf')
for i in range(-10, 2100):
  if i not in p:
    if abs(X-i) < d:
      d = abs(X-i)
      ans = i

print(ans)

Submission status: Accepted

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

ans = 0
tmpabs = 150

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

for i in range(110):
    if i not in P and tmpabs > abs(X-i):
        ans = i
        tmpabs = abs(X-i)

print(ans)

Submission status: Accepted

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

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

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

Sa = []

Ba = list(range(-1, 102))
Cha = list(range(-1, 102))

for i in range (0, N):
	if Ba.count(P[i]) > 0:
		Cha.remove(P[i])

Denbaba = len(Cha)

for i in range (0, Denbaba):
	Sa.append(abs(Cha[i]-X))

Da = min(Sa)

for i in range (0, Denbaba):
	if Sa[i] != Da:
		Cha[i]=1000000


print(min(Cha))

Submission status: Accepted

Solution code:
a,b = map(int,input().split())
z = list(map(int,input().split()))
if a in z:
	j =1
	while True:
		if (a-j) not in z:
			print(a-j)
			break
		if a+j not in z :
			print(a+j)
			break
		j+=1
else:
	print(a)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


def solve(X: int, N: int, p: "List[int]"):
    if N == 0:
        print(X)
        return
    
    arr = [0 for _ in range(102)]

    for i in p:
        arr[i] = 1
    
    i = 0
    while True:
        if not arr[X - i]:
            print(X - i)
            return
        elif not arr[X + i]:
            print(X + i)
            return
        i += 1
    return


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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
X,N=map(int, input().split())
if N==0:
  print(X)
  exit()
P=list(map(int, input().split()))  
ans=-1
for i in range(-1,102):
  if i not in P:
    if abs(X-i)<abs(X-ans):
      ans=i
print(ans)

Submission status: Accepted

Solution code:
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


x, n = LI()
p = LI()
if n == 0:
    print(x)
    sys.exit()

ans = 10000
for i in range(-1, 102):
    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())
if N > 0:
    p = list(map(int, input().split()))
    for i in range(100):
        now_p = X+i
        now_m = X-i
        if not now_m in p:
            ans=now_m
            break
        elif not now_p in p:
            ans = now_p
            break
else:
    ans = X

print(ans)

Submission status: Accepted

Solution code:
x, n = [int(x) for x in input().split()]
arr = [int(x) for x in input().split()]
arr.append(n)
arr = set(arr)
a = 0
ans = 0
while True:
    if (x - a) not in arr:
        ans = x-a
        break
    if (x + a) not in arr:
        ans = x+a
        break
    a += 1
print(ans)

Submission status: Accepted

Solution code:
def resolve():
    X, N = [int(i) for i in input().split()]
    if N == 0:
        print(X)
        return
    P = sorted([int(i) for i in input().split()])
    if X not in P:
        print(X)
        return
    for i in range(100):
        if (X - i) not in P:
            print(X - i)
            return
        if (X + i) not in P:
            print(X + i)
            return


resolve()

Submission status: Accepted

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

if N != 0:
    p = [int(i) for i in input().split()]

ans = 0
if N == 0:
    ans = X
else:

    for i in range(N):
        key = X - i

        if key in p:
            pass
        else:
            ans = key
            break

        key = X + i

        if key in p:
            pass
        else:
            ans = key
            break

print(ans)

Submission status: Accepted

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

if n == 0 or not x in p:
    print(x)
    sys.exit()
c = 1
while True:
    if not x-c in p:
        print(x-c)
        sys.exit()
    if not x+c in p:
        print(x+c)
        sys.exit()
    c+=1

Submission status: Accepted

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

ans = X
for i in range(101):
    a = X + i
    b = X - i
    if a not in P_set:
        ans = a
        if b not in P_set:
            ans = b
        break
    if b not in P_set:
        ans = b
        break
print(ans)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    X, N = [int(x) for x in input().split()]
    P = [int(x) for x in input().split()]

    if N == 0:
        print(X)
        return

    sa = 10000
    ans = []
    for i in range(-100, 102):
        if i in P:
            continue

        tmpans = sa
        sa = min(sa, abs(X - i))
        ans.append([sa, i])


    ans.sort()
    print(ans[0][1])



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
P = list(map(int,input().split()))
ans = 0
if P:
    for i in range(1,300):
        if i not in P:
            if abs(x-i) < abs(x-ans):
                ans = i
else:
    ans = x

print(ans)

Submission status: Accepted

Solution code:
x,n,*a=map(int,open(0).read().split())
b=[1]*103
for i in a:
    b[i]=0
c=1000 
ans=n
for i in range(102):
    if b[i] and c>abs(x-i):
        c=abs(x-i)
        ans=i
print(ans)

Submission status: Accepted

Solution code:
import sys
a=input()
a0=a.split()
x=int(a0[0])
n=int(a0[1])
if n==0:
    print(x)
    sys.exit()
p=input()
pl=list()
p=p.split()
k=-1
for i in range(n):
    pl.append(int(p[i]))
for i in range(102):
    q=i in pl
    if q==False :
        if abs(i-x)<abs(k-x):
            k=i
        else:
            print(k)
            sys.exit()
print(k)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:

def main():
  x, n = list(map(int, input().split()))
  if n == 0:
    print(x)
    exit()
  pp = list(map(int, input().split()))
  
  i = 0
  while True:
    if x-i not in pp:
      print(x-i)
      exit()
    if x+i not in pp:
      print(x+i)
      exit()
    i += 1
  
  
if __name__ == "__main__":
  main()

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline
x, n = map(int, input().split())
p = list(map(int, input().split()))
for i in range(100):
    s = x - i
    e = x + i
    if p.count(s) == 0:
        print(s)
        break
    elif p.count(e) == 0:
        print(e)
        break

Submission status: Accepted

Solution code:
x,n=[int(i) for i in input().split()]
p=[int(i) for i in input().split()]
np=[i for i in range(0,200) if not i in p]
r=0
for i in np:
    if abs(x-i)<abs(x-r):
        r=i
print(r)

Submission status: Accepted

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

pinv=[True for i in range(102)]

for i in p:
    pinv[i]=False

ab=1000
ans=-1
for i in range(102):
    if (i<0 or pinv[i]) and abs(x-i)<ab:
        ab=abs(x-i)
        ans=i

print(ans)

Submission status: Accepted

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

def get_result():
    for i in range(100):
        a = X - i
        b = X + i
        if not a in P:
            return a
        if not b in P:
            return b

print(get_result())

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
if n!=0:
    p=list(map(int,input().split()))
    L=[i for i in range(102) if i not in p]
    l=[abs(i-x) for i in L]
    key=l.index(min(l))
    print(L[key])
else:
    print(x)

Submission status: Accepted

Solution code:
import sys
x,n=map(int,input().split())
if n==0:
  print(x)
  sys.exit()
b=list(map(int,input().split()))
a=list(range(-1,102))
for i in b:
  a.remove(i)
mn=1000
j=1000
for i in a:
  c=abs(x-i)
  if c<mn:
    j=i
    mn=c    
  elif c==mn:
    j=min(j,i)
print(j)

Submission status: Accepted

Solution code:

import glob
import os

bn = os.path.basename(__file__).split('.')[0]
dn = os.path.dirname(__file__).split('/')

# 問題ごとのディレクトリのトップからの相対パス
REL_PATH = dn[len(dn)-2] + '\\' + dn[len(dn)-1] + '\\' + bn

# テスト用ファイル置き場のトップ
TOP_PATH = 'C:\\AtCoder'

class Common:

    problem = []
    index = 0

    def __init__(self, rel_path):
        self.rel_path = rel_path

    def initialize(self, path):
        file = open(path)
        self.problem = file.readlines()
        self.index = 0
        return

    def input_data(self):
        try:
            IS_TEST
            self.index += 1
            return self.problem[self.index-1]

        except NameError:
            return input()

    def resolve(self):
        pass

    def exec_resolve(self):
        try:
            IS_TEST
            for path in glob.glob(TOP_PATH + '\\' + self.rel_path + '/*.txt'):
                print("Test: " + path)
                self.initialize(path)
                self.resolve()
                print("\n\n")
        except NameError:
            self.resolve()


class Solver(Common):

    def resolve(self):

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

        result = [0,200]
        for i in range(0, 200):
            if i in p:
                continue
            if abs(X-i) < result[1]:
                result[0] = i
                result[1] = abs(X-i)
            elif abs(X-i) == result[1] and i < result[0]:
                result[0] = i

        print(str(result[0]))

solver = Solver(REL_PATH)
solver.exec_resolve()

Submission status: Accepted

Solution code:
from collections import defaultdict,deque
from sys import stdin,setrecursionlimit
import heapq,bisect,math,itertools,string,queue,datetime,copy
setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, stdin.readline().split()))

def main():
    x,n = inpl()
    Pls = inpl()

    for k in range(100):
        if x-k not in Pls:
            print(x-k)
            return
        elif x+k not in Pls:
            print(x+k)
            return
main()

Submission status: Accepted

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

ans_list = [i for i in range(102)]
for i in range(N):
    now = p[i]
    for j in range(len(ans_list)):
        if ans_list[j] == now:
            del ans_list[j]
            break
        
ans = 1000
k = 1000
for i in range(len(ans_list)):
    if abs(ans_list[i] - X) < ans:
        ans = abs(ans_list[i] - X)
        k = ans_list[i]

print(k)

Submission status: Accepted

Solution code:
X, N = list(map(int, input().split()))
if N==0:
    print(X)
else:
    ps = list(map(int, input().split()))
    sub_abs = 0
    while True:
        if (X-sub_abs) not in ps:
            print(X-sub_abs)
            break
        if (X+sub_abs) not in ps:
            print(X+sub_abs)
            break
        sub_abs += 1

Submission status: Accepted

Solution code:

#!/usr/bin/python
# -*- coding: utf-8 -*-

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


for x in range(0,101):
    if X-x not in p:
        print(X-x)
        exit()
    elif X+x not in p:
        print(X+x)
        exit()

Submission status: Accepted

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

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

else:
    p = list(map(int, input().split()))
    li = [i for i in range(-101, 102) if i not in p]
    li.sort(reverse = True)

    tmp1 = float('inf')
    ans = float('inf')

    for i in li:
        if abs(i - x) <= tmp1:
            if i < ans:
                ans = i
                tmp1 = abs(i - x)

    print(ans)

Submission status: Accepted

Solution code:
x, n  = map(int, input().split())
if n > 0:
  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
else:
  print(x)

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    x, n = map(int, input().strip().split())
    p = input().strip()

    if not p == "":
        p = list(map(int, p.split()))
        p.sort()

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

    else:
        print(x)

Submission status: Accepted

Solution code:
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

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

ans = X
for i in range(2 * N):
    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:
x,n=map(int,input().split())
if n>0:
	p=list(map(int,input().split()))
	ans,cnt=0,0
	while cnt<=100:
		if x-cnt not in p:
			ans=x-cnt
			break
		if x+cnt not in p:
			ans=x+cnt
			break
		cnt+=1
	print(ans)
else:
	print(x)

Submission status: Accepted

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

P = sorted(P)

prev = 1000
ans = 101
for i in range(101, -1, -1):
    if i in P:
        pass
    else:
        if abs(X-i) <= prev:
            ans = min(i, ans)
            prev = abs(X-i)
print(ans)

Submission status: Accepted

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

for i in range(102):
    if i in p:
        pass
    else:
        if abs(X-i)<d:
            d=abs(X-i)
            ans=i
        else:
            pass


print(ans)

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
p = list(map(int,input().split()))
now = 99999
ans = -200
ls = [(i+1) for i in range(-1000,1001)]
for i in range(len(p)):
    ls.remove(p[i])
k = []
for i in range(len(ls)):
    if abs(ls[i]-x) < now:
        now = abs(ls[i]-x)
        ans = ls[i]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
X,N = map(int,input().split())
P = list(map(int,input().split()))
move = 0
discover = True
while discover:
    nowdis = True
    for i in range(0,N):
        if P[i] == X + move:
            nowdis = False
    if nowdis == True:
        discover = False
        print(X + move)
    if move >= 0:
        move = (-1) * move - 1
    else:
        move = (-1) * move

Submission status: Accepted

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

ans = 300

for i in range(-100, 200):
    if i not in p:
        if abs(ans - x) > abs(i - x):
            ans = i

print(ans)

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
p = list(map(int, input().split()))
k = 0
ans = 0
c = True

while c:
    if (X - k) not in p:
        ans = X -  k
        c = False
        break
    elif (X + k) not in p:
        ans = X + k
        c = False
        break
    else:
        k += 1
        
print(ans)

Submission status: Accepted

Solution code:
X,N = map(int,input().split())
P = list(map(int,input().split()))
if P == []:
  print(X)
  exit()
for n in range(101):
  if X - n not in P:
    ans = X - n
    break
  if X + n not in P:
    ans = X + n
    break

print(ans)

Submission status: Accepted

Solution code:

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


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

p.sort()

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

for i in range(len(q)):
    if q[i] in p:
        q[i]=1000

d=[]
for i in range(len(q)):
    d.append(abs(X-q[i]))

a=min(d)

if X-a in q:
    print(X-a)
else:
    print(X+a)