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:
#n, m, q = map(int, input().split())
#List = list(map(int, input().split()))
#req = [list(map(int, input().split())) for _ in range(q)]
#t = t[:-1]
#print(ans[j], end = "") 改行無しで出力
#[0]*n
import math
x, n = map(int, input().split())
p = list(map(int, input().split()))

if n == 0:
    print(x)

else:
    max = -1
    i = -1
    while(max == -1):
        i = i + 1
        if p.count(x+i) == 0:
            max = x+i

    min = -1
    j = -1
    while(min == -1):
        j = j + 1
        if p.count(x-j) == 0:
            min = x-j

    if (abs(x-max) < abs(x-min)):
        print(max)
    else:
        print(min)

Submission status: Accepted

Solution code:

MOD = 10**9+7

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

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

p = []
for i in range(102):
    p.append(i)

for i in range(N):
    p[P[i]] = MOD

tmp = 0
m = MOD
ans = 0
for i in reversed(range(0,102)):
    tmp = abs(X-p[i])
    m = min(tmp,m)
    if m == tmp:
        ans = p[i]

print(ans)

Submission status: Accepted

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

nyuryoku = []

try:
    while True:
        p = list(map(int,input().split()))
        if p == '':
            break
        nyuryoku.append(p)

except EOFError:
    pass

# for p in nyuryoku:
#     print(p)

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

L = []
for i in range(1, 100):
    for j in ['-', '']:
        # print(j, i)
        a = (j + str(i))
        # print(int(a))
        L.append(a)
# print(L)

if N == 0:
    print(X)
elif X not in p:
    print(X)
else:
    for i in L:
        if (X + int(i)) not in p:
            print(X + int(i))
            break

Submission status: Accepted

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


  
  if x not in i:
    print(x)
  
  else:
    p = 1
    while True:
      z = x - p
      if z not in i:
        print(z)
        break
        
      z = x + p
      if z not in i:
        print(z)
        break
        
      p = p +1

Submission status: Accepted

Solution code:
from collections import defaultdict
x,n=map(int,input().split())
p_array=map(int,input().split())
p_map=defaultdict(bool)

for p in p_array:
    p_map[p]=True
ans=0
for i in range(51):
    if not p_map[x-i]:
        ans=x-i
        break
    elif not p_map[x+i]:
        ans=x+i
        break
print(ans)

Submission status: Accepted

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

i=0
p=X+1
q=X-1
while True:
    if N==0:
        print(int(X))
        break
    if X not in P:
        print(int(X))
        break
    if q not in  P:
        print(int(q))
        break
    if p not in P:
        print(int(p))
        break
    i+=1
    p+=1
    q-=1

Submission status: Accepted

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

p = list(map(int, input().split()))
pp = set(p)
numlist = [i for i in range(-1000, 1000)]
numlistt = set(numlist)
newlist = numlistt - pp
newlistt = list(newlist)
absn = 1000
ans = 1000
 
for i in newlistt:
    if absn > abs(X-i):
        ans = i
        absn = abs(X-i)
    elif absn == abs(X-i) and i < ans:
        ans = i
        absn = abs(X-i)

print(ans)

Submission status: Accepted

Solution code:
X,N = map(int,input().split())
p = list(map(int,input().split()))
number = X
j = 0
while j<100:
    if (X-j in p)== False:
        number = X-j
        break
    if (X+j in p) == False:
        number = X+j
        break
    j = j + 1
print(number)

Submission status: Accepted

Solution code:

import numpy as np
from functools import *

import sys
sys.setrecursionlimit(100000)



def gcd(a, b):
	while b:
		a, b = b, a % b
	return a


def acinput():
    return list(map(int, input().split(" ")))


X,N=acinput()
if N>0:
    #print(X,N)
    p=sorted(acinput())
else:
    print(X)
    sys.exit()

