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 iput(): return int(input())
def mput(): return map(int, input().split())
def lput(): return list(map(int, input().split()))

def solve():
    x, n = mput()
    p = lput()
    ans = []
    for i in range(x, x-n-1, -1):
        boo = i in p
        if boo != True:
            ans.append(i)
            break
    for i in range(x, x+n+1):
        boo = i in p
        if boo != True:
            ans.append(i)
            break
    if abs(x-ans[0]) <= abs(x-ans[1]):
        print(ans[0])
    else:
        print(ans[1])
    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
def main():
    X, N = map(int, input().split())
    p = set(list(map(int, input().split())))
    table = set()
    for i in range(1, 101):
        table.add(i)
    table = table - p
    lis = list(table)
    ans = -1
    diff = 10 ** 9
    for i, a in enumerate(lis):
        if abs(a-X) < diff:
            diff = abs(a-X)
            ans = a
        elif abs(a-X) == diff:
            ans = min(ans, a)
    if abs(X-ans) > abs(X-101):
        ans = 101
    if abs(X-ans) >= abs(X):
        ans = 0
    print(ans)
if __name__ == "__main__":
    main()

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

ans = X+10
tmp = []
P2 = [int(i) for i in range(-200,200)]
P3 = list(set(P2)-set(P))
P3.sort()
P3[::-1]
for i in P3:
    if ans > abs(X-i):
        ans = abs(X-i)
        tmp.append(i)
print(max(tmp))

Submission status: Accepted

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

i = 0

while X+i<=101 or X-i>=0:
    pflag = X+i in p
    mflag = X-i in p
    if pflag and mflag:
        i+=1
    else:
        if not mflag:
            print(X-i)
            exit()
        else:
            print(X+i)
            exit()

# if 101-X <= X:
#     print(0)
# else:
#     print(101)

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
l = list(map(int,input().split()))
if n == 0:
    print(x)
    exit()
sa = 0
ansa,ansb = x,x
while ansa in l and ansb in l:
    ansa -= 1
    ansb += 1
if not ansa in l:
    print(ansa)
else:
    print(ansb)

Submission status: Accepted

Solution code:
import os

x,n = (int(x) for x in input().split())
p = [int(i) for i in input().split()]

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

mini = 0
min = 1000
for b in range(-200,200):
    if min>abs(x-b):
        if b not in p:
            min = abs(x-b)
            mini = b

print(mini)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
try:
  p = list(map(int, input().split()))
except EOFError:
  print(100)
  exit()
old_diff = 10000
for i in range(-110, 110):
  if i in p:
    continue
  else:
    diff = abs(x-i)
    if diff < old_diff:
      ans = i
      old_diff = abs(x-i)

try:
  print(ans)
except:
  print()

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
if N==0: print(X)
else:
    p = list(map(int, input().split()))
    pd = [[] for _ in range(100)]

    for i in range(N):
        pd[abs(p[i]-X)].append(X - p[i])

    for i in range(1,100):
        if len(pd[i])==0:
            ans = X - i
            break
        elif len(pd[i])==1:
            ans = X + pd[i][0]
            break
    print(ans if pd[0]==[0] else X)

Submission status: Accepted

Solution code:
import sys
import math

x,n=list(map(int,input().split()))
l=list(map(int,input().split()))
dic={}
if n==0:
    print(x)
else:
    for i in l:
        dic[i]=0
    k=0
    while True:
        if not x-k in dic:  
            print(x-k)
            break
        if not x+k in dic:  
            print(x+k)
            break
        k+=1

Submission status: Accepted

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

for i in range(0,102):
    if i in p:
        continue
    if temp <= min(abs(i - x),temp):
        break
    temp = min(abs(i - x),temp)
    ans = i

print(ans)

Submission status: Accepted

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

check = x
tansaku = 1
count = 0
while True:
    count += 1
    if not(check in p_list):
        print(check)
        exit()
    
    check -= tansaku
    tansaku = -tansaku
    if tansaku <0:
        tansaku -= 1
    else:
        tansaku += 1
    if count >= 500:
        exit()

