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: Wrong Answer

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:
    continue
  else:
    print(X-i)
    break

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

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
if n == 0:
    print(x)
else:
    P = set(map(int, input().split()))
    NP = set([i for i in range(1, 101)]) - P
    d = 100
    mx = 100
    for p in NP:
        if abs(x-p) < d:
            mx = p
            d = abs(x-p)
    print(mx)

Submission status: Wrong Answer

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 = 0
    score = inf
    for i in range(101):
        tmp = abs(x - i)
        if score > tmp and i not in p:
            ans = i
            score = tmp
    print(ans)

if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

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=101
for i in range(110):
    if i not in p:
        if abs(x-now)>abs(x-i):
            now=i
    # print(now)
print(now)

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
if n==0:
  print(x)
else:
  a=list(map(int,input().split()))
  tmp=1000
  for i in range(-1,101):
    if i not in a:
      if tmp > abs(i-x):
        tmp=abs(i-x)
        ans=i
  print(ans)

Submission status: Wrong Answer

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

a = 0
for i in range(x):
  if i not in p:
    a = i
b = 0
for i in range(x, 101):
  if i not in p:
    b = i
    break

if abs(x-a) <= abs(x-b):
  print(a)
else:
  print(b)

Submission status: Wrong Answer

Solution code:
from sys import stdin
from collections import defaultdict as dd
from collections import deque as dq
import itertools as it
from math import sqrt, log, log2
from fractions import Fraction

x, n = map(int, input().split())
if n!=0: nums = set(map(int, stdin.readline().split()))

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

ans = 10**9
for i in range(1, 10000):
    t1 = x + i if x+i not in nums else 10**4
    t2 = x - i if x-i not in nums else 10**4
    if t1!=10**4 or t2!=10**4:
        ans = min(t1, t2)
        print(ans)
        exit()

Submission status: Wrong Answer

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

sa = float("inf")
ans = 0
for i in range(1, 101):
    if sa > abs(x - i) and (i not in p):
        ans = i
        sa = abs(x - i)
print(ans)

Submission status: Wrong Answer

Solution code:
x, n = list(map(int, input().split()))
al = list(map(int, input().split()))
INF = float("inf")
ans = INF
sa = INF
for i in range(0, 101):
    if i not in al:
        if sa > abs(x-i):
            sa = abs(x-i)
            ans = i
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
from bisect import bisect_left
INF = float("inf")


def main():
    X, N = map(int, input().split())
    if N > 0:
        p = set(map(int, input().split()))
    else:
        p = set()

    ans = INF
    for n in range(100+1):
        if n in p:
            continue
        if abs(n-X) < abs(ans-X):
            ans = n

    print(ans)

    return


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

sa = float("inf")
ans = 0

for i in range(1, 101):
    if i not in p and abs(X - i) < sa:
        sa = abs(X - i)
        ans = i

print(ans)

Submission status: Wrong Answer

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

#p_L = list(sorted(p_L))
p_L = set(p_L)

sa = 101
for i in range(0,101):
    if i not in p_L:
        if sa > min(sa,abs(i-x)):
            sa = abs(x-i)
            ans = i
        #ans = min(i,)

print(ans)

Submission status: Wrong Answer

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

    m = [i for i in range(1, 101)]

    o = list(set(m) - set(p))

    ans = 100000
    dif = ans - x
    for i in range(len(o)):
        if(dif > abs(x-o[i])):
            ans = o[i]
            dif = abs(x-o[i])
    print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    x,n = map(int,input().split())
    p = set(map(int,input().split()))
    x1,x2 = x,x
    if n == 0:
        print(x)
        return 0
    while True:
        x1 = x1-1
        x2 = x2+1
        if x1 not in p:
            print(x1)
            return 0
        elif x2 not in p:
            print(x2)
            return 0

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
#from fractions import gcd
#from itertools import combinations # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
x,n = readInts()
if n == 0:
    print(x)
    exit()
P = readInts()
A = []
for i in range(min(max(P)+1,100)):
    if i + 1 in P:
        pass
    else:
        A.append(i+1)
#print(A)
m = float('inf')
ans = -1
for a in A:
    if abs(x - a) < m:
        ans = a
        m = abs(x-a)
print(ans)

Submission status: Wrong Answer

Solution code:
inf = float('inf')
X,N = map(int,input().split())
p = list(map(int,input().split()))
ans = []
for i in range(101):
    if i in p:
        ans.append([inf,i])
    else:
        ans.append([abs(X-i),i])