res=0
res_v=2000
for i in range(0,102):
    #print(i,res,res_v)
    
    d=abs(X-i)
    if res_v>=d and not (i in p):
        if i<X:
            res_v=d
            res=i
        elif d<res_v:
            res_v=d
            res=i
        
print(res)        
#print(res_v)

Submission status: Accepted

Solution code:
x,n = map(int, input().split())
a = list(map(int,input().split()))
c = -1
b = 0
d = 101
e = 0
for w in range(103):
  if c not in a:
    b = abs(x - c)
    if b < d:
      d = b
      e = c
      c += 1
    else:
      c += 1
  else:
    c += 1
print(e)

Submission status: Accepted

Solution code:
import math

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

pnt_big = 0
pnt_small = 0
ans_big = 100
ans_small = 100
for i in range(101):
    if p.count(x+i) == 0:
        ans_big = x+i
        pnt_big = 1
    if p.count(x-i) == 0:
        ans_small = x-i
        pnt_small = 1
    if pnt_small == 1 or pnt_big == 1:
        break

if pnt_big ==1 and pnt_small == 1:
    print(ans_small)
if pnt_big == 0 and pnt_small == 1:
    print(ans_small)
if pnt_big == 1 and pnt_small == 0:
    print(ans_big)

Submission status: Accepted

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


def serchBup(list,n):
    if n in list:
        return 1+serchBup(list,n+1)
    else:
        return 1
        
    
def serchBdown(list,n):
    if n in list:
        return -1+serchBdown(list,n-1)
    else:
        return -1

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

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

    for i in range(n):
        if abs(x-p[i])<min:
            min  = abs(x-p[i])
            ans = p[i]
            pos=i
    
    if ans in p:
        #print("True")
        tmp1=serchBup(p,ans+1)
        tmp2=serchBdown(p,ans-1)
        #print(tmp1,tmp2)
        if abs(tmp1) < abs(tmp2):
            print(ans+tmp1)
        else:
            print(ans+tmp2)
        
    else:
        print("Fasle")
        print(ans)

Submission status: Accepted

Solution code:
nums=[int(s) for s in input().split()]

x=nums[0]
n=nums[1]

if n==0:
  print(x)
else:
  row=[int(s) for s in input().split()]
  ls=[]
  for i in range(0,220):
    if i not in row:
      ls.append(abs(i-x))

  ls.sort()

  if x-ls[0] not in row:
    print(x-ls[0])
  else:
    print(x+ls[0])

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


for i in range(100) :
    i1=x-i
    i2=x+i
    
    if i1 not in p and i2 not in p :
        print(i1)
        sys.exit()
        
    
    if i1 not in p and i2 in p :
        print(i1)
        sys.exit()
    
    if i2 not in p and i1 in p :
        print(i2)
        sys.exit()

Submission status: Accepted

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

  i=0
  while(True):

    Xi = X - i
    if Xi not in p_list:
      break

    Xi = X + i
    if Xi not in p_list:
      break

    i = i + 1

  print(Xi)

Submission status: Accepted

Solution code:
s=input().rstrip().split(' ')
x=int(s[0])
n=int(s[1])

if(n>0):
    s=input().rstrip().split(' ')
    p=[]
    
    for i in s:
        p.append(int(i))
    
    p.sort()
    cur1=x
    count1=0
    
    if(p[n-1]>x):
        while(cur1 in p):
            cur1+=1
            count1+=1
    elif(p[n-1]==x):
        cur1+=1
        count1+=1
        
    cur2=x
    count2=0
    
    if(p[0]<x):
        while(cur2 in p):
            cur2-=1
            count2+=1
    elif(p[n-1]==x):
        cur2-=1
        count2+=1
        
    if(count1>=count2):
        print(cur2)
    else:
        print(cur1)
        
else:
    print(x)

Submission status: Accepted

