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:
x,n = map(int,input().split())

if n==0:
    print(x)
else:
    a = list(map(int,input().split()))
    lower = min(a)
    upper = max(a)
    mini = 10000005
    res = -1
    for i in range(lower-1,upper+2):
        if i not in a:
            if abs(x-i)<mini:
                mini = abs(x-i)
                res = i

    print(res)

Submission status: Accepted

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

s =True
while s:
    if (x-i) not in lst:
        print(x-i)
        s = False
    elif (x+i) not in lst:
        print(x+i)
        s = False
    else:
        i += 1

Submission status: Accepted

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

for i in range(x[1]+1):
    for j in [-1,1]:
        if set() == {x[0]+j*i}&y:
            print(x[0]+j*i)
            sys.exit()

Submission status: Accepted

Solution code:
def main():
    x, n = map(int, input().split())
    p = set(map(int, input().split()))
    if not x in p:
        print(x)
    else:
        a = [abs(x-i) if not i in p else 1000 for i in range(-1, 102)]
        print(a.index(min(a))-1)
 
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = set(map(int, input().split()))
if not x in p:
  print(x)
else:
  a = [abs(x-i) if not i in p else 1000 for i in range(-1, 102)]
  print(a.index(min(a))-1)

Submission status: Accepted

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

for i in range(110):
  if i in p:
    S.append(100)
  else:
    S.append(abs(i-X))
 
print(S.index(min(S)))

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
np =[0]*102 

for i in p:
    np[i] = 1

dist = 1000
ans = 1000
for i in reversed(range(102)):
    if np[i] == 0:
        if abs(x-i) <= dist:
            dist = abs(x-i)
            ans = i
    
print(ans)

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
ps = list(map(int, input().split()))
s = set(range(0, 101+1))-set(ps)
m = min([abs(p-X) for p in s])
if X-m in s:
  r = X-m
else:
  r = X+m
print(r)

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
lst = [int(x) for x in input().split()]
if N == 0 or X not in lst:
    print(X)
else:
    i = 1
    while True:
        if X - i not in lst:
            print(X - i)
            exit()
        elif X + i not in lst:
            print(X + i)
            exit()
        i += 1

Submission status: Accepted

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

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

ans_l = X
ans_h = X
h_s = 0
l_s = 0

while True:
    if l_s == 0 and ans_l not in P:
        print(ans_l)
        break
    else:
        ans_l -= 1
    
    if ans_h not in P:
        print(ans_h)
        break
    else:
        ans_h += 1
        
    if ans_h > 100:
        h_s = 1
    
    if ans_l < 0:
        l_s = 1
    
    if l_s and h_s == 1:
        break

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect


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


def z():
    return int(input())


def S():
    return input()


def C(line):
    return [input() for _ in range(line)]


X, N = zz()
p = zz()
small_x = X
big_x = X
if (X not in p):
    print(X)
    exit()

while True:
    # for v in [-1, 1]:
    if (small_x - 1 not in p):
        print(small_x-1)
        exit()
    if (big_x + 1 not in p):
        print(big_x+1)
        exit()
    small_x -= 1
    big_x += 1

Submission status: Accepted

Solution code:
def main():
    x, n = map(int, input().split())
    p = set([int(v) for v in input().split()])
    ans = 0
    for i in range(1, 102):
        if i in p:
            continue
        if abs(x - i) < abs(x - ans):
            ans = i
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
for base in range(x+1):
    if p.count(x+base*-1) == 0:
        print(x+base*-1)
        break
    if p.count(x+base) == 0:
        print(x+base)
        break

Submission status: Accepted

Solution code:
import operator

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

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

abs_val_dict = {}

if N == 0:
    print (X)

for i in range (X-N, X+N):
    if i not in p:
        abs_val_dict[i] = abs(i-X)

if abs_val_dict != {}:
    print(min(abs_val_dict.items(), key=operator.itemgetter(1))[0])

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 6)  # 再帰関数の再帰の深さを設定
to_index = lambda x: int(x) - 1  # 入力した数字に1を引いたものを返す
print_list_in_2D = lambda x: print(*x, sep="\n")  # リストの要素を改行を挟んで表示する関数

# 入力を整数に変換して受け取る
def input_int():
    return int(input())

def map_int_input():
    return map(int, input())

MII = map_int_input

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

def MII_to_index():
    return map(to_index, input())

def MII_split_to_index():
    return map(to_index, input().split())

# 入力全てを整数に変換したものの配列を受け取る
def list_int_inputs():
    return list(map(int, input()))

