Problem:


Score : 300 points

Problem Statement

Given are an integer X and an integer sequence of length N: p_1, \ldots, p_N.

Among the integers not contained in the sequence p_1, \ldots, p_N (not necessarily positive), find the integer nearest to X, that is, find the integer whose absolute difference with X is the minimum. If there are multiple such integers, report the smallest such integer.

Constraints

1 \leq X \leq 100

0 \leq N \leq 100

1 \leq p_i \leq 100

p_1, \ldots, p_N are all distinct.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

X N
p_1 ... p_N

Output

Print the answer.

Sample Input 1

6 5
4 7 10 6 5

Sample Output 1

8

Among the integers not contained in the sequence 4, 7, 10, 6, 5, the one nearest to 6 is 8.

Sample Input 2

10 5
4 7 10 6 5

Sample Output 2

9

Among the integers not contained in the sequence 4, 7, 10, 6, 5, the ones nearest to 10 are 9 and 11. We should print the smaller one, 9.

Sample Input 3

100 0

Sample Output 3

100

When N = 0, the second line in the input will be empty. Also, as seen here, X itself can be the answer.



Sample input:
6 5
4 7 10 6 5


Sample output:
8

Submission status: Accepted

Solution code:
def forbidden_list():
    condition = input()
    num_str = input()
    
    condition_list = condition.split()
    X = int(condition_list[0])
    N = int(condition_list[1])
    
    if N == 0:
        print(X)
        return
    
    num_list_str = num_str.split()
    num_list = []
    for i in num_list_str:
        num_list.append(int(i))
    
    num_list.sort()
    flag = True
    sub = 0
    tmp = X
    
    while flag:
        tmp = X + sub
        for i in num_list:
            count = 0
            if tmp == i:
                count = 1
                break
        if count == 0:
            print(tmp)
            return
        
        sub += 1
        tmp = X - sub
        for i in num_list:
            count = 0
            if tmp == i:
                count = 1
                break
        if count == 0:
            print(tmp)
            return
    
forbidden_list()

Submission status: Accepted

Solution code:
a = list(map(int, input().split()))
if a[1] == 0:
    print(a[0])
else:
    b = list(map(int, input().split()))
    c = []
    out = 0
    res = 10000001
    for i in range(102):
        if i not in b:
            c.append(i)
    for j in c:
        if (abs(j - a[0]) < res):
            res = abs(j - a[0])
            out = j
    print(out)

Submission status: Accepted

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

not_in_p = []
for i in range(0, 102):
    if i not in p:
        not_in_p.append(abs(x-i))
    else:
        not_in_p.append(102)

address = not_in_p.index(min(not_in_p))
print(address)

Submission status: Accepted

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

o = []
for i in range(2 * X + 1):
    if i in P:
        continue
    o.append(abs(i-X)*10000+i)

print(min(o)%10000)

Submission status: Accepted

Solution code:
x,y=map(int,input().split())
if y==0:
  print(x)
  exit()
p=list(map(int,input().split()))
for i in range(200):
  if not x-i in p:
    print(x-i)
    exit()
  if not x+i in p:
    print(x+i)
    exit()

Submission status: Accepted

Solution code:
X,N = map(int,input().split())
P = list(map(int,input().split()))
ans = 100
l = 101
for i in range(0,102):
    if P.count(i) == 0:
        if abs(i-X) < l:
            #print(i)
            l = abs(i-X)
            ans = i
print(ans)

Submission status: Accepted

Solution code:
import sys


def read_input(trans=int):
    return list(map(trans, input().split()))


X, N = read_input()
if N == 0:
    print(X)
else:
    list_p = read_input()

    for i in range(N+1):
        if X-i not in list_p:
            print(X-i)
            sys.exit()

        if X+i not in list_p:
            print(X+i)
            sys.exit()

Submission status: Accepted

Solution code:
# coding:utf-8


