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

flag = False

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

for i in range(1,100):
    if not x+i in p:
        flag = True
        print(x+i)
    if not x-i in p:
        flog = True
        print(x-i)
    if flag:
        break

Submission status: Wrong Answer

Solution code:
X,N = map(int,input().split())
l=list(map(int,input().split()))
tmp1=X
tmp2=X
if not l:
    print(X)
else:
    while True:
        if not tmp1-1 in l:
            print(tmp1-1)
            exit()
        else :
            tmp1-=1
        if not tmp2+1 in l:
            print(tmp2+1)
            exit()
        else:
            tmp2+=1

Submission status: Wrong Answer

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

def solve():
    import bisect

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

    if N == 0:
        print(X)
        return

    setP = set(Ps)

    ans = float("inf")
    for x in range(1, 101):
        if not x in setP:
            if abs(X-ans) > abs(X-x):
                ans = x

    print(ans)


if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
X, N = [int(i) for i in input().split(' ')]
if N>0:
  p = [int(i) for i in input().split(' ')]
  abs_list = {}

  for i in range(-100,100):
    if(i in p):
      continue
    abs_list[i] = abs(X - i)
  min_k = min(abs_list, key=abs_list.get)
  print(min_k)
else:
  print(X)

Submission status: Wrong Answer

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

int_set = set(list(range(1,101)))

for x in input().split():
    int_set.remove(int(x))

for i in range(50):
    if X - i in int_set:
        print(X - i)
        break
    elif X + i in int_set:
        print(X + i)
        break

Submission status: Wrong Answer

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

d = 10**10
v = 10**10
for i in range(1, 101):
    if i in P:
        continue
    _d = abs(X - i)
    # print('d, _d', d, _d)
    if _d < d:
        d = _d
        v = i
    if _d == d:
        v = min(i, v)
print(v)

Submission status: Wrong Answer

Solution code:
X,N = (int(x) for x in input().split())
ans = 10000
ansnum = -3
if (N > 0):
    p = list(map(int, input().strip().split()))
    for i in range(-1,100):
        preans = abs(X-i)
        if(preans < ans) and (i in p ) == False:
            ans = preans
            ansnum = i
    print(ansnum)
else:
    print(X)

Submission status: Wrong Answer

Solution code:
''''atcoder beginner contest-170'''

import math
from collections import defaultdict
def r():
    return int(input())
def rm():
    return map(int,input().split())
def rl():
    return list(map(int,input().split()))

'''C'''
x,n=rm()
l=True
try:
    a=rl()
except:
    a=[]
b=defaultdict(int)
for i in a:
    b[i]=1
mini=math.inf
value=-1
for j in range(1,101):
    if b[j]!=1:
        if abs(x-j)<mini:
            mini=abs(x-j)
            value=j
print(value)

Submission status: Wrong Answer

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

check = [0] * max(p)
for i in range(n):
    check[p[i]-1] = 1

ans = 0
d = 10**9
for i in range(1,len(check)+1):
    if d >= abs(i-x) and check[i-1] != 1:
        d = abs(i-x)
        ans = i
print(ans)

Submission status: Wrong Answer

Solution code:
X,N = map(int,input().split())
if N == 0:
  print(X)
  exit()
A = list(map(int,input().split()))
for i in range(N):
  if (X - i) not in A:
    print(X-i)
    exit()
  elif (X + i ) not in A:
    print(X+i)

Submission status: Wrong Answer

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

diff_min,diff_min_x = 1000,1000
for x in reversed(range(-101,101)):
    if x not in P and abs(X-x) <= diff_min:
        diff_min,diff_min_x = abs(X-x),x

print(diff_min_x)

Submission status: Wrong Answer

Solution code:
X,N = map(int,input().split())
p_li = set(map(int,input().split()))
p = set(range(101))
kouho = p - p_li
ans = 10000
sa_min = 1000000
for i in sorted(list(kouho)):
    sa = abs(X-i)
    if sa_min > sa:
        ans = i
        sa_min = sa
print(ans)

Submission status: Wrong Answer

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

if n <= 0:
    print(x)
    sys.exit()
else:
    a1 = x - 1
    a2 = x + 1
    c = 0
    while True:
        if c % 2 == 0:
            if not a1 in p:
                print(a1)
                break
            else:
                a1 -= 1
        else:
            if not a2 in p:
                print(a2)
                break
            else:
                a2 += 1
        c += 1

