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: Runtime Error

Solution code:
x, _ = [int(x) for x in input().split(" ")]
nums = set([int(x) for x in input().split(" ")])

dist = 0

while True:
    if not x - dist in nums:
        print(x - dist)
        exit(0)

    if not x + dist in nums:
        print(x + dist)
        exit(0)

    dist += 1

Submission status: Runtime Error

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

lst=[]
z = 0
index=0
inedx2=0
counterplus=1
counterminus=1
x = int(input())
n = int(input())

while z < n:
    s =int( input())
    lst.append(s);
    z+=1
if n == 0:
    print(x)

for i in lst:
    index = x + counterplus
    index2 = x - counterminus
    if index in lst:
        counterplus +=1
    if index2 in lst:
        counterminus +=1
    
    if counterplus < counterminus:
        index= x + counterplus
    else:
        index = x - counterminus


print(index)

Submission status: Runtime Error

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

#nが0でない場合の処理を考える

def Calculation(x):
	p = list(map(int,input().split())
	#xより値の大きいもので確認
	for i in rage(x+1,100+1):
		if i not in p:
			countl = 0
			countl = i
		break
	#xより値の小さいもので確認
	for i in range(x,1,-1):
		if i not in p:
			coutns = 0
			counts = i
			break

	if abs(contl - i) >= abs(i - counts):
		print(counts)
	else:
		print(countl)

if n == 0:
	print(x)
else:
	Calculation(x)

Submission status: Runtime Error

Solution code:
def ans(x):
	p = list(map(int,input().split()))
	ue = []
	shita = []
#xより値の大きい値を順に比較していき、リストpに存在しない最小値を取得する
	for i in range(x+1,p[-1]+2):
    		if False == (i in p):
        		ue.append(i)
 
#xより値の小さい値を順に比較していき、リストpに存在しない最大値を取得する
	for i in range(p[0] -1,x):
    		if False == (i in p):
        		shita.append(i)

'下記のコードの検証はまだ行っていないため、次回は下記のコードの実行検証から確認をする'

	abs_ue = 100
	for i in ue:
    		if abs_ue > abs[x - i]:
        		abs_ue = i
        		break

	abs_shita = 100
	daburi = []
		for i in shita:
    			if abs_shita > abs(x - i):
        			abs_shita = i
        			break


	if abs_ue > abs_shita:
    		print(abs_shita)
	else:
    		print(abs_ue)

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

if n == 0:
	print(x)
else:
	def(x)

Submission status: Runtime Error

Solution code:
x = int(input())
n = int(input())

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

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
    else:
        continue

Submission status: Runtime Error

Solution code:
x = int(input())
n = int(input())

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

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

Submission status: Runtime Error

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

ans_enable = [True] * 102
for pi in p:
    ans_enable[pi] = False

diff = 0

check_ok = ans_enable[X]

ans_small = True

while not check_ok:
    diff += 1
    if ans_enable[X - diff]:
        check_ok = True
        ans_small = True
    elif ans_enable[X + diff]:
        check_ok = True
        ans_small = False

print(X - diff if ans_small else X + diff)

Submission status: Runtime Error

Solution code:
x,n=map(int, input().split())
ans=x
judge=True
if(n!=0):
  p=list(map(int, input().split()))
else:
  ans=x
  judge=False

if(judge):
  check=True
  s_list=[]
  l_list=[]
  for i in range(n):
    for j in range(n):
      if(x-i==p[j]):
        check=False
    if(check):
      s_list.append(x-i)
    check=True

    for i in range(n):
      for j in range(n):
        if(x+i==p[j]):
          check=False
      if(check):
        l_list.append(x+i)
      check=True
    if(l_list == [] and s_list == []):
      ans = x-1
    else:
      if(abs(x-min(l_list)) > abs(x-max(s_list))):
        ans = max(s_list)
      elif(abs(x-min(l_list))==abs(x-max(s_list))):
        ans=max(s_list)
      else:
        ans=min(l_list)  

print(ans)

Submission status: Runtime Error

Solution code:
x,n=map(int, input().split())
ans=x
judge=True
if(n!=0):
  p=list(map(int, input().split()))
else:
  ans=x
  judge=False

if(judge):
  check=True
  s_list=[]
  l_list=[]
  for i in range(n):
    for j in range(n):
      if(x-i==p[j]):
        check=False
    if(check):
      s_list.append(x-i)
    check=True

    for i in range(n):
      for j in range(n):
        if(x+i==p[j]):
          check=False
      if(check):
        l_list.append(x+i)
      check=True
    if(l_list == []):
      ans = max(s_list)
    if(s_list == []):
      ans = min(l_list)
    else:
      if(abs(x-min(l_list)) > abs(x-max(s_list))):
        ans = max(s_list)
      elif(abs(x-min(l_list))==abs(x-max(s_list))):
        ans=max(s_list)
      else:
        ans=min(l_list)  

print(ans)

Submission status: Runtime Error

Solution code:
x,n=map(int, input().split())
ans=x
judge=True
if(n!=0):
  p=list(map(int, input().split()))
else:
  ans=x
  judge=False

if(judge):
  check=True
  s_list=[]
  l_list=[]
  for i in range(n):
    for j in range(n):
      if(x-i==p[j]):
        check=False
    if(check):
      s_list.append(x-i)
    check=True

    for i in range(n):
      for j in range(n):
        if(x+i==p[j]):
          check=False
      if(check):
        l_list.append(x+i)
      check=True
    if(l_list != []):
      if(abs(x-min(l_list)) > abs(x-max(s_list))):
        ans = max(s_list)
      elif(abs(x-min(l_list))==abs(x-max(s_list))):
        ans=max(s_list)
      else:
        ans=min(l_list)  

print(ans)

Submission status: Runtime Error

Solution code:
x,n=map(int, input().split())
ans=x
judge=True
if(n!=0):
  p=list(map(int, input().split()))
else:
  ans=x
  judge=False

if(judge):
  check=True
  s_list=[]
  l_list=[]
  for i in range(n):
    for j in range(n):
      if(x-i==p[j]):
        check=False
    if(check):
      s_list.append(x-i)
    check=True
  if(n!=1):
    for i in range(n):
      for j in range(n):
        if(x+i==p[j]):
          check=False
      if(check):
        l_list.append(x+i)
      check=True
    if(abs(x-min(l_list)) > abs(x-max(s_list))):
      ans = max(s_list)
    elif(abs(x-min(l_list))==abs(x-max(s_list))):
      ans=max(s_list)
    else:
      ans=min(l_list)  

print(ans)

Submission status: Runtime Error

Solution code:
x,n=map(int, input().split())
ans=x
judge=True
if(n!=0):
  p=list(map(int, input().split()))
else:
  ans=x
  judge=False

if(judge):
  check=True
  s_list=[]
  l_list=[]
  for i in range(n):
    for j in range(n):
      if(x-i==p[j]):
        check=False
    if(check):
      s_list.append(x-i)
    check=True
  for i in range(n):
    for j in range(n):
      if(x+i==p[j]):
        check=False
    if(check):
      l_list.append(x+i)
    check=True
  if(abs(x-min(l_list)) > abs(x-max(s_list))):
    ans = max(s_list)
  elif(abs(x-min(l_list))==abs(x-max(s_list))):
    ans=max(s_list)
  else:
    ans=min(l_list)

print(ans)

Submission status: Runtime Error

Solution code:
x, n = map(int, input().split())
P = list(map(int, input().split()))
if not P:
    print(x)
	exit(0)
for i in range(x, 102):
    if i not in P:
        upper = i
        break
    else:
        upper = 102
for i in range(x, -1, -1):
    if i not in P:
        lower = i
        break
    else:
        lower = 0
print(lower if x-lower <= upper - x else upper)

Submission status: Runtime Error

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

input_line = input().split()

sabun_list = []
for i in range(len(input_line)):
  sabun = int(input_line[i]) - X
  sabun_list.append(abs(sabun))

print(int(input_line[sabun_list.index(min(sabun_list))]))

Submission status: Runtime Error

Solution code:
x,n=map(int, input().split())
ans=x
judge=True
if(n!=0):
  p=list(map(int, input().split()))
else:
  ans=x
  judge=False

if(judge):
  check=True
  s_list=[]
  l_list=[]
  for i in range(n):
    for j in range(n):
      if(x-i==p[j]):
        check=False
    if(check):
      s_list.append(x-i)
    check=True

  for i in range(n):
    for j in range(n):
      if(x+i==p[j]):
        check=False
    if(check):
      l_list.append(x+i)
    check=True
  if(abs(x-min(l_list)) > abs(x-max(s_list))):
    ans = max(s_list)
  elif(abs(x-min(l_list))==abs(x-max(s_list))):
    ans=max(s_list)
  else:
    ans=min(l_list)
  
print(ans)

Submission status: Runtime Error

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

    if n == 0:
        return x
    
    if n == 100:
        return 0
    
    for i in range(x,maxx):
        if not i in l:
            u = i
            #dic.setdefault(i,abs(i-x))
            break
    
    for i in range(x,minx,-1):
        if not i in l:
            d = i
            #dic.setdefault(i,abs(x-i))
            break
    
    if abs(x-u) == abs(x-d):
        return min(u,d)
    elif abs(x-u) < abs(x-d):
        return u
    else:
        return d

u=999
d=999
minx = 1-1
maxx = 100+1

ans = workC()
print(ans)

Submission status: Runtime Error

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

    if n == 0:
        return x
    
    if n == 100:
        return 0
    
    for i in range(x,maxx):
        if not i in l:
            u = i
            #dic.setdefault(i,abs(i-x))
            break
    
    for i in range(x,minx,-1):
        if not i in l:
            d = i
            #dic.setdefault(i,abs(x-i))
            break
    
    if abs(x-u) == abs(x-d):
        return min(u,d)
    elif abs(x-u) < abs(x-d):
        return u
    else:
        return d

ans = workC()
print(ans)

Submission status: Runtime Error

Solution code:
a=input()
a=a.split()
x=int(a[0])
p=input()
p=p.split()

i=0
p_1=p+[]



for y in p_1:
  p_1[i]=abs(int(p_1[i])-x)
  i=i+1

p_1.sort()
if p_1[0]==0:
  del p_1[0]

q=p_1[0]
if str(x-q) in p:
  print(x-q)
else:
  print(x+q)

Submission status: Runtime Error

Solution code:
import sys

def Forbidden_List(x,n,p):
  k = [abs(s - x) for s in p]
  for i in range(n):
    if i not in k: 
      return 10 - i
  return 10 - n

if __name__ == '__main__':
    input = sys.stdin.readline
    
    inp1 = input().rstrip().split()
    x,n = int(inp1[0]),int(inp1[1])
    if n == 0:
        print(x)
    else: 
     	inp2 = input().rstrip().split()
       	p = list(map(int,inp2))

        print(Forbidden_List(x,n,p))

Submission status: Runtime Error

Solution code:
 import sys
  
def Forbidden_List(x,n,p):
  k = [abs(s - x) for s in p]
  for i in range(n):
    if i not in k: 
      return 10 - i
  return 10 - n
 
if __name__ == '__main__':
    input = sys.stdin.readline
    
    inp1 = input().rstrip().split()
    inp2 = input().rstrip().split()
    
    x,n = int(inp1[0]),int(inp1[1])
    if n == 0:
        print(x)
    else:
        p = list(map(int,inp2))
 
        print(Forbidden_List(x,n,p))

Submission status: Runtime Error

Solution code:
import bisect
X,N=map(int,input().split())
P=list(map(int,input().split()))
hako=set(P)
kari=[]
if X<P[0]:
    print(X)
    exit()
if X>P[-1]:
    print(X)
    exit()
for i in range(102):
    if i not in hako:
        kari.append(i)
#print(kari)
kari.sort()
tekitpu=kari[bisect.bisect_left(kari,X)]
aho=kari[bisect.bisect_left(kari,X)-1]
#print(tekitpu,aho)
if abs(tekitpu-X)<abs(X-aho):
    print(tekitpu)
else:
    print(aho)

Submission status: Runtime Error

Solution code:
X, N = map(int, input().split())
A = [map(int, input().split())]
a = 0
while True:
  if X-a in A:
    if X+a in A:
    a += 1
    else:
      print(X+a)
      break
  else:
    print(X-a)
    break

Submission status: Runtime Error

Solution code:
import bisect
X,N=map(int,input().split())
P=list(map(int,input().split()))
P=set(P)
A=[]
for i in range(101):
    if i not in P:
        A.append(i)
zahyo=bisect.bisect_left(A,X)
ans=[]
ans.append([abs(X-A[zahyo]),A[zahyo]])
ans.append([abs(X-A[zahyo-1]),A[zahyo-1]])
ans.sort()
print(ans[0][1])

Submission status: Runtime Error

Solution code:
X, N = map(int, input().split())
A = [map(int, input().split())]
a = 0
while True:
  if X-a in A:
    if X+a in A:
    a +=1
    else:
      print(X+a)
      exit()
  else:
    print(X-a)
    exit()

Submission status: Runtime Error

Solution code:
X, N = map(int, input().split())
A = [int(input()) for i in range(N)]
a = 0
while True:
  if X-a in A:
    if X+a in A:
    a +=1
    else:
      print(X+a)
      exit()
  else:
    print(X-a)
    exit()

Submission status: Runtime Error

Solution code:
lst = []
check = False
loop = 1
final = 0
x, n = map(int, input().split())
for i in range(n):
    element = int(input())
    lst.append(element)

while check == False:
    if x not in lst:
        final = x
        check = True
    elif (x+loop) not in lst:
        final = (x+loop)
        check = True
    elif (x-loop) not in lst:
        final = (x-loop)
        check = True
    else:
        loop+=1

print(final)

Submission status: Runtime Error

Solution code:
import numpy as np
import sys

x, n  = [int(i) for i in input().split()]

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

p = []
[p.append(int(i)) for i in input().split()]
max_list = list(range(1, max(p)+ 1))

list_calc = (list(set(max_list) - set(p)))


def getNearestValue(list, num):
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]