Submission status: Accepted

Solution code:
X,N=list(map(int,input().split()))
if N==0:
  print(X)
else:
  p_list=list(map(int,input().split()))
  not_p_list=[]
  for i in range(-105,105):
    if i not in p_list:
      not_p_list.append(i)

  nN=len(not_p_list)
  abs_list=[]
  for i in range(nN):
    temp=not_p_list[i]-X
    abs_list.append(abs(temp))

  abs_list.sort()    
  if abs_list[0]==0:
    print(X)
  else:
    ans=abs_list[0]
    for i in range(nN):
      if not_p_list[i]==X-ans:
        print(X-ans)
        break
      elif not_p_list[i]==X+ans:
        print(X+ans)
        break

Submission status: Accepted

Solution code:
in_1 = [int(x) for x in input().split(' ')]
x = in_1[0]
n = in_1[1]
result = 0

# n=0の場合、resultにxを設定する
if n == 0:
  result = x
# 絶対値が小さい順にin_dataに含まれるか検索し、含まれなければresultにx-i,もしくはx+1を設定する
else:
  in_data = [int(x) for x in input().split(' ')]
  for i in range(100):
    tmp_m = x-i
    tmp_p = x+i
#    print('tmp_m:{}'.format(tmp_m))
#    print('tmp_p:{}'.format(tmp_p))
    if tmp_m not in in_data:
      result = tmp_m
      break
    if tmp_p not in in_data:
      result = tmp_p
      break

print(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(1, n + 1):
        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=[int(_) for _ in input().split(" ")]

s=0
t=0
u=0
w=0
ans=0
flgs=0
flgt=0


for i in range(100):
  s = x + i
  t = x - i
  for j in range(n):
    if s==p[j]:
      flgs=1
  for k in range(n):
    if t==p[k]:
      flgt=1
  if flgs==1 and flgt==1:
    flgs=0
    flgt=0
  else:
    a = i
    break

if flgt == 0:
  ans = x - a
else:
  ans = x + a
  
print(ans)

Submission status: Accepted

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

    for d in range(101):
        if X-d not in P:
            print(X-d)
            return
        elif X+d not in P:
            print(X+d)
            return


##########
if __name__ == "__main__":
    c()

Submission status: Accepted

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

if N == 0:
    print(X)

else:
    p = list(map(int, input().split()))
    q = [i for i in range(-1, 102)]

    for r in p:
        idx = q.index(r)
        del q[idx]

    if X in q:
        print(X)

    else:
        q.sort()
        mindif = 1000

        for num in q:
            dif = abs(X - num)
            if mindif <= dif:
                break
            else:
                mindif = dif
                ans = num
        print(ans)

Submission status: Accepted

Solution code:
x, n = list(map(int, input().split()))
if n == 0:
  print(x)
  exit()
p = list(map(int, input().split()))
d = 1e9
ans = 0
for e in range(200, -1, -1):
  dd = abs(e - x)
  if e not in p and dd <= d:
    d = dd
    ans = e
print(ans)

Submission status: Accepted

Solution code:
X, N = map(lambda x: int(x), input().split(" "))
if N != 0:
    Ps = set(map(lambda x: int(x), input().split(" ")))
    result = 0
    for i in range(1, 102):
        if i in Ps:
            continue
        if abs(X-result) > abs(X-i):
            result = i
else:
    input()
    result = X

print(result)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
d = [0]*102
for i in p: d[i] = 1
if d[x] == 0:
    print(x)
else:
    i = 1
    while True:
        if x-i>=0:
            if d[x-i] == 0:
                print(x-i)
                break
        if x+i<=101:
            if d[x+i] == 0:
                print(x+i)
                break
        i += 1

Submission status: Accepted

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

Submission status: Accepted

Solution code:

def iput(): return int(input())
def mput(): return map(int, input().split())
def lput(): return list(map(int, input().split()))

def solve():
    x, n = mput()
    p = lput()
    ans = []
    for i in range(x, x-n-1, -1):
        boo = i in p
        if boo != True:
            ans.append(i)
            break
    for i in range(x, x+n+1):
        boo = i in p
        if boo != True:
            ans.append(i)
            break
    if abs(x-ans[0]) <= abs(x-ans[1]):
        print(ans[0])
    else:
        print(ans[1])
    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
X, N = list(map(int,input().split()))
if N >0:
    P =  list(map(int,input().split()))
else:
    print(X)
    exit()
# 
# ans = 1000
# P.sort()
# ok = len(P)
# ng = 0
# 
# while (ok - ng)> 1:
#     mid = (ok + ng) //2
#     if P[mid] > X:
#         ok = mid
#     else:
#         ng = mid
# 
# threshold = P[ok]
ans = None
for n in range(100):
    plus = X +n
    if plus not in P:
        ans = plus
    minus = X -n
    if minus not in P:
        ans = minus
    if ans is not None:
        print(ans)
        exit()

Submission status: Accepted

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

import sys
import math
from decimal import Decimal, ROUND_DOWN


debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        # for line in sys.stdin:
        #     lines.append(line)
        lines.append(input())
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]

    (x, n) = [int(e) for e in lines[0].split(' ')]
    if n >= 1:
        p = [int(e) for e in lines[1].split(' ')]
    else:
        p = []

    return (x, n, p)