ans.sort()
print(ans[0][1])

Submission status: Wrong Answer

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

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

if X in P:
    ans = -1
else:
    ans = X
for i in range(100):
    if i in P:
        continue
    if abs(i-X) < abs(ans-X):
        ans = i

print(ans)

Submission status: Wrong Answer

Solution code:
from bisect import bisect_left
X, N = map(int, input().split())
P = sorted(list(map(int, input().split())))
i = 0
if N == 0:
  print(X)
else:
  while True:
    x = X-i
    idx = bisect_left(P, x)
    if idx >= 0 and idx < N and P[idx] != x:
      print(x)
      break
    else:
      x = X+i
      idx = bisect_left(P, x)
      if idx >= 0 and idx < N and P[idx] != x:
        print(x)
        break
    i += 1

Submission status: Wrong Answer

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

mi = 1000
ans = -1
for i in range(-1, 101):
    if i not in P:
        if mi > abs(X - i):
            mi = abs(X - i)
            ans = i
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
ans = float("inf")
for i in range(101):
    if ans > abs(i - x) and not i in p:
        ans = abs(i - x)
        a = i
print(a)

Submission status: Wrong Answer

Solution code:
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
from bisect import bisect_left
from operator import lt, le
def find_nearst_value(lst, val, left=True):
    """ソート済のリストから，valに最も近い要素を返す.
    @param lst: ソート済のリスト
    @param left:
        lv < val < rv，val-lv == rv-val のとき，
        Trueならばlvを，Falseならばrvを選択する
    @return もっともvalに値が近いlstの要素
    """
    pos = bisect_left(lst, val)
    if pos == 0: return lst[0]
    if pos == len(lst): return lst[-1]
    lv, rv = lst[pos-1:pos+1]
    op = le if left else lt
    return lv if op(val-lv, rv-val) else rv
#======================================================#
def main():
    x, n = MII()
    pp = MII()
    qq = [i for i in range(101) if not i in set(pp)]
    qq.sort()
    print(find_nearst_value(qq,x))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
X, N = map(int, input().split())
if N == 0:
    print(X)
    exit()
P = list(map(int, input().split()))
P.sort()
ans = 10 ** 9
d = [True for _ in range(0, 101)]
for i in range(N):
    d[P[i]] = False
for i in range(len(d)):
    if d[i] and abs(ans - X) > abs(i - X):
        ans = i
print(ans)

Submission status: Wrong Answer

Solution code:
nums = set(range(1, 101))

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: Wrong Answer

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


diff=float('inf')
ans=-1
for i in range(-100,110):
    if i in P:
        continue
    d = abs(X-i)
    if d<diff:
        ans=i
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np
# from numpy import cumsum  # accumulate

def solve():
    X, N = MI()
    P = LI()

    ans = X
    if P == []:
        print(ans)
        return
    mn = INF
    for i in range(X-110, X+110):
        if i == X: continue
        if i not in P:
            if mn > abs(X - i ):
                mn = abs(X - i)
                ans = i
            # print(i, abs(X - i), ans)
    print(ans)

if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)

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

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

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

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

if N == 100:
    if X <= 50:
        print(0)
    else:
        print(101)
    exit()


DIFF = 101
ans = 101

for p in range(101):
    if p in P:
        continue

    d = abs(X - p)

    if d == DIFF:
        ans = min(p, ans)
    elif d < DIFF:
        DIFF = d
        ans = p

print(ans)

Submission status: Wrong Answer

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

print(ans)

Submission status: Wrong Answer

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

for i in range(101):
    if i in P:
        continue
    if abs(ans - X) > abs(i - X):
        ans = i

print(ans)

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
p=list(map(int,input().split()))
k=0
sa=100
for i in range(100,0,-1):
    if i in p:
        continue
    value=abs(x-i)
    if value<=sa:
        k=i
        sa=value
print(k)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = 100
abs_ans = 100
for i in range(1,101):
    if i in P:
        continue
    if abs(x-i) < abs_ans:
        ans = i
        abs_ans = abs(x-i)
print(ans)

Submission status: Wrong Answer

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

import sys
from collections import defaultdict, deque
from heapq import heappush, heappop
import math
import bisect
input = sys.stdin.readline

# 再起回数上限変更
# sys.setrecursionlimit(1000000)

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

all = list(range(101))
val = 1000
# print(list(set(all) - set(p)))

for a in list(set(all) - set(p)):
    if abs(a - x) < val:
        ans = a
        val = abs(a - x)
        # print(val)