print(getNearestValue(list_calc, x))

Submission status: Runtime Error

Solution code:
x, n = map(int, input().split())
if n == 0:
    print(x)
else:
    p = list(map(int, input().split()))
    a = set(range(1, 200))
    b = list(a - set(p))
    c = [abs(i - x) for i in b]
    import numpy as np
    pos = np.argmin(c)
    print(min([b[y] for y in c if y == pos]))

Submission status: Runtime Error

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

if p:
    x = [i for i in range(1, max(p)) if i not in p]

    c = x.pop()
    a = abs(c - X)
    for i in x:
        if abs(i - X) < a:
            c = i
    print(c)
else:
    print(X)

Submission status: Runtime Error

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

lp.sort()

distance = 0
try:
    idx = lp.index(x)
    while True:
        distance += 1
        dmin = x-distance
        dmax = x+distance
        if dmin != lp[idx-distance]:
            print(dmin)
            exit()
        if dmax != lp[idx+distance]:
            print(dmax)
            exit()
except ValueError:
    print(x)
    exit()

Submission status: Runtime Error

Solution code:
x, n = map(int, input().split())
a = set(map(int, input().split()))
print(min(i for i in range(102) if i not in a, key=lambda y:abs(x-y)))

Submission status: Runtime Error

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

if n==0:
  print(x)
  import sys
  sys.exit()
  