def solve(x, n, p):
    
    pp = set(p)
    result = None
    for i in range(0, 99):
        xa = x - i
        xb = x + i

        if xa in pp:
            pass
        else:
            result = xa
            break

        if xb in pp:
            pass
        else:
            result = xb
            break


    return result
    


def main():
    # 出力
    result = solve(*parse_input())
    if isinstance(result, list):
        for r in result:
            print("%s" % r, sep='')
    else:
        print("%s" % result, sep='')

if __name__ == '__main__':

    main()

Submission status: Accepted

Solution code:
X,N = map(int,input().split())
try:
    li = list(map(int,input().split()))
except:
    li = []
flg=0
d=1
if X not in li:
    print(X)
    flg=1
while flg==0:
    if X+d in li and X-d in li:
        d+=1
    elif X+d not in li and X-d not in li:
        print(X-d)
        flg=1
    elif X+d not in li:
        print(X+d)
        flg=1
    else:
        print(X-d)
        flg=1

Submission status: Accepted

Solution code:
import sys

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

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

    if not x in ps:
        print(x)
        return

    for i in range(1,int((n+1)/2)+1):
        if not x-i in ps:
            print(x-i)
            return

        if not x+i in ps:
            print(x+i)
            return

main()

Submission status: Accepted

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

else :
    for i in range(0,200):
        s=x+i
        if s in p:
            pass
        else:
            ans = s
            break

    for n in range(0,200):
        m =x-n
        if m in p:
            pass
        else:
            anss = m
            ansss = x + n
            break
    if ansss <= ans:
        print(anss)
    else :
        print(ans)

Submission status: Accepted

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

for i in range(200):
    Y = X - i
    Z = X + i
    if Y not in p:
        print(Y)
        break
    elif Z not in p:
        print(Z)
        break

Submission status: Accepted

Solution code:
[X, N] = list(map(int, input().split()))
P = list(map(int, input().split()))
answer = 0
c = 0
N_min = X
N_max = X
while c == 0:
    if N_min not in P:
        answer = N_min
        c += 1
    elif N_max not in P:
        answer = N_max
        c += 1
    N_min = N_min - 1
    N_max = N_max + 1
print(answer)

Submission status: Accepted

Solution code:
def resolve():
  X, N = map(int, input().split(" "))
  if N == 0:
    print(X)
    return True

  p = [int(x) for x in input().split(" ")]
  set_p = set(p)

  for i in range(N+100):
    if (X-i) not in set_p:
      print(X-i)
      return True

    if (X+i) not in set_p:
      print(X+i)
      return True