def main():
    X, N = map(int, input().split())
    if (N > 0):
        P = list(map(int, input().split()))
        ans = 0
        abs_temp = 101

        for pi in range(0, 102):
            n = abs(pi - X)
            if n < abs_temp  and not pi in P:
                ans = pi
                abs_temp = n
            elif n == abs_temp  and not pi in P and pi < ans:
                ans = pi
                abs_temp = n

        print(ans)

    else:
        print(X)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
a = [int(x) for x in input().split()]
b = [i for i in range(0,102) if i not in a] 
b_tmp = list(map(lambda s:abs(s-x), b)) #b_tmpはbとxの差分のリストをさくせい
address = b_tmp.index(min(b_tmp))
print(b[address])

Submission status: Accepted

Solution code:
def c_forbidden_list(RANGE=50):
    X, N = [int(i) for i in input().split()]
    P = set([int(i) for i in input().split()]) if N != 0 else set()

    for t in range(RANGE + 1):
        if X - t not in P:
            return X - t
        elif X + t not in P:
            return X + t
    return None  # 入力の制約上ここには来ない

print(c_forbidden_list())

Submission status: Accepted

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

Submission status: Accepted

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

ans = 0
for i in range(102):
    if abs(i - x) < abs(ans - x):
        if i not in p:
            ans = i

print(ans)

Submission status: Accepted

Solution code:
def solution(X, N, P):
    P = set(P)
    if N <= 0 or X not in P:
        return X
    for i in range(1, len(P) + 1):
        left = X - i
        right = X + i
        if left not in P:
            return left
        if right not in P:
            return right

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

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
if n == 0:
    print(x)
    exit()
P = [*map(int,input().split())]
ans = 100 + 100 # inf = x + d + 1
for d in range(100): # [0,100)
    now_diff = abs(ans - x)
    min_x, max_x = x - d, x + d
    if min_x not in P:
        if now_diff > abs(min_x - x): ans = min_x
    elif max_x not in P:
        if now_diff > abs(max_x - x): ans = max_x
print(ans)

Submission status: Accepted

Solution code:
x,n=map(int, input().split())
if n == 0:
  print(x)
  exit()
p=list(map(int, input().split()))
all=set(range(0,102))
s_p=set(p)
kouho=sorted(all-s_p)

min_dis=201
for i in kouho:
  dis=abs(i-x)
  if min_dis > dis:
    min_i=i
    min_dis=dis
print(min_i)

Submission status: Accepted

Solution code:
X,N=map(int,input().split())
li=list(map(int,input().split()))
sa = 101
for i in range(102):
    if sa > abs(X-i) and not i in li:
        sa = abs(X-i)
        ans = i
print(ans)

Submission status: Accepted

Solution code:
x,n=map(int, input().split())
if n == 0:
  print(x)
  exit()
p=list(map(int, input().split()))
all=set(range(-100,102))
s_p=set(p)
kouho=sorted(all-s_p)

min_dis=201
for i in kouho:
  dis=abs(i-x)
  if min_dis > dis:
    min_i=i
    min_dis=dis
print(min_i)

Submission status: Accepted

Solution code:
X,N = map(int,input().split())
if N == 0 :
    print(X)
else :
    P = list(map(int,input().split()))
    a = list(range(10000000))
    ab = 101
    an = []
    for i in range(N):
        a.remove(P[i])
        a = a
    for j in range(0,102):
        ab = min(ab,abs(X - a[j]))
    if X - ab in a :
        print(X - ab)
    elif X + ab in a:
        print(X + ab)

Submission status: Accepted

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

if N == 0:
    print(X)
else:
    for i in range(0,102):
        if i not in P:
            differ.append(abs(X - i))
        else:
            differ.append(1000)
    ans = differ.index(min(differ))
    print(ans)

Submission status: Accepted

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

p_all = set(range(0, 102)) - 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: Accepted

Solution code:
x,y=map(int,input().strip().split())
nums = list(map(int, input().strip().split()))
ans=0
if y==0:
  print(x)
elif x not in nums:
  print(x)