P = list(map(int, input().split()))
P.sort()
notP = [i for i in range(1, 101) if i not in P]

ans = notP[0]
min_delta = abs(x - ans)

for p in notP:
  delta = abs(x - p)
  if delta<min_delta:
    ans = p
    min_delta = abs(x - ans)
    
print(ans)

Submission status: Runtime Error

Solution code:
x, n = map(int, input().split())
P = list(map(int, input().split()))
P.sort()
notP = [i for i in range(1, 101) if i not in P]

ans = notP[0]
min_delta = abs(x - ans)

for p in notP:
  delta = abs(x - p)
  if delta<min_delta:
    ans = p
    min_delta = abs(x - ans)
    
print(ans)

Submission status: Runtime Error

Solution code:
x, n = map(int, input().split())
P = list(map(int, input().split()))
P.sort()
notP = [i for i in range(1, 101) if i not in P]

ans = notP[0]
for p in notP:
  delta = abs(x - p)
  if delta<ans:
    ans = p
    
print(ans)

Submission status: Runtime Error

Solution code:
import sys

X, N = map(int, input().split())
P = list(map(int, input().split()))
NL = [i for i in range(-1000,1000) if i == X or i not in P]

if len(P) == 0:
    print(X)
    sys.exit()

idx = NL.index(X)
if abs(NL[idx + 1]) - X >= abs(NL[idx - 1]) - X ):
    print(NL[idx - 1])