LII = list_int_inputs

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

# 2次元リスト化
def LII_2D(rows_number):
    return [LII() for _ in range(rows_number)]

def LII_split_2D(rows_number):
    return [LII_split() for _ in range(rows_number)]

X, N = MII_split()
if N==0:
    print(X)
    exit()
ps = LII_split()

# diss = map(lambda x: abs(X - x), ps)
# min_dis = min(diss)

for dis in range(105):
    if X - dis not in ps:
        ans = X - dis
        break
    elif X + dis not in ps:
        ans = X + dis
        break
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(' ')))

if not X in p:
    print(X)
    sys.exit()

for i in range(1, 101):
    if not X - i in p:
        print(X - i)
        sys.exit()

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 **5)

# sys.stdin = open('input.txt', 'r')
# sys.stdout = open('output.txt', 'w')

readline = sys.stdin.readline

def proc():
    x,n = map(int, readline().rstrip().split())
    a = list(map(int, readline().rstrip().split()))
    hash_map = {}
    for i in a:
        hash_map[i] = True
    
    if not n or x not in hash_map:
        return x
    
    
    p,q = x-1, x+1
    while 1:
        if p not in hash_map and q not in hash_map:
            return p
        elif p not in hash_map:
            return p
        elif q not in hash_map:
            return q
        
        p-=1
        q+=1
    

#for _ in range(int(readline())):
print(proc())

Submission status: Accepted

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

check = 1000000
ans = 0

N = list(range(102))

for i in range(1, 101):
    if i in p:
        N.remove(i)

for i in range(len(N)):
    if check > abs(N[i]-x):
        check = abs(N[i]-x)
        ans = N[i]
print(ans)

Submission status: Accepted

Solution code:


def submit():
    x, n = map(int, input().split())
    p = set(map(int, input().split()))

    ans = -1
    ans_d = 10000
    for c in range(102):
        if c in p:
            continue

        if abs(x - c) < ans_d:
            ans_d = abs(x - c)
            ans = c
    
    print(ans)
    

if __name__ == "__main__":
    submit()

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
p=list(map(int,input().split()))
 
for d in range(x+1):
    for s in [-1,+1]:
        a=x+s*d
        if p.count(a) == 0:
            print(a)
            exit()

Submission status: Accepted

Solution code:
import sys

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

for d in range(X + 1):
    for s in [-1, +1]:
        a = X + s * d
        if p.count(a) == 0:
            print(a)
            sys.exit(0)

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
p = list(map(int,input().split()))
p.sort()
for i in range(n):
    p[i] -= x

idx = -1
for i in range(n):
    if p[i] == 0:
        idx = i
if idx == -1:
    print(x)
    exit()
sa = 1
while 1:
    if idx-sa<0:
        print(x-sa)
        exit()
    if p[idx-sa] != -sa:
        print(x -sa)
        exit()
    if idx+sa>n-1:
        print(x+sa)
        exit()
    elif p[idx+sa] != sa:
        print(x+sa)
        exit()
    sa +=1

Submission status: Accepted

Solution code:
def main():
    x, n = map(int, input().split())
    p = set(map(int, input().split()))
    if not x in p:
        print(x)
    else:
        a = [abs(x-i) if not i in p else 1000 for i in range(-1, 102)]
        print(a.index(min(a))-1)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

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):
    if x-i not in p:
        print(-i+x)
        sys.exit()
    if x+i not in p:
        print(x+i)
        sys.exit()

Submission status: Accepted

Solution code:
from math import*
x,n=map(int,input().split())
arr=list(map(int,input().split()))
if len(arr)==0:
	print(x)
else:
	arr.sort()
	i=arr[0]-1
	dif=[]
	abdif=[]
	while i<arr[-1]+2:
		if i not in arr:
			dif.append(x-i)
			abdif.append(int(fabs(x-i)))
		i+=1
	#print(dif)
	#print(abdif)
	ans=[]
	for i in range(len(abdif)):
		if abdif[i]==min(abdif):	
			if dif[i]>=0:
				ans.append(x-dif[i])
			else:
				ans.append(x-dif[i])
	#print(ans)
	print(min(ans))

Submission status: Accepted

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


def func(near):
    if near not in p_list:
        print(near)
        quit()


while(True):
    near = X - abs_num
    func(near)
    near = X + abs_num
    func(near)
    abs_num += 1

Submission status: Accepted

Solution code:
input=[input().split() for i in range(2)]
num=int(input[0][0])
length=int(input[0][1])
list=[]
for i in range(length):
    list.append(int(input[1][i]))