sys.exit()

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys
import math
import itertools
import collections

X , N = map(int,input().split())
if N != 0:
    P = list(map(int,input().split()))
else:
    print(X)
    sys.exit()

s = set(P)

m = 1000
ans = None
for i in range(0,101):
    if i not in s:
        if m > abs(X-i):
            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()))
p.sort()
ans = []
key = []
for i in range(max(p)+1):
  if i in p:
    continue
  else:
    key.append(i)
    ans.append(abs(x-i))

aa = zip(ans,key)
aa = sorted(aa)
d,f = zip(*aa)
print(f[0])

Submission status: Wrong Answer

Solution code:

import sys
x, n = map(int, input().split(" "))

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

p = list(map(int, input().split(" ")))
for i in range(1, 100):
    if x >= 0:
        if x - i not in p:
            print(x-i)
            break
        if x + i not in p:
            print(x+i)
            break
    else:
        if x + i not in p:
            print(x+i)
            break
        if x - i not in p:
            print(x-i)
            break

Submission status: Wrong Answer

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

flag=[False for i in range(101)]

for i in P:
    flag[i]=True

d=0
while True:
    if X-d==0:
        ans=0
        break
    elif X+d==101:
        ans=101
        break
    elif not flag[X-d]:
        ans=X-d
        break
    elif not flag[X+d]:
        ans=X+d
        break
    d+=1
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
def main():
    x, n = map(int, readline().split())
    p = [int(i) for i in readline().split()]
    xx = [i for i in range(100+1)]
    pp1 = [i for i in xx if i not in p] 
    pp2 = [abs(x-i) for i in pp1]

    mi = 1000000
    for i in range(len(pp2)):
        if pp2[i] < mi:
            mi = pp2[i]
            midx = i 
    print(pp1[midx])
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
P = [int(x) for x in input().split()]
cand = 100
ans = 0
for t in range(-100, 101):
    if not(t in P):
        if cand > abs(t-X):
            cand = abs(t-X)
            ans = t
print(ans)

Submission status: Wrong Answer

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

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

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

ans = 0
for i in range(101):
    if i in a:
        continue
    if abs(x-ans) > abs(x-i):
        ans = i
        
if ans != 0:
    print(ans)
else:
    print(0 if x <= 50 else 101)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

X,N=(int(x) for x in input().rstrip('\n').split())
ps=[int(x) for x in input().rstrip('\n').split()]
if N==0:
  print(X)
else:
  for i in range(1,X):
    if X-i not in ps:
      print(X-i)
      break
    elif X+i not in ps:
      print(X+i)
      break

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
if n!=0:
  pp=list(map(int,input().split()))
else:
  pp=[]
q=True
r=True
i=0
a=0
b=0
while q:
  if x+i not in pp:
    a=x+i
    q=False
  else:
    i+=1
while r:
  if x-i not in pp:
    b=x-i
    r=False
  else:
    i+=1  

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
p = set(map(int, input().split()))
ans = X
min = 10000
for i in range(-100, 101):
  if i in p:
    continue
  else:
    if abs(X - i) < min:
      min = 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()
elif n == 100:
    print(0)
    exit()
p = list(map(int,input().split()))
t = list(range(1,101))
u = set(t)-set(p)
u = list(u)
u.sort()
dif = 2**60
ans = 2**60
for a in u:
    tmp = abs(a-x)
    if dif > tmp:
        ans = a
        dif = tmp
if x <= dif:
    ans = 0
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

P = set(P)
All = set( np.arange(0,101) )
Q = np.array(list(All-P))

Q_X = np.absolute( Q-X )
ans = Q[ np.argmin(Q_X ) ]

print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

P2 = []

for i in range(1, 101):
    if i in P:
        continue
    P2.append(i)

sa = 10**9
ret = -1
for p in P2:
    if abs(X-p) < sa:
        sa = abs(X-p)
        ret = p

print(ret)

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
if n==0:
  print(x)
else:
  p = list(map(int,input().split()))
  numberset = set()
  for i in range(1,101):
    numberset.add(i)
  for s in p:
    numberset.remove(s)
  diff = 100
  mindifint = 101
  for s in numberset:
    if abs(s-x)<diff:
      diff = abs(s-x)
      mindifint = s
    elif abs(s-x)==diff:
      mindifint = min(mindifint,s)
  print(mindifint)

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
p = list(map(int, input().split()))
q = set(range(1, 100))
r = list(q - set(p))
r.sort()
max = 1000
ans = X