else:
    print(NL[idx + 1])

Submission status: Runtime Error

Solution code:
x, n = list(map(int, input().split()))
if not n:
  print(x) 
else:
  l = list(map(int, input().split()))
  dic = {} 
  for ll in l: dic[ll] = 1
  i = 0
  while true:
    if not dic.get(x-i,0):
      print(x-i)
      break
    elif not dic.get(x+i, 0):
      print(x+i) 
      break
    i+=1

Submission status: Runtime Error

Solution code:
x, n = list(map(int, input().split()))
if not n:
  print(x) 
else:
  l = list(map(int, input().split()))
  dic = {} 
  for ll in l: dic[ll] = 1
  i = 1
  while true:
    if not dic.get(x-i,0):
      print(x-i)
      break
    elif not dic.get(x+i, 0):
      print(x+i) 
      break
    i+=1

Submission status: Runtime Error

Solution code:
x, n = list(map(int, input().split()))
if not n:
  print(x) 
else:
  l = list(map(int, input().split()))
  dic = {} 
  for ll in l: dic[l] = 1
  i = 1
  while true:
    if not dic.get(x-i,0):
      print(x-i)
      break
    elif not dic.get(x+i, 0):
      print(x+i) 
      break
    i+=1

Submission status: Runtime Error

Solution code:
x,n=map(int,input().split())
r=[i-x for i in map(int,input())]
for i in range(100):
  if not -(i+1) in r:
    print(x-i-1)
    break
  elif not i+1 in r:
    print(x+i+1)
    break