Solution code:
# import numpy as np
import sys
input = sys.stdin.readline


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

    ans = x
    for i in range(-1, 102):
        if i in p:
            continue

        if i <= x:
            ans = i
        else:
            if x - ans > i - x:
                ans = i
            break

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
x,n = map(int, input().split())
if n != 0:
    p = list(map(int, input().split()))
    flag = False
    for i in range(100):
        for j in range(n):
            if p[j] == x - i:
                break
            if j == n-1:
                print(x - i)
                flag = True
                break
        if flag:
            break
        for h in range(n):
            if p[h] == x + i:
                break
            if h == n-1:
                print(x + i)
                flag = True
                break
        if flag:
            break
else:
    print(x)

Submission status: Accepted

Solution code:
X, N = list(map(int, input().strip().split()))
l = list(map(int, input().strip().split()))
l = sorted(l, reverse = False)

rslt = 200

#自明なパターン
if N == 0: rslt = X
if N != 0:
  if l[0] > X: rslt = X
  elif l[-1] < X: rslt = X
  elif (l[0]<=X) and (l[-1]>=X):
    e_min = int(l[0]-1)
    e_max = int(l[-1]+1)
    e_l = [i for i in range(e_min, e_max+1) if i not in l]
    for n in e_l[::-1]:
      if abs(X-n) <= abs(X - rslt): rslt = n
  
print(rslt)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = set(map(int, input().split()))
l = set(range(102))
l = l - p
a = list(l)
a = sorted(a, reverse=True)
t = 101; ans=-1
for i in a:
    if(t >= abs(x-i)):
        t = abs(x-i)
        ans = i
print(ans)

Submission status: Accepted

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

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

dif = 100
ans = 0

for i in range(min(p) - 1, max(p) + 2):
    if not (i in p):
        if dif > abs(x - i):
            dif = abs(x - i)
            ans = i

print(ans)

Submission status: Accepted

Solution code:
"""#D - Not Divisible
N= map(int,input().split())
A= list(map(int,input().split()))"""


#C - Forbidden List
X,N= map(int,input().split())
p= list(map(int,input().split()))
A= list(range(-200,200))
#print(A)
for i in range(N):
    A.remove(p[i])

D = 201
ans = -100
for j in range(len(A)):
    if D > abs(X - A[j]):
        D = abs(X - A[j])
        ans = A[j]

    else:
        pass
print(ans)

Submission status: Accepted

Solution code:
X,N = map(int,input().split())
if N != 0:
  num = list(map(int,input().split()))
  num.sort()
b = 1000
if N == 0:
  print(X)
else:
  for i in range(N):
    a = abs(int(num[i])-X)
    if a <= b:
      b = a
      ans = int(num[i]) - b
  low = ans
  high = ans
  while low in num:
    low -= 1
  
  while high in num:
    high += 1
  loo = abs(low-ans)
  hii = abs(high-ans)
  if loo > hii:
    print(high)
  else:
    print(low)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
x,n = map(int, input().split())
if n > 0:
    p = list(map(int , input().split()))
else:
    p  = []
a = list(set(list(range(-100,102))) - set(p))
values = []
for i in a:
    values = values +  [[abs(x-i), i]]
values.sort(key=lambda x: x[0])
mins = values[0][0]
b = []
for i in values:
    if i[0] > mins:
        break
    b += [i[1]]
b.sort()
print(b[0])

Submission status: Accepted

Solution code:
n = input().split()
X = int(n[0])
N = int(n[1])

try:
    n2 = input()
except:
    pass

if N == 0:
    print(X)

else:
    n2 = n2.split()
    p = [int(item) for item in n2]

    for i in range(101):
        if i == 0:
            if X not in p:
                print(X)
                break
        tmp = []

        if (X + i not in p ):
            tmp.append(X + i)

        if (X - i not in p ):
            tmp.append(X - i)
    
        if len(tmp)!=0:
            print(min(tmp))
            break

Submission status: Accepted

Solution code:
X, N = map(int,input().split())
if N > 0:
  p = list(map(int, input().split()))
else:
  p=[]