if N == 0:
    print(X)
else:
    for i in r:
        if abs(X - i) < max:
            max = abs(X - i)
            ans = i

    print(ans)

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
p = list(map(int,input().split()))
a = x-1
b = x+1

while 1:
    if a not in p:
        ans = a
        break
        
    if b not in p:
        ans = b
        break
        
    a -= 1
    b += 1

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

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
p = list(map(int,input().split()))
p.sort()
ans1 = 999999
for i in range(1,101):
    if i not in p:
        if abs(x - i) < abs(x - ans1):
            ans1 = i
print(ans1)

Submission status: Wrong Answer

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

exist = [False] * 101
p = list(map(int, input().split()))

for i in range(N):
    exist[p[i]] = True

for i in range(100):
    if X - i <= 0:
        print(X-i)
        exit()

    if X + i > 100:
        print(X+i)
        exit()

    if not exist[max(0, X-i)]:
        print(X-i)
        exit()

    if not exist[min(X+i, 100)]:
        print(X+i)
        exit()

Submission status: Wrong Answer

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

p.sort()


ans1 = 100
ans2 = 100

flag = 1

for i in range(102):
    if x-i not in p:
        ans1 = x-i
        flag = 0
    if x+i not in p:
        ans2 = x+i
        flag = 0
    if flag == 0:
        break
    else:
        continue

print(min(ans1, ans2))

Submission status: Wrong Answer

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

listP.sort()

minD = 100
val = 1
bef = None
for p in listP:
    if bef == None:
        bef = p
    else:
        if p-1 == bef:
            pass
        else:
            if bef < x < p:
                val = p
            elif x <= bef:
                if abs(bef+1-x) < minD:
                    minD = abs(bef+1-x)
                    val = bef+1
            else:
                if abs(p-1-x) < minD:
                    minD = abs(p-1-x)
                    val = p-1
        bef = p
if not x in listP:
    val = x

print(val)

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
if n==0:
    print(x)
else:
    p = list(map(int,input().split()))
    k = [0]*100
    a = [i+1 for i in range(100)]
    ans = 101
    ans_x = 100
    for i in p:
        k[i-1]=1
    for i in range(x-1,99):
        if k[i]==0:
            if ans_x > abs(x-a[i]):
                ans,ans_x = a[i],abs(x-a[i])
                break
    for i in range(x-1,0,-1):
        if k[i]==0:
            if ans_x >= abs(x-a[i]):
                ans,ans_x = a[i],abs(x-a[i])
                break
    print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from sys import stdin
X, Y = [int(x) for x in stdin.readline().rstrip().split()]
P = [int(x) for x in stdin.readline().rstrip().split()]
tmp = 10**9+7
P = set(list(range(-100, 101))) - set(P)
P = list(P)
P.sort(reverse=True)


ans = 0
for i in P:
    if abs(i-X) <= tmp:
        ans = i
        tmp = abs(i-X)

print(ans)

Submission status: Wrong Answer

Solution code:
X,N=map(int,input().split())
p=list(map(int,input().split()))
p.sort()
ans=0
ans1=X
for i in range(1,101):
    if i in p:
        a=p.pop(0)
        continue
    A=abs(X-i)
    if ans1>A:
        ans1=A
        ans=i
    elif ans1==A:
        ans=min(ans,i)
    else:
        break
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8
X,N=map(int,input().split())
P=[]
if N!=0:
    P=list(map(int,input().split()))
K=[]
for i in range(1,101):
    if not(i in P):
        K.append(i)

K.append(1000)

tmp=1000

for i in range(len(K)):
    if tmp<=abs(K[i]-X):
        print(K[i-1])
        break
    tmp=abs(K[i]-X)

Submission status: Wrong Answer

Solution code:
S=lambda:input()
I=lambda:int(input())
L=lambda:list(map(int,input().split()))
LS=lambda:list(map(str,input().split()))

def main():
    x,n=L()
    if n!=0:p=L()
    z=[]
    for i in range(0,101):
        flag=False
        for j in range(n):
            if i==p[j]:
                flag=True
                break
        if(flag): continue
        z.append(i)
    
    mini=1e+5
    ans=1e+5
    for i in range(len(z)):
        absxz=abs(x-z[i])
        if absxz<mini:
            mini=absxz
            ans=z[i]
    print(ans)
            
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