Submission status: Runtime Error

Solution code:
x,n=map(int,input().split())
r=[i-x for i in map(int,input())]
for i in range(100):
  if not -(i+1) in r:
    print(x-i)
  elif not (i+1) in r:
    print(x+i)

Submission status: Runtime Error

Solution code:
x,n=map(int,input().split())
r=[i-x for i in map(int,input())]
for i in range(100):
  if not -i in r:
    print(x-i)
  elif not i in r:
    print(x+i)

Submission status: Runtime Error

Solution code:
x,n=map(int,input().split())
r=[i-x for i in map(int,input())]
i=1
while True:
  if not -i in r:
    print(x-i)
    break
  elif not i in r:
    print(x+i)
  else:
    i+=1

Submission status: Runtime Error

Solution code:
from sys import stdin
 
input_num = stdin.readline().strip().split(" ")

X = int(input_num[0])
N = int(input_num[1])
num_list = [int(x) for x in stdin.readline().strip().split(" ")]

dec_num = X
inc_num = X
if N == 0:
    print(X)
elif X not in num_list:
    print(X)
else:
    while True:
        dec_num += -1
        inc_num += 1
        if dec_num not in num_list:
            print(dec_num)
            break
        if inc_num not in num_list:
            print(inc_num)
            break

Submission status: Runtime Error