i=0
flg=True
while (flg):
    ret=num-i
    flg=ret in list
    if(flg):
        ret=num+i
        flg=ret in list
        if(flg):
            i=i+1
        else:
            print(ret)
    else:
        print(ret)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x,m = map(int,input().split())
a = list(map(int,input().split()))
for i in range(x+1):
    for s in [-1,1]:
        b = x+i*s
        if a.count(b) == 0:
            print(b)
            exit()

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
p=sorted(map(int,input().split()))
t={}
y=[(i>>1)*(1 if i&1 else -1)+x for i in range(1000)]
for i in range(-200,200):
    t[i]=True
for i in p:
    t[i]=False
for i in y:
    if t[i]:
        print(i)
        break

Submission status: Accepted

Solution code:
x,n = [int(i) for i in input().split()]
l = [int(i) for i in input().split()]

for i in range(x+1):
    for j in [-1,1]:
        y = x + j * i
        if y in l:
            pass
        else:
            print(y)
            exit()

Submission status: Accepted

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

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

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: Accepted

Solution code:
import numpy as np
import sys

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

def search_list(x, p):
    flag = False
    for ii in range(len(p)):
        if p[ii]==x:
            flag = True
    return flag

if not search_list(X, p):
    print(X)
    sys.exit()

X_small = X
diff_small = 0

while search_list(X_small, p):
    X_small -= 1
diff_small = abs(X-X_small)

X_big = X
diff_big = 0

while search_list(X_big, p):
    X_big += 1
diff_big = abs(X-X_big)

if diff_small<=diff_big:
    print(X_small)
else:
    print(X_big)

Submission status: Accepted

Solution code:
import sys
import time
st = time.perf_counter()
# ------------------------------

def main():
    x, n = map(int, input().split())
    if n == 0:
        print(x)
        return
    pn = list(map(int, input().split()))
    if x not in pn:
        print(x)
        return
    for i in range(1, 1001001001):
        ls = []
        if x - i not in pn:
            ls.append(x-i)
        if x + i not in pn:
            ls.append(x+i)
        if ls:
            print(min(ls))
            return

main()
    
# ------------------------------
ed = time.perf_counter()
print('time:', ed-st, file=sys.stderr)

Submission status: Accepted

Solution code:
import numpy as np
import sys

x, n = map(int, input().split())
if(n==0):
  print(x)
  sys.exit()
c = 0
b = 0
p = list(map(int, input().split()))
for i in range(102):
  for j in range(n):
    if(p[j] - x + i == 0):
      c+=1
    if(p[j] - x - i==0):
      b+=1
  if(b==0 or c==0):
    if(c==0):
      print(x-i)
      sys.exit()
    else:
      print(x+i)
      sys.exit()
  else:
    b=0
    c=0

Submission status: Accepted

Solution code:
X,N=map(int,input().split())
if N==0:
    print(X)
    exit()
s=set(map(int,input().split()))
ans=10**9
for i in range(101):
    if not X-i in s:
        print(X-i)
        exit()
    if not X+i in s:
        print(X+i)
        exit()

Submission status: Accepted

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


l,r = x,x
while True:
  if l not in p:
    print(l)
    exit()
  elif r not in p:
    print(r)
    exit()

  l-=1
  r+=1

Submission status: Accepted

Solution code:
#! env python
# -*- coding: utf-8 -*-

import os
import sys


# atcoder.main
# Date: 2020/06/18
# Filename: main 
# Author: acto_mini

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

    if not X in P:
        print(X)
        exit()

    min_num = 0
    min_dist = 101
    P.sort()
    for i in range(0, 102):
        if i in P: continue

        dist = abs(X - i)

        if dist < min_dist:
            min_dist = dist
            min_num = i

    print(min_num)

    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
a,b= map(int, input().split())
if(b==0):
    print(a)
else:
    L=list(map(int,input().split(" ")))
    if(a not in L):
       print(a)
    else:
       i=int(1)
       while(True):
          if((a-i) not in L):
             print(a-i)
             break
          elif((a+i) not in L):
             print(a+i)
             break
          i+=1

Submission status: Accepted

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

if(n == 0):
    print(x)
else:
    p_str_list = input().split()
    p_int_list = [int(x) for x in p_str_list]

    flg = True
    abs_count = 0
    answer = 0
    while(flg):
        search_n_minus = x - abs_count
        search_n_plus = x + abs_count
        if(search_n_minus in p_int_list):
            if(search_n_plus in p_int_list):
                abs_count += 1
            else:
                answer = search_n_plus
                break
        else:
            answer = search_n_minus
            break
    print(answer)