else:
  for i in range(0,102):
    if i not in nums:
      if abs(x-i)<abs(x-ans):
        ans=i
  print(ans)

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
p = list(map(int, input().split()))
ans = X
for i in range(101):
    ans = X - i
    if ans in p:
        ans = X + i
        if ans in p:
            continue
        else:
            break
    else:
        break

print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

def II(): return int(input())
def MII(): return map(int, input().split())
def LII(): return list(map(int, input().split()))

def main():
    X, N = MII()
    p = LII()

    mn = 101
    ans = 0
    for i in range(-1, 102):
        if i not in p:
            if mn > abs(X - i):
                ans = i
                mn = abs(X - i)

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
X,N=map(int,input().split())
p=list(map(int,input().split()))
diff=98
for x in range(102):
    if x not in p and abs(X-x)<diff:
        diff=abs(X-x)
        ans=x
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
x,n = map(int,input().split())
p = list(map(int,input().split()))
 
num_list = list(range(0,102))
y = (num_list + p)
 
counter = Counter(y)
result =  [elem for elem in y if counter[elem] < 2]
 

ans = 10 *100000000000
 
for i in result:
    temp = abs(i - x)
    if ans > temp:
        ans = temp
        res = i
print(res)

Submission status: Accepted

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

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

    num=[1]*102
    count=1

    for i in p:
        num[i]=0   
    if num[x]==1:
        print(x)
    else:
        while True:
            if x-count>-1:
                if num[x-count]==1:
                    print(x-count)
                    break
            if x+count<103:
                if num[x+count]==1:
                    print(x+count)
                    break    
            count+=1

Submission status: Accepted

Solution code:
X,N=map(int,input().split())
p=list(map(int,input().split()))
diff=99
for x in range(102):
    if x not in p and abs(X-x)<diff:
        diff=abs(X-x)
        ans=x
print(ans)

Submission status: Accepted

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

for i in range(101):
  if X-i not in x:
    print(X-i)
    sys.exit()
  elif X+i not in x:
    print(X+i)
    sys.exit()

Submission status: Accepted

Solution code:
X,N=map(int,input().split())
p=list(map(int,input().split()))
diff=100
for x in range(102):
    if x not in p and abs(X-x)<diff:
        diff=abs(X-x)
        ans=x
print(ans)

Submission status: Accepted

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

    d = 1 << 30
    ans = -1
    for v in (0, 101):
        diff = abs(X - v)
        if d > diff or (d == diff and ans > v):
            d = diff
            ans = v

    for v in range(101):
        if v in P: continue
        diff = abs(X - v)
        if d > diff or (d == diff and ans > v):
            d = diff
            ans = v

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# C
x, n = map(int, input().split())
p = list(map(int, input().split()))
# print(p)
ans = 0
if n == 0:
    print(x)
elif x not in p:
    print(x)
else:
    for i in range(102):
        if i not in p:
            if abs(x - i) < abs(x - ans):
                ans = i
    print(ans)

Submission status: Accepted

Solution code:
X,N = map(int, input().split())
try:
  p = list(map(int, input().split()))
except EOFError:
  p = []
  
int_list = [i for i in range(102)]
forbidden_list = sorted(list(set(int_list) - set(p)))
num_X = int_list.index(X)
c = 10000000
 
if X in forbidden_list:
  print(X)
else:
  for i in range(len(forbidden_list) - 1):
    a = abs(X - forbidden_list[i])
    b = abs(X - forbidden_list[i + 1])
    if a == b:
      print(forbidden_list[i])
      break
    elif c > a:
      c = a
    elif c <= a and b >= a:
      print(forbidden_list[i - 1])
      break
    elif b < a:
      print(forbidden_list[i])
      break
  else:
    if a < b:
      print(forbidden_list[i])
    else:
      print(forbidden_list[i + 1])

Submission status: Accepted

Solution code:
x,N=map(int,input().split())
p=list(map(int,input().split()))
ans=101
if x in p:
    for i in range(102):
        if i in p:
            continue
        ans=min(ans,abs(i-x))
    if x-ans in p:
        ans*=-1
else:
    ans=0
print(x-ans)

Submission status: Accepted