#print(p)
p.sort()
#dis = p[0] - X
ans_1 = X
ans_2 = X
for i in range(N) :
  pi = p[i]
  if pi == ans_1:
    ans_1 += 1

p.reverse()
for i in range(N) :
  pi = p[i]
  if pi == ans_2:
    ans_2 -= 1

ans = X
if abs(ans_1 - X) < abs(ans_2 - X):
  ans = ans_1
elif ans_1 - X == -abs(ans_2 - X):
  ans = ans_1
else:
  ans = ans_2
print(ans)

Submission status: Accepted

Solution code:
import sys

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

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

all_list = [int(x) for x in range(0, 102)]
target_list = sorted(list(set(list_p) ^ set(all_list)))

ans = [abs(num - X) for num in target_list]
# print(all_list)
# print(target_list)
# print(min(ans))
# print(ans.index(min(ans)))
print(target_list[ans.index(min(ans))])

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
p=set([int(i) for i in input().split()])
low=x
high=x
if not x in p:
  print(x)
  exit()
while True:
  low-=1
  if not low in p:
    print(low)
    exit()
  high+=1
  if not high in p:
    print(high)
    exit()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
x, n = map(int, input().split())
aa = 0
if n == 0:
   aa = 1
if aa == 0:
    p = list(map(int, input().split()))
    p.sort()
    i = 0
    flg = 0
    dis = []
    while flg == 0:
        if i > 100:
            flg = 1
        if i in p:
            dis.append(5000)
        else:
            dis.append(abs(x-i))
        i += 1
    for i in range(len(dis)):
        if dis[i] == min(dis):
            print(i)
            break
else:
    print(x)

Submission status: Accepted

Solution code:
a = list(map(int,input().split()))
x =a[0]
n =a[1]
if n==0:
  print(x)
else:
  p = list(map(int,input().split()))
  p.sort()
  out_p = []
  for i in range(p[n-1]-p[0]+1):
    if not i+p[0] in p:
      out_p.append(i+p[0])
  if min(p)>x or max(p)<x:
    print(x)
  else:
    re_p =[]
    for j in range(len(out_p)):
      re_p.append(abs(out_p[j]-x))
    if re_p:
      print(out_p[re_p.index(min(re_p))])
    else:
      if abs(max(p)-x)>=abs(min(p)-x):
        print(min(p)-1)
      else:
        print(max(p)+1)

Submission status: Accepted

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

for i in range(n):
    p[i] = int(p[i])

for i in range(100):
    min_flag = 0
    max_flag = 0
    for j in range(n):
        if p[j] != x - i:
            min_flag += 1
        if p[j] != x + i:
            max_flag += 1

    if min_flag == n:
        ans = x-i
        break
    elif max_flag == n:
        ans = x+i
        break

print(ans)

Submission status: Accepted

Solution code:
# /usr/bin/python3
# -*- coding: utf-8 -*-
from queue import Queue
from queue import LifoQueue as Stack
from math import sqrt, floor, ceil, log2, log10, pi
from fractions import gcd
from itertools import permutations, combinations
from operator import itemgetter
from functools import cmp_to_key


INF=1001001001
__MOD__=(10**9)+7
yn = 'YNeos'
judge = False
cnt = 0
ans = None


def lcm(a, b):
    return (a*b) // gcd(a,b)

def intinput():
    return int(input())

def mulinputs():
    return map(int,input().split())

def lineinputs(func=intinput):
    datas = []
    while True:
        try:
            datas.append(func())
        except EOFError:
            break
    return datas