Solution code:
from sys import stdin
 
input_num = stdin.readline().strip().split(" ")

X = int(input_num[0])
N = int(input_num[1])
num_list = [int(x) for x in stdin.readline().strip().split(" ")]

minv = 10000
num = 0

if N == 0:
  print(X)
else:
  for i in range(len(num_list)):
    if minv > abs(X - num_list[i]):
      minv = abs(X - num_list[i])
      num = i
  print(num_list[num])

Submission status: Runtime Error

Solution code:
from sys import stdin
 
input_num = stdin.readline().strip().split(" ")

X = int(input_num[0])
N = int(input_num[1])
num_list = [int(x) for x in stdin.readline().strip().split(" ")]

minv = 10000
num = 0

if N == 0:
  print(X)
else:
  for i in range(len(num_list)):
    if minv > abs(X - num_list[i]):
      minv = abs(X - num_list[i])
      num = i
  print(num)

Submission status: Runtime Error

Solution code:
from sys import stdin
 
input_num = stdin.readline().strip().split(" ")

X = int(input_num[0])
N = int(input_num[1])
num_list = stdin.readline().strip().split(" ")

minv = 10000
num = 0

if N == 0:
  print(X)
else:
  for i in range(len(num_list)):
    if minv > abs(X - num_list[i]):
      minv = abs(X - num_list[i])
      num = i
  print(num)

Submission status: Runtime Error

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

def main(X, N):
    if N == 0:
        return X
    arrp = [int(x) for x in input().split()]
    b = sorted(arrp)
    lists = []
    for x in range(1, 101):
        if x not in arrp:
            a = abs(X-x)
            if a != 0:
                lists.append([a, x])
    return sorted(lists)[0][1]

print(main(X, N))

Submission status: Runtime Error

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


def main(X,N):
    if N == 0:
        return X
    arrp = [int(x) for x in input().split()]
    b = sorted(arrp)
    lists = []
    for x in range(b[0],b[-1]):
        if x not in arrp:
            a = abs(X-x)
            lists.append([a,x])
    return sorted(lists)[0][1]

print(main(X,N))

Submission status: Runtime Error

Solution code:
import numpy as np


def main():
  x, n = map(int, input().split())
  p = np.array(tuple(int(_) for _ in input().split()))
  
  answer = p[np.argmin(np.abs(p - x))]
  print(answer)


main()

Submission status: Runtime Error

Solution code:
lst = []
l = []
str = input()
l = str.split(' ')
n = int(l[0])
no = int(l[1])
if no==0:
  print(n)
 

else:  
  str1 = input()
  lst = str1.split(' ')
  for i in range(0,no):
    lst[i] = int(lst[i])
  i=1
  while:
    if n-i not in lst:
      print(n-i)
      break
    if n+i not in lst:
      print(n+i)
      break
    i+=1

Submission status: Runtime Error

Solution code:
a,b = map(int, input().split())
if b>0:
	p = list(map(int, input().split()))
else:
	print(a)
	exit()

n = a
m = a

for i in range(b):
	print(n)
	print(m)
	print("")
	if n in p:	a,b = map(int, input().split())
if b>0:
	p = list(map(int, input().split()))
else:
	print(a)
	exit()

n = a
m = a

for i in range(b):
	if n in p:	
		n = n-1
			
	else:
		if n < 1:
			continue
		print(n)
		exit()

	if m in p:		
		m = m+1
	else:
		print(m)
		exit()


	
		n = n-1
		if n < 1:
			n = 1
	else:
		print(n)
		exit()

	if m in p:		
		m = m+1
	else:
		print(m)
		exit()

Submission status: Runtime Error

Solution code:
x, t = map(int, input().split())
data = list(map(int, input().split()))
data.sort()
if t == 0:
  print(x)
else:
  s = 1000
  for i in data:
    tmp = abs(i-x)
    if tmp != 0 and tmp < s:
      s = tmp
      ans = i
    elif s < tmp:
      break
  print(ans)