Submission status: Accepted

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

ans = -1
dmin=100
for i in range(102):
    if i in Ps:
        continue
    if abs(i-X) < dmin:
        ans =i
        dmin = abs(i-X)
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(101):
    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())
if N == 0:
    print(X)
else:
    L = list(map(int,input().split()))
    for i in range(100):
        if X - i not in L:
            print(X-i)
            break
        elif X + i not in L:
            print(X+i)
            break

Submission status: Accepted

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

Submission status: Accepted

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


for i in range(100):
    if n-i not in l:
        print(n-i)
        break
    if n+i not in l:
        print(n+i)
        break

Submission status: Accepted

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

answer = -1
for i in range(max(x - n, 0), x + n + 1):
    if i in li_p:
        continue
    if abs(answer - x) > abs(i - x):
        answer = i
print(answer)

Submission status: Accepted

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)
        break
    elif (X + i) not in p:
        print(X + i)
        break

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
a = list(map(int, input().split()))
ans = 1
min_diff = float('inf')
for i in range(0, 102):
    if i in a:
        continue
    if (abs(i - X) < min_diff) or (abs(i - X) == min_diff and i < ans):
        min_diff = abs(i - X)
        ans = i
print(ans)

Submission status: Accepted

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

if N == 0:
  ans = X
else:
  p = list(map(int, input().split()))
  ans = 0
  for i in range(200):
    if i in p:
      continue
    else:
      dis = abs(i - X)
      if dis < abs(ans - X):
        ans = i

print(ans)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = {*map(int, input().split())}

ans = 1000
diff = 1000
for i in range(102):
  if i in p:
    continue
  if abs(x - i) < diff:
    diff = abs(x - i)
    ans = i
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()))
    min=1000000000000000
    ans=0
    for i in range(102):
        if i not in p and abs(x-i) < min:
            min = abs(x-i)
            ans = i
    print(ans)

Submission status: Accepted

Solution code:
str1 = input()
lst1 = str1.split()
x = int(lst1[0])
n = int(lst1[1])

string = input()
list = string.split()
p = []
for num in list:
    p.append(int(num))

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: Accepted