class ModInt():
    def __init__(self, x):
        self.__x = (x % __MOD__)
    def __add__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x + other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x + other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __radd__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x + self.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x + self.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __sub__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x - other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x - other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __rsub__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x - self.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x - self.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __mul__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x * other.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x * other.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __rmul__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x * self.__x)%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x * self.__x)%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __truediv__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((self.__x * other.__modinv())%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((self.__x * other.__modinv())%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")
    def __rtruediv__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__((other.__x * self.__modinv())%__MOD__))
        elif type(other) == ModInt:
            return self.__class__((other.__x * self.__modinv())%__MOD__)
        else:
            raise Exception("Not Int or Not ModInt")

    def __pow__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__(pow(self.__x, other.__x, __MOD__)))
        elif type(other) == ModInt:
            return self.__class__(pow(self.__x, other.__x, __MOD__))
        else:
            raise Exception("Not Int or Not ModInt")
    def __rpow__(self, other):
        if type(other) == int:
            other = self.__class__(other)
            return int(self.__class__(pow(other.__x, self.__x, __MOD__)))
        elif type(other) == ModInt:
            return self.__class__(pow(other.__x, self.__x, __MOD__))
        else:
            raise Exception("Not Int or Not ModInt")

    def __modinv(self, m=__MOD__):
        a = self.__x
        if a == 0:
            raise ZeroDivisionError()
        if gcd(a, m) != 1:
            raise Exception("%sの逆数は求まりません。" % a)
        b, u, v = m, 1, 0
        while b != 0:
            t = a//b;
            a -= t*b
            a, b = b, a
            u -= t * v
            u, v = v, u
        u %= m
        if u < 0:
            u += m
        return u
    def __int__(self):
        return self.__x
    def __str__(self):
        return str(self.__x)



if __name__ == '__main__':
    X, N = mulinputs()
    ps = set(mulinputs())

    # # mins = [ [] for _ in range(100)]
    # mins = []
    # m = INF
    # for p in range(-100,101):
    #     if p in ps:
    #         continue
    #     tmp = abs(X-p)
    #     if tmp < m:
    #         m = tmp
    #         mins = []
    #         mins.append(p)
    #     elif tmp == m:
    #         mins.append(p)
# 
    # mins.sort()
    # # 出力
    # if mins:
    #     print(mins[0])
    # else:
    #     print(X)

    if X not in ps:
        print(X)
        exit()
    for i in range(1,100):
        p1, p2 = X-i, X+i
        if p1 not in ps:
            print(X-i)
            exit()
        if p2 not in ps:
            print(X+i)
            exit()

Submission status: Accepted

Solution code:
def f(x, P):
    y = x
    z = x
    while y > 0 or z <= 100:
        if y not in P:
            return y
        y -= 1
        if z not in P:
            return z
        z += 1


x, N = map(int, input().split())
if N:
    P = list(map(int, input().split()))
    print(f(x, P))
else:
    print(x)

Submission status: Accepted

Solution code:
a = input().split(" ")
x = int(a[0])
if a[1] == "0":
    print(a[0])
else:
    b = input().split(" ")
    c = []
    for i in b:
        c.append(int(i))
    d = sorted(c)
    e = 0
    while True:
        y = x - e
        if d.count(y) == 0:
            print(x-e)
            break
        y = x + e
        if d.count(y) == 0:
            print(x+e)
            break
        e += 1

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
import bisect
import numpy as np
import math
from collections import deque
from collections import defaultdict
from math import gcd


def main():
    X, N = map(int, input().split())
    P = list(map(int, input().split()))
    P = np.array(P)
    
    P = np.sort(P)
    ind = bisect.bisect_right(P, X)

    if len(P) == 0 or P[ind-1] != X:
        return X
    
    if len(P) == 1:
        if P[0] != X:
            return X
        else:
            return X-1
    
    Left = P[:ind-1] - X
    Right = P[ind:] - X

    Left = abs(Left[::-1])

    diff = 1
    Left_over = False
    Right_over = False

    if len(Left) == 0:
        Left_over = True
    if len(Right) == 0:
        Right_over = True

    while True:
        if not Left_over and Left[0] != diff:
            return X - diff
        elif Left_over:
            return P[0] - 1
        elif not Right_over and Right[0] != diff:
            return X + diff
        elif Right_over:
            return P[-1] + 1
        diff += 1
        if len(Left) >= 2:
            Left = Left[1:]
        else:
            Left_over = True
        if len(Right) >= 2:
            Right = Right[1:]
        else:
            Right_over = True

        if Left_over and Right_over:
            return P[0]-1