Solution code:
def c_forbidden_list(RANGE=101):
    X, N = [int(i) for i in input().split()]
    P = set([int(i) for i in input().split()]) if N != 0 else set()

    for t in range(RANGE + 1):
        if X - t not in P:
            return X - t
        elif X + t not in P:
            return X + t
    return None  # 入力の制約上ここには来ない

print(c_forbidden_list())

Submission status: Accepted

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

table=[0]*102

for i in Ps:
    table[i]=1

ans=0
min=101
for i in range(0,102):
   if table[i]==0:
       temp=abs(x-i)
       if temp<min:
           min=temp
           ans=i

print(ans)

Submission status: Accepted

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

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

#p.sort()

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solution(X, N, P):
    if N <= 0 or X not in P:
        return X

    P.sort()
    diff = [abs(p - X) for p in P]
    X_idx = diff.index(0)
    left = sorted(diff[:X_idx])
    right = sorted(diff[X_idx+1:])

    for i in range(1, len(P) + 1):
        left = X - i
        right = X + i

        nearest_l = None
        nearest_r = None
        if left not in P:
            nearest_l = left
            break
        if right not in P:
            nearest_r = right
            break
    else:
        nearest_r = len(P) + 1
    if nearest_l and nearest_r:
        nearest = min(nearest_l, nearest_r)
    elif nearest_l is not None:
        nearest = nearest_l
    elif nearest_r is not None:
        nearest = nearest_r
    return nearest

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

print(solution(X, N, P))

Submission status: Accepted

Solution code:
import sys

def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def S(): return sys.stdin.readline().rstrip()

X,N = map(int,S().split())
p = LI()
p = sorted(p)

for i in range((N+1)//2+1):
    if not (X-i in p):
        print(X-i)
        exit()
    if not (X+i in p):
        print(X+i)
        exit()

Submission status: Accepted

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

for i in range(1000):
    if X-i not in arr:
        print(X-i)
        exit()
    if X+i not in arr:
        print(X+i)
        exit()

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
if n==0:exit(print(x))
p=list(map(int,input().split()))
ans=-1
tmp=float("inf")
for i in range(0,102):
    if i in p:
        continue
    k=abs(i-x)
    if k<tmp:
        ans=i
        tmp=k
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
#, setrecursionlimit, stdout
#setrecursionlimit(1000000)
#from collections import deque
#from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin
def ii(): return int(stdin.readline())
def fi(): return float(stdin.readline())
def mi(): return map(int, stdin.readline().split())
def fmi(): return map(float, stdin.readline().split())
def li(): return list(mi())
def si(): return stdin.readline().rstrip()
def lsi(): return list(si())
#mod=1000000007
res=['Yes', 'No']
############# CODE STARTS HERE #############

test_case=1
while test_case:
    test_case-=1

    v=[1]*110
    x, n=mi()
    for i in li():
        v[i]=0
    l=r=x
    while True:
        if v[l]:
            print(l)
            exit()
        elif v[r]:
            print(r)
            exit()
        l-=1
        r+=1

Submission status: Accepted

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

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

hanb = 0
hans = 0

for i in range(0,100):
    big = x + i
    sml = x - i
    
    if big not in p:
        hanb += 1

    if sml not in p:
        hans += 1

    if hanb == 1 or hans == 1:
        break

if hanb == 1 and hans == 1:
    print(sml)

elif hans == 1:
    print(sml)

else:
    print(big)

Submission status: Accepted

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

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

Submission status: Accepted

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

import sys
# import time
# import math
# import numpy as np
# import scipy.sparse.csgraph as cs            # csgraph_from_dense(ndarray, null_value=inf), bellman_ford(G, return_predecessors=True), dijkstra, floyd_warshall
# import random                                # random, uniform, randint, randrange, shuffle, sample
# import string                                # ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from datetime import date, datetime          # date.today(), date(year,month,day) => date obj; datetime.now(), datetime(year,month,day,hour,second,microsecond) => datetime obj; subtraction => timedelta obj
# from datetime.datetime import strptime       # strptime('2019/01/01 10:05:20', '%Y/%m/%d/ %H:%M:%S') returns datetime obj
# from datetime import timedelta               # td.days, td.seconds, td.microseconds, td.total_seconds(). abs function is also available.
# from copy import copy, deepcopy              # use deepcopy to copy multi-dimentional matrix without reference
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from fractions import Fraction               # Fraction(a, b) => a / b ∈ Q. note: Fraction(0.1) do not returns Fraciton(1, 10). Fraction('0.1') returns Fraction(1, 10)
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)