p_list.append(x)
p_list.sort()

idx = p_list.index(x)

i = 0
while True:
    x_i = x - i
    x_j = x + i

    if x_i not in p_list:
        print(x_i)
        exit()
    if x_j not in p_list:
        print(x_j)
        exit()

    i += 1

Submission status: Wrong Answer

Solution code:
# from math import factorial,sqrt,ceil #,gcd
# from itertools import permutations,combinations,combinations_with_replacement
# from collections import deque,Counter
# from bisect import bisect_left
# from heapq import heappush,heappop
# from numba import njit
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from fractions import gcd

# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np    # numpy.lcm()
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb,perm #permはnPk
# import networkx as nx
# G = Graph()

# slist = "abcdefghijklmnopqrstuvwxyz"
X,N = map(int,input().split())
lisP = list(map(int,input().split()))

tmp = 102
ans = 102
for p in range(1,121):
    if p in lisP:
        continue
    num = abs(X-p)
    if num == tmp:
        ans = min(ans,p)
    elif num < tmp:
        tmp = num
        ans = p

print(ans)
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-
x, n = map(int, input().split())
p_list = list(map(int, input().split()))
for i in range(0, n // 2 + 1):
    if x - i not in p_list:
        print(x - i)
        break
    if x + i not in p_list:
        print(x + i)
        break

Submission status: Wrong Answer

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

for i in range(50):
    if x - i not in aa:
        print(x-i)
        break
    elif x+i not in aa:
        print(x+i)
        break

Submission status: Wrong Answer

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

counter = 1
if n == 0:
    print(x)
else:
    while True:
        if x - counter not in p:
            print(x - counter)
            break
        elif x + counter not in p:
            print(x + counter)
            break
        counter += 1

Submission status: Wrong Answer

Solution code:
import sys
X, N = map(int,input().split())
if N == 0:
  PN = []
else:
  PN = list(map(int,input().split()))
nums = [i for i in range(102)]

for P in PN:
  nums.remove(P)

dist = abs(nums[0]-X)
target = nums[0]
for num in nums[1:]:
  tmp = abs(num-X)
  if tmp >= dist:
    print(target)
    sys.exit()
  else:
    dist = tmp
    target = num

Submission status: Wrong Answer

Solution code:
x,n = map(int,input().split())
L = list(map(int,input().split()))
ans = 10**10
li = []
for i in range(-100,101):
    if i not in L:
        ans = min(ans,abs(x-i))
        li.append((ans,i))
li.sort()
print(li[0][1])

Submission status: Wrong Answer

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

if N == 0:
    print(X)
else:
    check_list = []
    for i in range(1, 105+1):
        check_list.append(X-i)
        check_list.append(X+i)

    for el in check_list:
        if el not in p_list:
            break

    print(el)

Submission status: Wrong Answer

Solution code:
X, N= list(map(int, input().split()))
P = list(map(int, input().split()))
if N == 0:
    print(X)
else:
    for i in range(1, 51):
        try:
            P.index(X - i)
        except Exception:
            print(X - i)
            break

        try:
            P.index(X + i)
        except Exception:
            print(X + i)
            break

Submission status: Wrong Answer

Solution code:
# 別変数の整数複数個
X, N = [int(x) for x in input().strip().split(" ")]
if N == 0:
    input()
    print(X)
else:
    P = sorted([int(x) for x in input().strip().split(" ")])
    x1, x2 = X, X
    while True:
        x1, x2 = x1 - 1, x2 + 1
        if x1 not in P:
            print(x1)
            break
        if x2 not in P:
            print(x2)
            break

Submission status: Wrong Answer

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

    num = list(range(-1, 101))

    ans = [0] * len(num)
    inf = 1000
    for i, n in enumerate(num):
        if n in p:
            ans[i] = inf
        else:
            ans[i] = abs(n-X)

    print(ans.index(min(ans))-1)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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 = INF
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)

Submission status: Wrong Answer

Solution code:
X,N = map(int,input().split())
import sys
p = list(map(int,input().split()))
if N == 0:
    print(X)
    sys.exit()
    