print(main())

Submission status: Accepted

Solution code:
[X,N] = [int(i) for i in input().split()]
if N == 0:
  print(X)
else:
  PA = [int(i) for i in input().split()]
  if not X in PA:
    print(X)
  else:
    i = 1  
    while True:
      [m,p] = [X-i,X+i]
      if not m in PA:
        print(m)
        break
      elif not p in PA:
        print(p) 
        break
      i += 1

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p_list = [i for i in map(int, input().split())]
p_list.sort()
plus_count = 1
minus_count = -1
while True:
    m_p = x + minus_count in p_list
    p_p = x + plus_count in p_list
    if x not in p_list:
        print(x)
        break
    elif m_p is False:
        print(x + minus_count)
        break
    elif p_p is False:
        print(x + plus_count)
        break
    else:
        minus_count -= 1
        plus_count += 1

Submission status: Accepted

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

num = [0,101]
for i in range(100):
  num.append(i + 1)
num.sort()

if n == 0:
  ans = x
else:
  p = list(map(int, input().split()))
  if p.count(x) == 0:
    ans = x
  else:
    for i in range(n):
      num.remove(p[i])
    for i in range(len(num)):
      num[i] -= x
    
    max_m = -200
    for i in range(len(num)):
      if num[i] < 0 and max_m < num[i]:
        max_m = num[i]
    
    min_p = 200
    for i in range(len(num)):
      if num[i] > 0 and min_p > num[i]:
        min_p = num[i]
    
    if abs(min_p) < abs(max_m):
      ans = min_p
    else:
      ans = max_m
    ans += x
print(ans)

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
p = list(map(int, input().split()))
ans = 10000
flg = 200
for i in range(X - 100, X + 101):
    if i in p:
        continue
    if flg > abs(X - i):
        flg = abs(X - i)
        ans = i
print(ans)

Submission status: Accepted

Solution code:
X , N = map(int,input().split())
if N == 0:
    print(X)
elif N == 1:
    P = int(input())
    if P == X:
        print(X - 1)
    elif X + 1 == P or X - P > 1:
        print(X - 1)
    else:
        print(X + 1)

else:
    P = list(map(int,input().split()))
    j = 1
    if X not in P:
        print(X)
    else:
        while True:
            
            if X - j not in P:
                print(X - j)
                break
            if X + j not in P:
                print(X + j)
                break
            j += 1

Submission status: Accepted

Solution code:
x,n,*p=map(int,open(0).read().split())
p=set(p)
l=r=x
while 1:
  if l not in p:
    print(l)
    break
  if r not in p:
    print(r)
    break
  l-=1
  r+=1

Submission status: Accepted

Solution code:
from sys import stdin
import sys

MAX_N = 100;

X, N = [int(x) for x in stdin.readline().rstrip().split()]
if N==0:
  print(X)
  sys.exit()
p = [int(x) for x in stdin.readline().rstrip().split()]