Submission status: Runtime Error

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

num = list(range(1,101))
nums = []
for i in num:
  if not(i in p):
    nums.append(i)
#print(nums)
p2 = [abs(nums[i]-x) for i in range(len(nums))]
p2min = min(p2)
for i in range(len(p2)):
  if p2[i] == p2min:
    print(nums[i])
    exit()

Submission status: Runtime Error

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

for i in range(1, 101)[::-1]:
    if abs(x - i) <= min:
        if i not in p:
            min = abs(x - i)
            ans = i

print(ans)

Submission status: Runtime Error

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
l = []
min = float('inf')

for i in range(1, 101)[::-1]:
    if abs(x - i) < min:
        if i not in p:
            min = abs(x - i)
            ans = i

print(ans)

Submission status: Runtime Error

Solution code:
x = list(map(int, input().split()))
l = list(map(int, input().split()))
if x[1] == 0:
  print(x[0])
else:
  l1 = []
  for i in range(1,x[1]+1):
    y = x[0]+1
    y2 = x[0]-1
    if y not in l:
      l1.append(y)
      
    if y2>0 and y2 not in l:
      l1.append(y2)
  print(min(l1))

Submission status: Runtime Error

Solution code:
x = list(map(int, input().split()))
l = list(map(int, input().split()))
l1 = []
for i in range(1,x[1]+1):
  y = x[0]+1
  y2 = x[0]-1
  if y not in l:
    l1.append(y)
    
  if y2>0 and y2 not in l:
    l1.append(y2)
print(min(l1))

Submission status: Runtime Error

Solution code:
x = list(map(int, input().split()))
l = list(map(int, input().split()))
for i in range(1,x[1]+1):
  y = x[0]+1
  y2 = x[0]-1
  if y is not in l:
    print(y)
    break
  elif y2>0 and y2 is not in l:
    print(y2)
    break

Submission status: Runtime Error

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

if(X not in p):
    print(X)
else:
    while True:
        if(X-dif not in p):
            dif = dif*(-1)
            break
        elif(X+dif not in p):
            break
        else:
            dif=dif+1
      print(X+dif)

Submission status: Runtime Error

Solution code:
import numpy as np

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

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

num_list = list(set([*range(1,101)]) - set(p_list))

diff = np.abs(np.array(num_list)-X)
diff_arg_min = np.argmin(diff)

print(num_list[diff_arg_min])

Submission status: Runtime Error

Solution code:
import numpy as np

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

num_list = list(set([*range(1,101)]) - set(p_list))

diff = np.abs(np.array(num_list)-X)
diff_arg_min = np.argmin(diff)

print(num_list[diff_arg_min])

Submission status: Runtime Error

Solution code:
X,N = input().split(' ')
x =int(X)
n = int(N)
try:
    kara_int = list(map(int,input().split(' ')))
except ValueError:
    print(X)
except EOFError:
    print(X)


for s in range(200):
    if x+s not in kara_int or x-s not in kara_int:
        if x-s in kara_int:
            print(str(x+s))
        else:
            print(str(x-s))
        break

Submission status: Runtime Error

Solution code:
x, y = map(int, input().split())
p = list(map(int, input().split()))
if len(p) != 0:
    max = max(p)
    nums =  []
    nums2 = []

    for i in range(1, max+1):
        if p.count(i):
            continue
        else:
            nums.append(abs(x-i))
            nums2.append(i)
    else:
        min = nums.index(min(nums))
        print(nums2[min])
else:
    print(x)

Submission status: Runtime Error

Solution code:
x,y=map(int,input().split())
a=list(map(int,input().split()))
a=set(a)
for i in range(101):
  
  if x-i not in a:
        print(x-i)
        exit()
    elif x+i not in a:
        print(x+i)
        exit()

Submission status: Runtime Error

Solution code:
x,n = map(int,input()split())
p = list(map(int,input().split()))
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: Runtime Error