def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79e+308
    # inf = 2 ** 63 - 1             # (for fast JIT compile in PyPy) 9.22e+18
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def isp():   return input().split()
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    x, n = mi()
    s = set(lmi())

    dist = 0
    while True:
        if x - dist not in s:
            print(x - dist)
            exit()
        elif x + dist not in s:
            print(x + dist)
            exit()
        dist += 1


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
now = 1001001001
ans = -1
for i in range(102):
    if i in p:
        continue
    j = abs(i-x)
    if j<now:
        ans = i
        now = j
print(ans)

Submission status: Accepted

Solution code:
import sys

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

p=list(map(int,input().split()))
n=[0]*(103)
for i in range(len(p)):
	n[p[i]+1]=1

d_min=1000
for j in range(103):
	if n[j]!=1:
		d=abs((X+1)-j)
		if d_min>d:
			d_min=d
			ans=j-1
print(ans)

Submission status: Accepted

Solution code:
X,N,*p = map(int,open(0).read().split())
dif = 100
ans = -1
for i in range(102):
    a = abs(X-i)
    if i in p:
        continue
    if  a < dif:
        dif = a
        ans = i
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect
x,n=map(int,input().split())
l=list(map(int,input().split()))
k=[0]*(102)
for i in l:
    k[i]=1
s=10000
for i in range(102):
    if k[i]==1:
        continue
    if abs(x-i)<s:
        s=abs(x-i)
        ans=i
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
p=list(map(int,input().split()))
m=102
j=0
for i in range(0,102):
    if abs(x-i)<m and i not in p:
        m=abs(x-i)
        j=i
print(j)

Submission status: Accepted

Solution code:
X,N=list(map(int,input().split()))
if N>0:p=list(map(int,input().split()))
else:p=[]
memo=[False for i in range(105)]
for i in range(N):memo[p[i]]=True

riget,left=X+1,X-1
ans_r,ans_l=0,0

while(True):
    if memo[left]==False:
        ans_l=left
        break
    if memo[riget]==False:
        ans_r=riget
        break
    left-=1
    riget+=1

if N==0 or memo[X]==False:print(X)
elif abs(X-ans_r)>=abs(X-ans_l):print(ans_l)
else:print(ans_r)

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
if n == 0:
    print(x)
    exit()
P = [*map(int,input().split())]
ans = 100+100 # inf = x + d + 1
for d in range(100): # [0,100)
    now_diff = abs(ans - x)
    min_x, max_x = x - d, x + d
    if min_x not in P:
        if now_diff > abs(min_x - x): ans = x-d
    elif max_x not in P:
        if now_diff > abs(max_x - x): ans = x+d
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import deque
import math

def Next(): return input()
def NextInt(): return int(Next())
def NextInts(): return map(int,input().split())
def Nexts(): return map(str,input().split())
def NextIntList(): return list(map(int,input().split()))
def RowInts(n): return [input() for i in range(n)]

x, n = NextInts()
da = NextIntList()

ans = -1000

for i in range(200):
    if abs(ans-x) > abs(x-i) and not(i in da):
        ans = i

print(ans)

Submission status: Accepted

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

not_in_p = [i for i in range(0, 102) if i not in p]
nip_temp = list(map(lambda s: abs(x - s), not_in_p))

address = nip_temp.index(min(nip_temp))
print(not_in_p[address])

Submission status: Accepted

