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.sort()
ans=300
for i in range(-100,101):
    if p.count(i)==0:
        if abs(ans-x)>abs(i-x):
            ans=i
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import math
import itertools
x, n = map(int, input().split())
p = list(map(int, input().split()))
if (n == 0):
    print(x)
    sys.exit()
diff = 1000
ans = 0
p.sort()
diff=1000
for i in range(100):
    if (i in p):
       continue
    else:
        if (abs(x - i) == diff):
            break
        if (abs(x - i) < diff):
            diff = abs(x - i)
            ans = i
print(ans)

Submission status: Wrong Answer

Solution code:
x, n = map(int, input().split())
if n != 0:
    p = list(map(int, input().split()))
else:
    print(x)
    exit()
ABS = 10 ** 9
ans = 0
for i in range(-10, 101):
    if i in p:continue

    temp = abs(i - x)
    if ABS > temp:
        ABS = temp
        ans = i
    else:
        print(ans)
        exit()

Submission status: Wrong Answer

Solution code:
num, n = map(int,input().split())
givenlist = set(list(map(int,input().split())))
numlist = set([i+1 for i in range(100)]) - givenlist
min = 1000
answer = []
for i in numlist:
    if abs(num-i) <= min:
        min = abs(num-i)

if num - min in numlist:
    print(num - min)
else:
    print(num + min)

Submission status: Wrong Answer

Solution code:
X,N=map(int,input().split())
if N==0:
    print(X)
P=list(map(int,input().split()))
p=sorted(P)
a=True
if (X in p)==False:
    print(X)
    a=False
if a==True:
    for i in range(1,100):
        if (X-i in p)==False and (X+i in p)==False:
            print(X-i)
            a=False
            break
        elif (X-i in p)==True and (X+i in p)==False:
            print(X+i)
            a=False
            break
        elif (X-i in p)==False and (X+i in p)==True:
            print(X-i)
            a=False
            break

Submission status: Wrong Answer

Solution code:
# fall 7, stand 8...
# !/ankit_SM/bin/env python

from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip

def main():
    tinn=1; #tinn=int(input())
    for tin in range(tinn):
        x,n=map(int,input().split())
        a=list(map(int,input().split()))
        dic={}
        for _ in range(-101,101):
            dic[_]=0;
        for _ in range(n):
            dic[a[_]]=1;
        mn=100000; val=0;
        for _ in range(101):
            if(dic[_]==0):
                if(mn>abs(x-_)):
                    mn=abs(x-_)
                    val=_
        print(val)


# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
def print(*args, **kwargs):
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()
if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# endregion
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
x = list(map(lambda x:int(x), input().split()))
X = x[0]
N = x[1]
p = []
if N != 0:
  p = list(map(lambda x:int(x), input().split()))

near = [False]*202#
near[1] = True
#print(near)
#print(near[200])

for i in p:
  near[i] = True
  
for i in range(0,100):
  if not near[X-i]:
    print(X-i)
    break
  elif not near[X+i]:
    print(X+i)
    break

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
if N != 0:
  p = list(map(int, input().split()))
  num = float("inf")
  for i in range(1, 101):
    if abs(i-X) < abs(num-X) and not i in p:
      num = i
  if abs(101-X) < abs(num-X):
    print(101)
  elif abs(0-X) <= abs(num-X):
    print(0)
  else:
    print(num)
else:
  print(X)

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
if n==0:
    print(x)
    exit()
List=list(map(int,input().split()))
num=list(range(1,101))
min_num=1000
for i in range(len(List)):
    if num.count(List[i])>=1:
        num.remove(List[i])
for i in range(len(num)):
    if (abs(num[i]-x)<abs(min_num-x)) or (abs(num[i]-x)==abs(min_num-x) and num[i]<min_num):
        min_num=num[i]