Solution code:
x,n = map(int,input()split())
p = lsit(map(int,input().split()))
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: Runtime Error

Solution code:

import copy
n = int(input())
list_a = list(map(int, input().split()))  #リスト入力

list_a = list(set(list_a))
list_a.sort(reverse=True)
# print(list_a)

count = 0
if len(list_a) == 1:
    print(0)
else:
    for i in range(len(list_a)):
        ai = list_a[i] 
        new_list = list_a[i+1:]  #  全くの別物としてコピー
#         print(new_list)
        data2 = []
        booler = True
        for j in range(len(new_list)):
            aj = new_list[-j]
#             print(ai, aj, ai%aj)
            if ai % aj == 0:

                booler = False
                break
        if booler == True:
            count += 1


    print(count)

Submission status: Runtime Error

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

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


l = list(range(0,102)) #ここの範囲設定が一番難しい部分だと思う
flist = []
for i in range(len(l)):
    if p.count(l[i]) == 0:
        flist.append(l[i])


flist.append(X)
anslist = sorted(flist)
t = anslist.index(X)

dist1 = anslist[t] - anslist[t-1] #Xと1つ前の数字との距離
dist2 = anslist[t+1] - anslist[t] #Xと1つ後ろの数字との距離
    if dist1 <= dist2:
        print(anslist[t-1])
    else:
        print(anslist[t+1])

Submission status: Runtime Error

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

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


l = list(range(0,102)) #ここの範囲設定が一番難しい部分だと思う
flist = []
for i in range(len(l)):
    if p.count(l[i]) == 0:
        flist.append(l[i])


flist.append(X)
anslist = sorted(flist)
t = anslist.index(X)

dist1 = anslist[t] - anslist[t-1] #Xと1つ前の数字との距離
dist2 = anslist[t+1] - anslist[t]) #Xと1つ後ろの数字との距離
    if dist1 <= dist2:
        print(anslist[t-1])
    else:
        print(anslist[t+1])

Submission status: Runtime Error

Solution code:
x, y = map(int, input().split())
p = list(map(int, input().split()))
if p:
    max = max(p)
    nums =  []
    nums2 = []

    for i in range(1, max+1):
        if p.count(i):
            continue
        else:
            nums.append(abs(x-i))
            nums2.append(i)
    else:
        min = nums.index(min(nums))
        print(nums2[min])
else:
    print(x)

Submission status: Runtime Error

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

ls.sort()
start = ls[0]
size = len(ls)
end = ls[size - 1]
s = [i for i in range(start, end+1)]

not_ls = set(s) - set(ls)

not_ls = list(not_ls)
not_ls.sort(reverse=True)


ans = 999
num = 999
for i in not_ls:
  if abs(X - i) <= num:
    num = abs(X - i)
    ans = i

print(ans)

Submission status: Runtime Error

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

ls.sort()
s = [i for i in range(ls[0],ls[len(ls)-1])]

not_ls = set(s) - set(ls)

not_ls = list(not_ls)
not_ls.sort(reverse=True)


ans = 999
num = 999
for i in not_ls:
  if abs(X - i) <= num:
    num = abs(X - i)
    ans = i

print(ans)

Submission status: Runtime Error

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

ans = 0
for i in range(1, 102):
  if i in p:
    continue
  if i < x:
    ans = i
  elif x - ans > i - x:
  	ans = i
    break
print(ans)

Submission status: Runtime Error

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

ans = 0
for i in range(1, 102):
  if i in p:
    continue
  if i < x:
    ans = i
  elif x - ans > i - x
  	ans = i
    break
print(ans)

Submission status: Runtime Error

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

a.sort()

M = 1000005
cnt = [0] * M

for i in range(n):
    if cnt[a[i]] != 0:
        cnt[a[i]] = 2
        continue
    for j in range(a[i], M, a[i]):
        cnt[j] += 1

ans = 0

for i in range(n):
    if cnt[a[i]] == 1:
        ans += 1

print(ans)