Solution code:
X, N = map(int, input().split())
p = list(map(int, 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: Accepted

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

for i in range(102):
    if i not in p:
        lst.append(abs(x- i))
d = min(lst)
l = x-d
u = x+d
if l not in p:
    print(l)
else:
    print(u)

Submission status: Accepted

Solution code:
import numpy as np


def getNearestValue(list, num):
    """
    概要: リストからある値に最も近い値を返却する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]


X, Y = map(int, input().split())
list = list(map(int, input().split()))
list = sorted(list)


listHandred = []
for i in range(0,102):
    listHandred.append(i)
    
ansList = listHandred

for i in list:
    if i in ansList:
        ansList.remove(i)

print(getNearestValue(ansList,X))

Submission status: Accepted

Solution code:
def solve():
	X, N = map(int, input().split())
	arr = set(map(int, input().split()))
	if X not in arr:
		return X
	i = X - 1
	j = X + 1
	while True:
		if i not in arr:
			return i
		else:
			i -= 1
		if j not in arr:
			return j
		else:
			j += 1
		


def main():
	print(solve())


if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
import math
x,n=map(int,input().split())
arr=list(map(int,input().split()))
min1,ans1=float('INF'),float('INF')
for i in range(x,x+n+1):
    if i not in arr:
        min1=abs(i-x)
        ans1=i
        break
min2,ans2=float("INF"),float("INF")
for i in reversed(range(x-n,x+1)):
    if i not in arr:
        min2=abs(i-x)
        ans2=i
        break

if min1>min2:
    print(ans2)
elif min1==min2:
    print(min([ans1,ans2]))
else:
    print(ans1)

Submission status: Accepted

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
    elif(l_list == []):
      ans = max(s_list)
    elif(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: Accepted

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

if n == 0:
    print(x)

else:
    l = list(map(int, input().split()))
    tmp = x
    i = 1
    while i:
        if not x in l:
            print(x)
            break
        elif not tmp in l:
            print(tmp)
            break
        x -= 1
        tmp += 1

Submission status: Accepted

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(n==1):
  if(x==p[0]):
    ans = x-1
    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: Accepted

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: Accepted

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)
    break
  elif (X+i)not in p:
        print(X+i)
        break

Submission status: Accepted

Solution code:
x, n = [int(i) for i in input().split(' ')]

if n:
    p = [int(i) for i in input().split(' ')]
    if x in p:
        for i in range(1, 101):
            if not x - i in p:
                print(x - i)
                exit()
            elif not x + i in p:
                print(x + i)
                exit()
    else:
        print(x)
else:
    print(x)

Submission status: Accepted

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)
        break
    elif (X+i) not in p:
        print(X+i)
        break

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
retsu = list(map(int, input().split()))
# X, N = 6, 5
# retsu = [4,7,10,6,5]

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

retsu = set(retsu)
hanbetsu = set(hanbetsu)
hikaku = hanbetsu.difference(retsu)

if X in hikaku:
    print(X)
else:
    for i in range(1,101):
        if X - i in hikaku:
            print(X-i)
            break
        elif X + i in hikaku:
            print(X+i)
            break

Submission status: Accepted

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

P.sort()
ans = 10000000
for i in range(-101, 102):
  if not i in P:
    ans = min(ans, abs(i-X))

if not X-ans in P:
  print(X-ans)
else:
  print(X+ans)

Submission status: Accepted

Solution code:
def search_near(X, N, nums):
    for n in range(1,N+2):
        if n % 2 ==0:
            diff = n//2 *(-1)
        else:
            diff = n//2
        target = X+diff
        if target in nums:
            pass
        else:
            print(target)
            break

X, N = map(int, input().split(" "))
if N ==0:
    print(X)
else:
    nums = [i for i in map(int, input().split(" "))]
    search_near(X,N,nums)

Submission status: Accepted

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

for i in range(200):
    a=x-i
    if a not in p:
        print(a)
        exit()
    a=x+i
    if a not in p:
        print(a)
        exit()

Submission status: Accepted

Solution code:
a=list(map(int,input().split()))
try:
  b=list(map(int,input().split()))
  out=-1
  for i in range(102):
    if i in b:
      continue
    if abs(out-a[0])>abs(i-a[0]):
      out=i
  print(out)
except EOFError:
  print(a[0])

Submission status: Accepted

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

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

p = [int(i) for i in input().split()]
  
q = set(range(102)) - set(p)  
  
r = sorted(q,key=lambda x:(abs(x-X),x))

print(r[0])

Submission status: Accepted

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

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

p = [int(i) for i in input().split()]

if X not in p:
  print(X)
  exit();

if N == 1 and p[0] == X:
  print(X-1)
  exit();

for j in range(101):
  if X-j not in p:
    print(X-j)
    exit();
  if X+j not in p:
    print(X+j)
    exit();

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
flag = [False] * 102
for value in p:
    flag[value] = True
minAbs = 200
for i in range(102):
    ab = abs(x - i)
    if not flag[i]:
        minAbs = min(minAbs, ab)
for i in range(102):
    ab = abs(x - i)
    if not flag[i] and ab == minAbs:
        print(i)
        break

Submission status: Accepted

Solution code:
import sys

def Forbidden_List(x,n,p):
  for i in range(n//2 + n%2 + 1):
    if x - i not in p: 
        return x - i
    if x + i not in p:
        return x + i

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: Accepted

Solution code:
import sys

def Forbidden_List(x,n,p):
  for i in range(n):
    if x - i not in p: 
        return x - i
    if x + i not in p:
        return x + i
  return x - 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: Accepted

Solution code:
x, n = map(int, input().split())
if n == 0:
    print(x)
else:
    p = set(map(int, input().split()))
    d = 0
    while True:
    	if x-d not in p:
    		print(x-d)
    		break
    	if d+x not in p:
    		print(d+x)
    		break
    	d+=1

Submission status: Accepted

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

Submission status: Accepted

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

if n==0:
  print(x);exit()
  
if not x in Q:
  print(x) ; exit()

A=[]
for i in range(1,250):
  A.append(-i)
  A.append(i)
  
for i in A:
  if not x+i in Q:
    print(x+i)
    exit()

Submission status: Accepted

Solution code:
# 全探索
x, n = map(int, input().split())

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

    min_list = []
    
    for i in range(-200, 200):
        if i not in p:
            ans = abs(i-x)
            min_list.append(ans)
    
    minimum = min(min_list)
    minimum_right = x + minimum
    minimum_left = x - minimum

    if minimum_right and minimum_left not in p:
        print(minimum_left)
    elif minimum_right not in p:
        print(minimum_right)
    else:
        print(minimum_left)

Submission status: Accepted

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