print(min_num)

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(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 = [int(x) for x in input().split()]
arr = set([int(x) for x in input().split()])
# arr.sort()

if n == 0:
    print(x)
elif x < min(arr):
    print(x)
elif x > max(arr):
    print(x)
elif not x in arr:
    print(x)
else:
    res = -1
    min_diff = 8491654891598
    for i in range(-1,102):
        if i in arr:
            continue
        min_diff = min(min_diff, abs(x - i))
        if abs(x - i) == min_diff:
            res = i
    print(res)

Submission status: Wrong Answer

Solution code:

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

ans = x

min_num = x
for i in range(301):
    if p.count(i) == 0:
        if min_num > abs(x-i):
            min_num = 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
    
if n==1 and x not in p:
    ans = x
    
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(1,len(p)):
    ans1 = X
    ans2 = X
    if X+i not in p:
        ans1 = X+i
    
    if X-i not in p:
        ans2 = X-i
    
    if ans1 != X and ans2 != X:
        print(ans2)
        exit()
    elif ans1 == X and ans2 != X:
        print(ans2)
        exit()
    elif ans1 != X and ans2 == X:
        print(ans1)
        exit()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    x,n = map(int,input().split())
    p = list(map(int,input().split()))
    min = 100000
    ans = 0
    for i in range(101):
        if i in p:
            pass
        elif min > abs(i-x):
            min = abs(i-x)
            ans = i
            
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

p_all = set(range(-101, 101)) - set(p)

mi = float('inf')
ans = 0
for i in p_all:
    if abs(x - i) < mi:
        mi = abs(x - i)
        ans = i

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
a,b = map(int,input().split())
if b==0:
  print(a)
else:
  b = list(map(int,input().split()))
  for i in range(101):
    _min=a-i
    _max=a+i
    if _min>0:
      if _min not in b:
        print(_min)
        sys.exit(0)
    if _max<=100:
      if _max not in b:
        print(_max)
        sys.exit(0)

Submission status: Wrong Answer

Solution code:
x,n=map(int,input().split())
p=list(map(int,input().split()))
q=list(range(101))
for i in range(n):
    q.remove(p[i])
ans=0
for i in q:
    if abs(x-i)==abs(x-ans):
        ans=min(i,ans)
    elif abs(x-i)<abs(x-ans):
        ans=i
print(ans)

Submission status: Wrong Answer

Solution code:
X, N = map( int, input().split() )
if N > 0:
  P = sorted( list( map( int, input().split() ) ))
  ret = -1
  dis = 10 ** 18
  for i in range( -100, 100 + 1 ):
    if i in P:
      continue
    if dis - abs( i - X ) > 0:
      ret = i
      dis = abs( i - X )
else:
  ret = X
print( ret )

Submission status: Wrong Answer

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

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

nota = list()

for i in range(1, 101):
    if i in a:
        continue
    nota.append(i)

ans = 1000
minabs = 1000
for i in nota:
    if minabs > abs(i-x):
        minabs = abs(i-x)
        ans = i

print(ans)

Submission status: Wrong Answer

Solution code:
X,N = map(int,input().split())
p_li = set(map(int,input().split()))
p = set(range(-100,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:
x, n = [int(e) for e in input().split()]
nums = [int(e) for e in input().split()]

ans = x
for i in range(n):
    if x-i not in nums:
        ans = x-i
        break
    elif x+i not in nums:
        ans = x+i
        break
    else:
        continue
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	C
# CreatedDate:  2020-06-14 21:12:01 +0900
# LastModified: 2020-06-14 21:18:58 +0900
#


import os
import sys
#import numpy as np
#import pandas as pd


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


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
p = list(map(int, input().split()))
if X not in p:
    print(X)
else:
    p_sorted = sorted(p)
    idx = p_sorted.index(X)
    for i in range(idx):
        idx_l = idx - i - 1
        idx_r = idx + i + 1
        if idx_l >= 0 and X - i - 1 !=  p_sorted[idx_l]:
            print(X - i - 1)
            break
        elif idx_r < N and X + i + 1 !=  p_sorted[idx_r]:
            print(X + i + 1)
            break

Submission status: Wrong Answer

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

if p == []:
    print(x)
    exit()

tmp1 = x
tmp2 = x

for i in range(1,120):
    tmp1 = tmp1 - 1
    tmp2 = tmp2 + 1
    if tmp1 not in p:
        print(tmp1)
        exit()
    if tmp2 not in p: 
        print(tmp2)
        exit()

Submission status: Wrong Answer

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


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

    if abs(X - i) < dist:
        ans = i
        dist = abs(X - i)

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
import math as mt
input=sys.stdin.buffer.readline  
#t=int(input())
mod=10**9+7
t=1
for __ in range(t):
    
    x,n=map(int,input().split())
    l=[0]*101
    #n=int(input())
    #a=[[0 for j in range(m)] for i in range(n)]
    p=list(map(int,input().split()))

    for i in range(n):
        l[p[i]]=1
    mini=abs(x)
    ans=0
    #print(l)
    for i in range(101):
        if l[i]==0:
            if abs(x-i)<mini:
                mini=abs(x-i)
                
                ans=i
        
    print(ans)

Submission status: Wrong Answer

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

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

d = float("inf")
ans = -1
for n in reversed(range(101)):
    if not n in P and abs(X - n) < d:
        ans = n
        d = abs(X - n)

print(ans)

Submission status: Wrong Answer

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

p_all = set(range(-101, 101)) - set(p)
print(p_all)

mi = float('inf')
ans = 0
for i in p_all:
    if abs(x - i) < mi:
        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()

p = set(map(int, input().split()))
a = set([i for i in range(101)])
np = a-p

ans = 0
dist = 1000000
for i in np:
  if(abs(x-i) < dist):
    dist = abs(x-i)
    ans = i
  elif(abs(x-i) == dist):
    ans = min(i, ans)
  else:
    pass
  
print(ans)

Submission status: Wrong Answer

Solution code:
def binarySearch (arr, l, r, x): 
  
    # Check base case 
    if r >= l: 
  
        mid = l + (r - l) // 2
  
        # If element is present at the middle itself 
        if arr[mid] == x: 
            return mid 
          
        # If element is smaller than mid, then it  
        # can only be present in left subarray 
        elif arr[mid] > x: 
            return binarySearch(arr, l, mid-1, x) 
  
        # Else the element can only be present  
        # in right subarray 
        else: 
            return binarySearch(arr, mid + 1, r, x) 
  
    else: 
        # Element is not present in the array 
        return -1

l=list(map(int, input().split(' ')))

find=l[0]
n=l[1]

if n==0:
    print(find)
else:
    l=list(map(int, input().split(' ')))
    l=sorted(l)

    a=find+1
    b=find-1
    
    while True:
        if binarySearch(l, 0, n-1, b)==-1:
            print(b)
            break
        elif binarySearch(l, 0, n-1, a)==-1:
            print(a)
            break
        else:
            a+=1
            b-=1

Submission status: Wrong Answer

Solution code:
x, n = list(map(int, input().split()))
ps = list(map(int, input().split())) if n else []

pss = [0] * 101
for p in ps:
    pss[p] = 1

#print(pss)
for i in range(n + 1):
    if x - i > -1 and pss[x - i] == 0:
        print(x - i)
        break
    if x + i < 101 and pss[x + i] == 0:
        print(x + i)
        break

Submission status: Wrong Answer

Solution code:
def main():
    X,N = [int(x) for x in input().split()]
    P = [int(x) for x in input().split()]
    top_diff = 200
    ans = 0
    for i in range(1,101):
        # print(i,top_diff,ans)
        if not i in P:
            if abs(X-i) < top_diff:
                top_diff = X-i
                ans = i
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

for i in range(N):
    p[i] = int(p[i])
    
if N == 0:
    print(X)
else:    
    for i in range(1,N+1):
        if not (X-i) in p:
            print(X-i)
            break
        elif not (X+i) in p:
            print(X+i)
            break
        else:
          continue

Submission status: Wrong Answer

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

check = [0 for i in range(100)]
for i in range(N):
    check[P[i]-1] = 1
    
dx_ls = [1000 for i in range(100)]
ans = []
for i in range(100):
    if check[i] == 0:
        dx_ls[i] = abs(X-(i+1))
            
dx_min = min(dx_ls)
for i in range(100):
    if dx_ls[i] == dx_min:
        ans.append(i+1)
        
ans_plus = min(ans)

if abs(ans_plus-X) >= abs(X - 0):
    print(0)
else:
    print(ans_plus)

Submission status: Wrong Answer

Solution code:
x, n = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]
if n == 0:
    print(x)
else:
    p = list(set(p))
    min_p = min(p)
    max_p = max(p)
    j = 0
    ans = -100
    for i in range(min_p+1, max_p):
        if i == p[j+1]:
            j += 1
        else:
            if abs(ans-x) > abs(i-x):
                ans = i
    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
a.sort()

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:
X, N = map(int, input().split())
if N == 0:
    print(X)
    quit()
p = set(map(int, input().split()))
not_p = sorted(set(range(1, 101)) - p)
ans = 0
minval = 101
for i in not_p:
    if minval > abs(X - i):
        minval = abs(X - i)
        ans = i
print(ans)

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 = -1
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())
if N !=0:
  p = list(map(int, input().split()))
if N ==0:
  print(X)
  exit()
  
  
if p.count(X) == 0:
  print(X)
for a in range(100):
  if p.count(X-a) ==0:
    print(X-a)
    exit()
  elif p.count(X+a) ==0:
    print(X+a)
    exit()

Submission status: Wrong Answer

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

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

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

for i in range(1,101):
  if X-i not in P:
    print(X-i)
    exit()
  elif X+i not in P:
    print(X+i)
    exit()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# coding=UTF-8
from collections import deque
from operator import itemgetter
from bisect import bisect_left, bisect
import itertools
import sys
import math
import numpy as np
import time
sys.setrecursionlimit(10**6)
input = sys.stdin.readline


def main():
    x, n = map(int, input().split())
    p = list(map(int, input().split()))
    if n == 0:
        print(x)
    else:
        for i in range(n):
            num1 = x - i
            num2 = x+i
            if num1 not in p and num2 not in p:
                print(min(num1, num2))
                break
            elif num1 not in p:
                print(num1)
                break
            elif num2 not in p:
                print(num2)
                break


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
X,N=map(int,input().split())
P = list(map(int,input().split()))
value = float('inf')
if(len(P)==0):
    print(X)
    exit()
min_P=min(P)
max_P=max(P)
ans_value = max(P)
for i in range(min_P,max_P+1):
    if(i not in P):
        
        if(abs(i-X)<value):
            value=abs(i-X)
            ans_value=i
            
print(ans_value)

Submission status: Wrong Answer

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

check = float("inf")
ans = 0
for p in range(1,101):
    if p in p_lst:
        continue
    else:
        if check > abs(p-x):
            check = abs(p-x)
            ans = p
print(ans)

Submission status: Wrong Answer

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

all_set = set(range(1, 101))
diff_set = all_set - P

min_value = -1
min_diff = 100
for e in diff_set:
    difference = abs(x - e)
    if difference < min_diff:
        min_value = e
        min_diff = difference
print(min_value)

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 = [i for i in range(1, 101) if i not in P]
    mx = 100
    for p in NP:
        if abs(x-p) < abs(x-mx):
            mx = p
    print(mx)

Submission status: Wrong Answer

Solution code:
import sys
X,N = map(int,input().split())
zettai = 10000
ans = 0
if N == 0:
    print(X)
    sys.exit()
    
a = list(map(int,input().split()))

print(a)

for i in range(101,1,-1):
    b = abs(X-i)
    if i in a:
        continue
    elif b <= zettai:
        zettai = b
        ans = i

print(ans)

Submission status: Wrong Answer

Solution code:
import itertools
from collections import deque,Counter
import bisect
import heapq

def IN(): return int(input())
def sIN(): return input()
def MAP(): return map(int,input().split())
def LMAP(): return list(map(int,input().split()))
def TATE(n): return [input() for i in range(n)]
MOD = 10**9 + 7

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


for i in range(1,5555555):
  a = x-i
  b = x+i
  if a not in p and b not in p:
    print(a)
    exit()
  if a not in p and b  in p:
    print(x-i)
    exit()
  if b not in p and a in p:
    print(x+i)
    exit()

Submission status: Wrong Answer

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

if n < 1:
  print(x)
  exit()

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

data.sort()

result = [(abs(x - i), i) for i in range(data[0]-1, data[-1]+1) if i not in data]
r = sorted(result, key=lambda x: x[0])

print(r[0][1])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if n == 0:
    input()
    print(x)
else:
    l = list(map(int, input().split()))
    l.sort()
    small = x
    large = x
    while small in l and large in l:
        small -= 1
        large += 1
    if x - small > large - x:
        print(large)
    else:
        print(small)

Submission status: Wrong Answer

Solution code:
X, N = (int(s) for s in input().rstrip().split())
if N == 0:
  nums = []
else:
  nums = [int(s) for s in input().rstrip().split()]

def find(nums, X):
  if not nums:
    return X
  for i in range(1, X + 1):
    X_plus = X + i
    X_minus = X - i
    
    if X_minus >= 1:
      if X_minus not in nums:
        return X_minus
    if X_plus <= 100:
      if X_plus not in nums:
        return X_plus

print(find(nums, X))

Submission status: Wrong Answer

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

    if n == 0 :
        print(x)
        return None


    p.sort()

    i = 1
    while True :
        idx = x - i
        if not idx in p :
            print(idx)
            return None

        idx = x + i
        if not idx in p :
            print(idx)
            return None

        i += 1

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
X, N = map(int, input().split())
P = [int(p) for p in input().split()]
while True:
  if X in P:
    X += 1
  else:
    print(X)
    exit()

Submission status: Wrong Answer

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

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

cnt = [0] *101
ans1 = 0
ans2 = 0

for _p in p:
    cnt[_p] += 1

for i in range(x, 101):
    if cnt[i] == 0:
        ans1 = i
        break

for i in range(1, x):
    if cnt[i] == 0:
        ans2 = i

if abs(ans1 - x) < abs(ans2 - x):
    print(ans1)
elif abs(ans1 - x) >= abs(ans2 - x):
    print(ans2)

Submission status: Wrong Answer

Solution code:
from sys import stdin, stdout
import heapq
import cProfile
from collections import Counter, defaultdict, deque
from functools import reduce
import math


def get_int():
    return int(stdin.readline().strip())


def get_tuple():
    return map(int, stdin.readline().split())


def get_list():
    return list(map(int, stdin.readline().split()))

x,n = get_tuple()
ls = get_list()
if n==0: print(x)
else:
    st = set()
    for i in range(-99,201): st.add(i)

    for val in ls:
        st.remove(val)

    ans ,mini = float('inf'),float('inf')
    for val in st:
        diff = abs(val-x)
        if diff>0:
            if mini>diff:
                mini = diff
                ans = val
    print(ans)

Submission status: Wrong Answer

Solution code:
x, n = map(int,input().split())
P = list(map(int,input().split()))
Q = []
ans = 100
for i in range(-100,100):
    if i+1 in P:continue
    else:
        Q.append(i+1)
for j in Q:
    d = abs(j - x)
    ans = min(d, ans)

l = x -ans
m = x + ans
if l in Q:
    print(l)
else:
    print(m)