if __name__ == "__main__":
  resolve()

Submission status: Accepted

Solution code:
X,N=map(int, input().split())
try: 
    p=list(map(int, input().split()))
except:
    print(X)
    exit(0)
if X not in p:
    print(X)
    exit(0)
c=1
while 1:
    if X-c not in p:
        print(X-c)
        exit(0)
    if X+c not in p:
        print(X+c)
        exit(0)
    c+=1

Submission status: Accepted

Solution code:
import collections
import sys

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

queue = collections.deque([X-1, X+1])

while True:
  cur = queue.popleft()
  if cur in p:
    if cur < X:
    	queue.append(cur-1)
    else:
    	queue.append(cur+1)
  else:
  	print(cur)
  	break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
p = list(map(int,input().split()))
ans = 1000000
a = 0
if x not in p:
    a = 1
else:#xがpに入っていない場合
    for i in range(n):
        ch = abs(x-p[i])
        ans = min(ans,ch)
count = x-ans-1
if a == 1:
    print(x)
elif count not in p:
    print(count)
else:
    for j in range(ans,10000,1):
        if (x-j>=0) and x-j not in p:
            print(x-j)
            break
        elif x+j not in p:
            print(x+j)
            break

Submission status: Accepted

Solution code:
import sys
x, n = (int(i) for i in input().split())
try:
    ps = [int(i) for i in input().split()]
    ps.sort()
    # print(x, n)
    # print(ps)
    result = 0
    d = 0
    while x-d > 0:
        if x-d not in ps:
            print(x-d)
            sys.exit()
        elif x+d not in ps:
            print(x+d)
            sys.exit()
        d += 1
    print(0)
except EOFError:
    print(x)

Submission status: Accepted

Solution code:
import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
x, n = M()
if n == 0:
    print(x)
else:
    n_l = LI()
    suchi_list = [i for i in range(-300, 300)] # 1~100までのリスト
    ans = -1
    for i in n_l:
        suchi_list.remove(i)
    if x in suchi_list:
        ans = x
    else:
        for j in range(1, 101):
            if x-j in suchi_list:
                ans = x-j
            elif x+j in suchi_list:
                ans = x+j
            if ans != -1:
                break
    print(ans)

Submission status: Accepted

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

if n == 0:
  print(x)
  sys.exit()
p = list(map(int, input().split()))
p.sort()

okList = [-1]*(300)
for i in range(len(okList)):
  okList[i] = i-150
for i in range(len(p)):
  okList[p[i]+150] = -1000

ans = 0
ans2 = 10000
for i in range(len(okList)):
  if okList[i] != -1000:
    if ans2 > abs(okList[i]-x):
      ans2 = abs(okList[i]-x)
      ans = okList[i]
print(ans)

Submission status: Accepted

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

        maxP = max(P)

        numList = [0 for i in range(maxP+2)]

        for num in P:
            numList[num] += 1
        
        maxRes = 101
        maxCount = 0
        minRes = 101
        minCount = 0

        for i in range(x, maxP+2):
            maxCount += 1
            if numList[i] == 0:
                maxRes = i
                break
        
        for i in range(x, -1, -1):
            minCount += 1
            if numList[i] == 0:
                minRes = i
                break

        if maxCount < minCount:
            print(maxRes)
        else:
            print(minRes)

    else:
        print(x)

    

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
X,N=map(int,input().split())
p=list(map(int,input().split()))
p_bar=[]
for i in range(0,102):
  if i not in p:
    p_bar.append(i)

d_min=1000
i_min = 0
for i in p_bar:
  d = abs(X-i)
  if d < d_min:
    d_min = d
    i_min = i
print(i_min)

Submission status: Accepted

Solution code:
import sys
x,n=map(int,input().split())
if n==0:
    print(x)
    sys.exit()