print(ans)

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
if N == 0:
    print(X)
else:
    *p, = map(int, input().split())
    ans = -1
    d = 10**10
    for i in range(-100, 101):
        if i in p:
            continue
        m = abs(i-X)
        if m < d:
            d = m
            ans = i
    print(ans)

Submission status: Wrong Answer

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

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

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



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

res = 10000

for i in range(0, 101):
    if i in P:
        continue

    if abs(X - res) > abs(X - i):
        res = i

print(res)

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
p = list(map(int, input().split()))
a = [False for _ in range(1000)]
for P in p:
    a[P] = True

ans = -1
d = 10000
for i in range(1, 110):
    if d > abs(i - X) and a[i] == False:
        d = abs(i - X)
        ans = i

print(ans)

Submission status: Wrong Answer

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

p = set(p)

now = 10**29
for i in range(1,101):
    if not i in p:
        if abs(i-X)<now:
            now = abs(i-X)

if not X-now in p:
    print(X-now)
else:
    print(X+now)

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
d = [0]*101
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<=100:
            if d[x+i] == 0:
                print(x+i)
                break
        i += 1

Submission status: Wrong Answer

Solution code:
import sys

X,N=[int(i) for i in input().split(" ")]
if N==0:
    print(X)
    sys.exit(0)
p=[int(i) for i in input().split(" ")]

d=100000
retval=100000
for i in range(101):
    if i in p:
        continue

    if abs(X-i)<d:
        d=abs(X-i)
        retval=i

print(retval)

Submission status: Wrong Answer

Solution code:
import sys
# input = sys.stdin.buffer.readline
def main():
    x, n = map(int, input().split())
    if n == 0:
        print(x)
        sys.exit()
    p = tuple(map(int, input().split()))
    cnt = 1
    while True:
        xt = x - cnt
        if xt not in p:
            print(xt)
            sys.exit()
        xt2 = x + cnt
        if xt2 not in p:
            print(xt2)
            sys.exit()
        cnt += 1

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

mindiff = 10*10
ans=-1
for i in range(100):
    if i in p:
        continue
    if abs(i - x) < mindiff:
        ans = i
        mindiff = abs(i-x)
print(ans)

Submission status: Wrong Answer

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

for i in range(100):
  if str(X - i) not in plist:
    print(X - i)
    break
  elif str(X + i) not in plist:
    print(X + i)
    break

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#import numpy as np
#from decimal import *

X, N = MAP()
p = LIST()

if N == 0:
	print(X)
	exit()
	
i = 1
while 1:
	if not X-i in p:
		print(X-i)
		exit()
	elif not X+i in p:
		print(X+i)
		exit()
	i += 1

Submission status: Wrong Answer

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

m = -100
d = 100000000
for i in range(1, 101):
    if i in ps:
        continue

    if abs(X - i) < abs(X - m):
        m = i
        d = abs(X - i)

print(m)

Submission status: Wrong Answer

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

    m = [i for i in range(1, 101)]

    o = list(set(m) - set(p))
    print(o)

    ans = 100000
    dif = ans - x
    for i in range(len(o)):
        if(dif > abs(x-o[i])):
            ans = o[i]
            dif = abs(x-o[i])
    print(ans)

Submission status: Wrong Answer

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 = sorted(list(map(int,input().split())))
    ans = 10000000000
    for i in range(-100,101):
        if i in p:
            continue
        else:
            d = abs(x-i)
            if d < ans:
               ans = d
               check = i 
    print(check)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