for i in range(1,101):  
    tmp_r = 10**9+7
    tmp_l = 10**9+7
    r_flag = 0
    l_flag = 0
    
    if X+i not in p:
        tmp_r = X+i
        r_flag = 1
    if X-i not in p:
        tmp_l = X-i
        l_flag = 1
        
    if r_flag == 1 or l_flag == 1:
        print(min(tmp_r,tmp_l))
        sys.exit()

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
p = sorted(list(map(int, input().split())))
l = [int(i) for i in range(1, 101)]
ll = []
for idx in l:
    if idx not in p:
        ll.append(idx)
mn = 1000
ans = -1
for i in range(len(ll)):
    if abs(ll[i] - x) < mn:
        mn = abs(ll[i] - x)
        ans = ll[i]
if ans == -1:
    print("")
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
INF = float("inf")
MOD = 10 ** 9 + 7
# ----------

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

S = set([i for i in range(-1, 101)])
S = S - P

ans = -1
diff = INF
for s in sorted(S):
    if abs(s - X) < diff:
        ans = s
        diff = abs(s - X)

print(ans)

Submission status: Wrong Answer

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

a = a+b
result = []
p_dif = set(a) - set(p)
#print(p_dif)

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

Submission status: Wrong Answer

Solution code:
import sys, io, os, re
import bisect
from pprint import pprint
from math import sin, cos, pi, radians, sqrt, floor
from copy import copy, deepcopy
from collections import deque
from fractions import gcd
from functools import reduce
from itertools import groupby

n1 = lambda: int(sys.stdin.readline().strip())
nn = lambda: list(map(int, sys.stdin.readline().strip().split()))
f1 = lambda: float(sys.stdin.readline().strip())
fn = lambda: list(map(float, sys.stdin.readline().strip().split()))
s1 = lambda: sys.stdin.readline().strip()
sn = lambda: list(sys.stdin.readline().strip().split())
nl = lambda n: [n1() for _ in range(n)]
fl = lambda n: [f1() for _ in range(n)]
sl = lambda n: [s1() for _ in range(n)]
nm = lambda n: [nn() for _ in range(n)]
fm = lambda n: [fn() for _ in range(n)]
sm = lambda n: [sn() for _ in range(n)]

def array1(n): return [0] * n
def array2(n, m): return [[0] * m for x in range(n)]
def array3(n, m, l): return [[[0] * l for y in xrange(m)] for x in xrange(n)]

X, N = nn()
P = nn()

if N == 0:
    print(X)
else:
    d = 999
    ans = -1
    for i in range(101):
        if (i in P):
            continue

        t = abs(X - i)
        if t < d:
            d = t
            ans = i

    print(ans)

Submission status: Wrong Answer

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

diff_min,diff_min_x = 1000,1000
for x in reversed(range(0,101)):
    if x not in P and abs(X-x) <= diff_min:
        diff_min,diff_min_x = abs(X-x),x

print(diff_min_x)

Submission status: Wrong Answer

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

if N==0:
  print(X)
else:
  P = list(map(int,input().split()))
  Q = [n for n in range(1,101) if n not in P]
  a = 100
  d1 = 100
  
  for q in Q:
    d2 = abs(q-X)
    if d2<d1:
      d1 = d2
      a = q
  
  print(a)

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
a = 1
ans = ''
while ans == '':
  if len(p) == 0:
    ans = x
  elif x - a not in p:
    ans = x - a
  elif x + a not in p:
    ans = x + a
  else:
    a += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys

X, N = map(int, sys.stdin.readline().strip().split())
P = set(map(int, sys.stdin.readline().strip().split()))

ans = X
ans_v = X
for i in range(101):
    if i in P:
        continue
    tmp = abs(X - i)
    if tmp < ans or (tmp == ans and i < ans_v):
        ans_v = i
        ans = tmp
        # print(ans, ans_v)
print(ans_v)

Submission status: Wrong Answer

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

if N == 0:
    print(X)
else:
    check_list = []
    for i in range(1, 105+1):
        check_list.append(X-i)
        check_list.append(X+i)
    
    print(check_list)

    for el in check_list:
        if el not in p_list:
            break

    print(el)

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
X, N = map(int, input().split())
P = set(map(int, input().split()))
U = set(range(-100, 101))
diff = sorted(list(U - P))

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

ans = 0
tmp = float('inf')
for i in diff:
    if tmp > abs(X - i):
        tmp = abs(X - i)
        ans = i
print(ans)