else:
    p=list(map(int,input().split()))
    res=1000
    ans=0
    for i in range(101,-101,-1):
        p.append(i)
        if len(p)==len(set(p)):
            if res>=abs(x-i):
                res=abs(x-i)
                ans=i
        del p[-1]
    print(ans)

Submission status: Accepted

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

ntmp = X-1
ptmp = X+1
while 0 <= ntmp or ptmp <= 100:
  if not ntmp in nList:
    print(ntmp)
    exit()
  if not ptmp in nList:
    print(ptmp)
    exit()
  ntmp -= 1
  ptmp += 1

Submission status: Accepted

Solution code:
import numpy as np
x,n = map(int,input().split())
if n!=0:
    p = list(map(int,input().split()))
    q = [i for i in range(-101,201)]
    r = set(q)-set(p)

    a = np.array(list(r))
    f = [x]*(len(list(r)))
    b = np.array(f)

    c = a-b
    d  = np.abs(c)
    e = np.argmin(d)

    print(int(c[int(e)])+x)
else:
    print(x)

Submission status: Accepted

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

pidx = 0
ansabs = 1000
for i in range(102):
    if pidx < n and i == p[pidx]:
        pidx += 1
        continue
    if ansabs > abs(i - x):
        ansabs = abs(i - x)
        ans = i

print(ans)

Submission status: Accepted

Solution code:
import sys

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

X,N = LI()
P_jyogai = LI()

P = list(range(-10000,10000))

P_difference = set(P)-set(P_jyogai)
P_difference = list(P_difference)
P_difference.sort()

sabun = 100000000
ans = 0
for p_diff in P_difference:
    temp = abs(X-p_diff)
    if sabun > temp:
        sabun = temp
        ans = p_diff
print(ans)

Submission status: Accepted

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

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

P_L = []
P_R = []

# for i in P:
#     if i <= x:
#         P_L.append(i)
#     else:
#         P_R.append(i)

A = True
i = 0

while A:
    if x - i not in P:
        print(x - i)
        A = False
    elif x + i not in P:
        print(x + i)
        A = False
    else:
        i += 1

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
if n!=0:
    p = list(map(int,input().split()))
    li = set([i for i in range(102)])
    li = li-set(p)
    k=10**9
    m=0
    li=sorted(list(li))
    for i in li:
        if k>abs(x-i):
            k=abs(x-i)
            m=i
    print(m)
else:
    print(x)

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
p = list(map(int, input().split()))
tip = 0
for i in range(3 * N):
    s = X - i
    t = X + i
    s_a = s not in p
    t_a = t not in p
    if tip == 0:
        if s_a:
            ans = s
            tip = 1
        elif t_a:
            ans = t
            tip = 1
if tip == 0:
    ans = X
print(ans)

Submission status: Accepted

Solution code:
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from math import factorial, sqrt, ceil, gcd, cos, radians, floor
from functools import lru_cache, reduce
from decimal import Decimal
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)

# UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

# 素因数分解
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# 2数の最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

# リストの要素の最小公倍数
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

# リストの要素の最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

# 素数判定
def is_prime(n):
    if n <= 1:
        return False
    p = 2
    while True:
        if p ** 2 > n:
            break
        if n % p == 0:
            return False
        p += 1
    return True


# limit以下の素数を列挙
def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P

# 同じものを含む順列
def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        # set（集合）型で重複を削除、ソート
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret


# ここから書き始める
x, n = map(int, input().split())
# y = [0 for i in range(100)]
p = list(map(int, input().split()))
# print("y =", y)
# for i in p:
#     y[i - 1] = 1
# print("y =", y)
# ans = 0
# gap = x
# for i in range(100):
#     if y[i] == 1:
#         continue
    # if i == 7:    
        # print(abs(x - i - 1))
    # if abs(x - i - 1) < gap:
    #     ans = i + 1
    #     gap = abs(x - i - 1)
        # print(gap)
# print(ans)

ans = -1
gap = INF
for i in range(102):
    if i in p:
        continue
    if abs(x - i) < gap:
        gap = abs(x - i)
        ans = i