import decimal


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [Scanner.string() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [Scanner.int() for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        res = []
        i = 1
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n // i)
        return res

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True

    @staticmethod
    def fact(N):
        res = {}
        tmp = N
        for i in range(2, int(N ** 0.5 + 1) + 1):
            cnt = 0
            while tmp % i == 0:
                cnt += 1
                tmp //= i
            if cnt > 0:
                res[i] = cnt
        if tmp != 1:
            res[tmp] = 1
        if res == {}:
            res[N] = 1
        return res


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)


def solve():
    X, N = Scanner.map_int()
    P = Scanner.map_int()
    if N == 0:
        print(X)
        return
    t = INF
    for i in range(-1, 102):
        if i in P:
            continue
        t = min(t, abs(i - X))
    if t - X in P:
        print(X + t)
    else:
        print(X - t)


def main():
    # sys.stdin = open("sample.txt")
    # T = Scanner.int()
    # for _ in range(T):
    #     solve()
    # print('YNeos'[not solve()::2])
    solve()


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
l = list(map(int,input().split()))
ans = 10**10
if n == 0:
    print(x)
    exit()
for i in range(-100,1000):
    if i in l or i == x:
        continue
    if ans > abs(i-x):
        ans1 = i
        ans = abs(i-x)
print(ans1)

Submission status: Wrong Answer

Solution code:
def get_ints():
    return list(map(int, input().split()))

x, n = get_ints()
ps = get_ints()
ps.sort()
ans = 10000000
d = 1000000
for i in range(101):
    if i in ps:
        continue
    nd = abs(x - i)
    if nd < d:
        ans = i
        d = nd

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
*P, = map(int, input().split())
cand = set(range(101)) - set(P)
ans, temp = None, 10**10
for c in cand:
    t = abs(X - c)
    if t < temp:
        temp = t; ans = c
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    X, N = map(int, input().split())
    P = list(map(int, input().split()))
    P.sort()
    if not (X in P):
        print(X)
        exit() 
    ans = 101
    value = -1
    for i in range(1,101):
        if i in P:
            continue
        if ans > abs(X - i):
            ans = abs(X-i)
            value = i

    print(value)
            




if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
a = list(map(int,input().split()))
ans = 0
if x + 1 > x + 101:
    ans = 101
else:
    ans = -1
for i in range(1,101):
    if i in a:
        continue
    if abs(x-i) < abs(x-ans):
        ans = i
print(ans)

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
ar=[int(i) for i in input().split()]
arr=[i for i in range(1,1000) if i not in ar]
arr.sort()
mini=10000000
for i in arr:
    if abs(i-x)<mini:
        mini=abs(i-x)
        ans=i 
print(ans)

Submission status: Wrong Answer

Solution code:
X,N = map(int,(input().split()))
p = list(map(int,(input().split())))
ans = []
for i in range(0,101):
    if i not in p:
        m = abs(i-X)
        ans.append((m,i))
ans.sort()
print(ans[0][1])

Submission status: Wrong Answer

Solution code:
import sys 
from collections import deque
sys.setrecursionlimit(10**6)
def S(): return sys.stdin.readline().rstrip()
def SL(): return map(str,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())
def LS(): return list(sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))

def main():
    x,y = IL()
    bit = 2**x
    for i in range(bit):
        tmp = 0
        for j in range(x):
            if (i>>j)&1:
                tmp += 2
            else:
                tmp += 4
            if y<tmp:
                continue
        if tmp == y:
            print('Yes')
            exit()
    print('No')
    return

if __name__=='__main__':
    main()

Submission status: Wrong Answer

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


def main():
    x, n = map(int, input().split())
    if n > 1:
        p_set = set(map(int, input().split()))
    else:
        p_set = set()

    for i in range(101):
        if (x - i) not in p_set:
            print(x - i)
            return
        elif (x + i) not in p_set:
            print(x + i)
            return


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
nums = set(range(1, 101))

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

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

Submission status: Wrong Answer

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
#from fractions import gcd
#from itertools import combinations # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
x,n = readInts()
if n == 0:
    print(x)
    exit()
P = readInts()
A = []
for i in range(max(P)+1):
    if i + 1 in P:
        pass
    else:
        A.append(i+1)
#print(A)
m = float('inf')
ans = -1
for a in A:
    if abs(x - a) < m:
        ans = a
        m = abs(x-a)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter
import sys

sys.setrecursionlimit(10 ** 6)

mod = 1000000007
inf = int(1e18)

dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]


def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft


def main():
    x, n = map(int, input().split())
    a = set(map(int, input().split()))
    a = sorted(set([i for i in range(1, 101)]) - a)
    s = inf
    for i in a:
        s = min(s, abs(x - i))

    for i in a:
        if abs(x - i) == s:
            print(i)
            return
main()

Submission status: Wrong Answer

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

ans=float("inf")
val=-1
for p in P:
    if abs(p-X)<ans:
        val=p
        ans=abs(p-X)
print(val)

Submission status: Wrong Answer

Solution code:
X,Y = map(int,input().split())
P = [int(i) for i in input().split()]
temp1 = 1000
ans = 1000
for p in P:
    temp2 = abs(X-p)
    if temp1 > temp2 and temp2 != 0:
        ans = p
        temp1 = temp2
print(ans)

Submission status: Wrong Answer

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

d = 200
ans = 0
for i in range(101):
    if i in P: continue
    if d > abs(X-i):
        d = abs(X-i)
        ans = i
print(ans)