Solution code:
import sys

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

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

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


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

    sa = float("inf")

    ans = 0
    for i in range(-100, 102):
        if i in P:
            continue

        satmp = sa
        sa = min(sa, abs(i - X))
        if sa != satmp:
            ans = i

    print(ans)

    
    

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
if n == 0:
    print(x)
    exit()
P = [*map(int,input().split())]

ans = 100000000 # inf
for d in range(100): # [0,100)
    now_diff = abs(ans - x)
    min_x, max_x = x - d, x + d
    if min_x not in P:
        if now_diff > abs(min_x - x): ans = x-d
    elif max_x not in P:
        if now_diff > abs(max_x - x): ans = x+d
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def read_input(trans=int):
    return list(map(trans, input().split()))


X, N = read_input()
if N == 0:
    print(X)
else:
    list_p = read_input()

    for i in range(N+1):
        if X-i in list_p:
            if X+i in list_p:
                continue
            else:
                print(X+i)
                break
        else:
            print(X-i)
            break

Submission status: Accepted

Solution code:
def read_input(trans=int):
    return list(map(trans, input().split()))


X, N = read_input()
if N == 0:
    print(X)
else:
    list_p = read_input()

    for i in range(100):
        if X-i in list_p:
            if X+i in list_p:
                continue
            else:
                print(X+i)
                break
        else:
            print(X-i)
            break

Submission status: Accepted

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

for i in range(x, -1, -1):
  if not i in p:
    a1 = i
    break

for i in range(x, 100 + 2):
  if not i in p:
    a2 = i
    break

if x - a1 <= a2 - x:
  print(a1)
else:
  print(a2)

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
if n == 0:
    print(x)
    exit()
P = [*map(int,input().split())]

ans = 100000000 # inf
for d in range(100+10):
    now_diff = abs(ans - x)
    min_x, max_x = x - d, x + d
    if min_x not in P:
        if now_diff > abs(min_x - x): ans = x-d
    elif max_x not in P:
        if now_diff > abs(max_x - x): ans = x+d
print(ans)

Submission status: Accepted

Solution code:
x, n = (int(x) for x in input().split())
p_list = list(map(int, input().split()))
 
ans = 0
 
max_ = 0
min_ = 0

for i in range(x, 102, 1) :
 
    if i not in p_list:
        max_ = i
        break
for j in reversed(range(x + 1)) :

 
    if j not in p_list:
        min_ = j
        break
 
if abs (min_ - x) <= abs(max_ - x) :
    ans = min_
else : 
    ans = max_
 
print(ans)

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
a=list(map(int,input().split()))
if n==0:
  ans=x
else:
  ans=0
  for i in range(101):
    y=x-i
    if y not in a:
      ans=y
      break
    z=x+i
    if z not in a:
      ans=z
      break
print(ans)

Submission status: Accepted

Solution code:
import numpy

import sys
#整数xと長さn
x, n = map(int, input().split())

#入力される整数列 list
list = list(map(int, input().split()))

#入力確認
#print(x, n)
#print(list)

for i in range(101):
    if x - i not in list:
        print(x - i)
        sys.exit()
    elif x + i not in list:
        print(x + i)
        sys.exit()

Submission status: Accepted

Solution code:
X,N=map(int,input().split())
p=list(map(int,input().split()))
diff=102
for x in range(102):
    if x not in p and abs(X-x)<diff:
        diff=abs(X-x)
        ans=x
print(ans)

Submission status: Accepted

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

ans=1000
for i in range(-105,102):
    if i in p:
        continue
    if abs(x-ans)>abs(i-x):
        ans=i
print(ans)

Submission status: Accepted

Solution code:
a,b=map(int,input().split())
if b!=0:
  B=list(map(int,input().split()))
  A=B.copy()
  for i in range(b):
    A[i]= abs(A[i]-a)
  A.sort()
  for i in range(A[-1]+2):
    if A.count(i)==1:
      if i!=0:
        if a-i in B:
          result=a+i
          break
        else:
          result=a-i
          break
    elif A.count(i)==0:
      result=a-i
      break
else:
  result=a
print(result)

Submission status: Accepted

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