print(ans)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = set(map(int, input().split()))
ans_can = set(range(-200, 200))
ans_can = sorted(list(ans_can - p))

ans = 10000000
for i in ans_can:
    if abs(x - i) < abs(x - ans):
        ans = i

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from sys import exit
import math
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

x,n = mi()
p=li()
p.sort()

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

dis=100000
q=0
for i in range(-200,200,1):
    if i in p:
        continue
    if abs(i-x) < dis:
        dis = abs(i-x)
        q=i
print(q)

Submission status: Accepted

Solution code:
stand = []
emp = [100]
ans = []

line = input().split()
x = int(line[0])
if int(line[1]) == 0:
  ans = x
  
elif int(line[1]) != 0:
  line2 = input().split()
  for i in range(-100,201):
    stand.append(int(i))
    
  for i in line2:
    if int(i) in stand:
      stand.remove(int(i))
  for i in stand:
    candi = abs(x - i)
    if candi < emp[0]:
      emp[0] = candi
      ans = 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()))  
for i in range(0,200):
  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 sys
X, N = map(int, input().split())
if N == 0:
    print(X)
    sys.exit()
p = list(map(int, input().split()))
mylist = [i for i in range(-1,102)]
#print(mylist)
mymin = float('INF')
mynum = 0

for i in range(103):
    if abs(mylist[i] - X) < mymin and mylist[i] not in p:
        mymin = abs(mylist[i] - X)
        mynum = i
    #print(mymin, mylist[i])
print(mylist[mynum])

Submission status: Accepted

Solution code:
x, n = list(map(int, input().split()))
p = set(map(int, input().split()))
i = 0
while True:
  if x-i >= 0 and 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 = [int(x) for x in input().split()]
if n == 0:
    print(x)
    exit()
p = [int(x) for x in input().split()]
a = []
for i in range(102):
    if i in p:
        continue
    a.append(i)
b = [0]*len(a)
for i in range(len(a)):
    b[i] = a[i]
for i in range(len(a)):
    a[i] = abs(a[i]-x)
m = min(a)
if x - m in b:
    print(x-m)
else:
    print(x+m)

Submission status: Accepted

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

f = range(102)
f = list(f)
for i in range(n):
  f.remove(p[i])

ans=0
dif=1000
for i in reversed(f):
  if abs(x-i) <= dif:
    ans = i
    dif = abs(x-i)
  
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
X, N=map(int,input().split())
if N==0:
  ans=X
  print(ans)
else:
  ps=map(int,input().split())

  ps_sort=sorted(ps)

  ind_crit=N-1
  for p in ps_sort:
    if p>=X:
      ind_crit=ps_sort.index(p)
      break

  if not ps_sort[ind_crit]==X:
    ans=X
  else:
    diff=0
    while(True):
      diff+=1
      if not X-diff in ps_sort:
        ans=X-diff
        break
      if not X+diff in ps_sort:
        ans=X+diff
        break

  print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
num = list(map(int,input().split()))

target = num[0]
kosuu = num[1]
ans = target

if(kosuu != 0):
    forbidden = sorted(list(map(int,input().split())))

    for i in range(kosuu+1):
        upper = target + i
        lower = target - i
        if not lower in forbidden:
            ans = lower
            break
        if not upper in forbidden:
            ans = upper
            break

print(ans)

Submission status: Accepted

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

if n == 0:
    print(x)
else:
    for i in range(100):
        yr = x+i
        yl = x-i
        if yl not in p:
            print(yl)
            break
        elif yr not in p:
            print(yr)
            break

Submission status: Accepted

Solution code:
X,N=map(int,input().split())
List=[int(i) for i in input().split()]
A=X
B=X
C=X in List
if C == True:    
    p=True
    q=True
    while p==True:
        A=A-1
        p= A in List
    while q==True:
        B=B+1
        q= B in List
    if X-A <= B-X:
        print (A)
    else:
        print (B)
else:
    print(X)