for i in range(MAX_N//2+1):
  a=X-i
  if not a in p:
    print(a)
    break
  a=X+i
  if not a in p:
    print(a)
    break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#C
import numpy as np
x,n=map(int,input().split())
ans=0
b_list=[]
if n==0:
    ans=x
else:
    p_list=list(map(int,input().split()))
    
    s=x-int(n/2)-1
    g=x+int(n/2)+1
    ans_list=[]
    for i in range(s,g+1):
        if i not in p_list:
            b_list.append(i)
    #print(b_list)
    ans=b_list[0]
    for i in b_list[1:]:
        if abs(x-i)<abs(x-ans):
            ans=i
        else:  
            break

                
print(ans)

Submission status: Accepted

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

    p = list(map(int, input().split()))
    p.sort()
    i = 0  # (p < X) p[i] == X (X < p)
    s_i = 0
    l_i = n
    while i < n:
        if p[i] == x: break
        elif p[i] > x: 
            print(x)
            return
        else: i += 1

    s_i = i-1
    l_i = i+1

    ans = 0
    diff = 1
    while True:
        if s_i < 0 or p[s_i] < x-diff:
            ans = x-diff
            break
        elif l_i >= n or p[l_i] > x+diff:
            ans = x+diff
            break
        else:
            s_i -= 1
            l_i += 1
            diff += 1

    print(ans)

resolve()

Submission status: Accepted

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

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

    p_set = set(p_list)
    new_list = []
    new_list.append(0)
    new_list.append(101)
    for i in range(1, 101):
        if i in p_set:
            pass
        else:
            new_list.append(i)

#    print(new_list)

    min_x = 100 #絶対値の最小
    min_diff = 100
    for x in new_list:
        if abs(x - X) <= min_diff:
            if min_diff == abs(x - X):
                if x < min_x:
                    min_x = x
            else:
                min_x = x
                min_diff = abs(x - X)
            
        else:
            pass
    print(min_x)

Submission status: Accepted

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

ans = X
if N !=0:
  P = list(map(int,input().split()))
  ansR = X
  ansL = X
  while True:
    if ansR in P and ansL in P:
      ansR +=1
      ansL -=1
    else:
      ans = min(ansR,ansL)
      if ans in P:
        print(max(ansR,ansL))
        break
      else:
        print(ans)
        break
else:
  print(ans)

Submission status: Accepted

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

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

arr = list(map(int, input().split())) # p1 ... pn

arr2 = []
arr3 = []

for i in range(-50, 110):
    if not i in arr:
        arr2.append(i)
        arr3.append(abs(x - i))

n2 = min([i for i, v in enumerate(arr3) if v == min(arr3)])
print(arr2[n2])

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
if n != 0:
    p = set(map(int, input().split()))
    nums = set([])
    for i in range(0, 102):
        nums.add(i)
    rest = nums.difference(p)
    minVal = 1000
    for j in rest:
        if abs(x - j) < abs(x - minVal):
            minVal = j
        else:
            pass
    print(minVal)
else:
    print(x)

Submission status: Accepted

Solution code:
import math
a,b=map(int,input().split(" "))
c=input()
if c=="":
    print(a)
else:
    c = list(map(int,c.split(" ")))
    c.sort()
    #print(c)
    inaria=list(range(min(c)-1,max(c)+2))
    add1=c+inaria
    add1=sorted(add1)
    l_all_only = [x for x in add1 if add1.count(x) == 1]
    #print(l_all_only)
    min=4000000
    min_data=0
    for n in l_all_only:
        abn=abs(a-n)
        #print(n,abn)
        if abn<min:
            min=abn
            min_data=n
    print(min_data)

Submission status: Accepted

Solution code:
X,N = map(int,input().split())
#p = [0]*N
p = list(map(int,input().split()))
ans = 0
tmp = []
tmpans = 0

for i in range(102):
    if i in p:
        continue
    else:
        if abs(X-ans)>abs(X-i):
            ans = i
            tmp.append(i)
            # if i < tmpans:
            #     ans = i
            # tmpans = ans
            # if ans == 0:
            #     ans = i
            # else:
            #     if ans > i:
            #         ans = i




print(ans)
#print(tmp)

Submission status: Accepted

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

candidates = list(map(lambda elm: (abs(x - elm), elm), range(102)))
for p_i in p:
    candidates[p_i] = (10000, p_i)

sorted_candidates = sorted(candidates, key=lambda elm: elm[0])
min_val = sorted_candidates[0][0]
res = []
for candidate in sorted_candidates:
    if min_val == candidate[0]:
        res.append(candidate[1])
print(sorted(res)[0])