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:
import sys
X, N = (int(x) for x in input().split())
num = list(int(x) for x in input().split())
num.sort()
if X in num:
    index = num.index(X)
    for i in range(1,N+2):
        # -
        if index-i >= 0:
            if num[index-i] != X-i:
                print(X-i)
                sys.exit()
        else:
            print(X-i)
            sys.exit()
        # +
        if index+i < N:
            if num[index+i] != X+i:
                print(X+i)
                sys.exit()
        else:
            print(X+i)
            sys.exit()
else:
    print(X)

Submission status: Accepted

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

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

    ans_list = []

    for i in range(x, -2, -1):
        if i not in p:
            ans_list.append(i)
            break

    for i in range(x, 102):
        if i not in p:
            ans_list.append(i)
            break

    if len(ans_list) == 1:
        print(ans_list[0])
    elif ans_list[0] == ans_list[1]:
        print(ans_list[0])
    else:
        ans_abs = min(abs(ans_list[0]-x), abs(ans_list[1]-x))
        if abs(ans_list[0]-x) == ans_abs:
            print(ans_list[0])
        else:
            print(ans_list[1])

Submission status: Accepted

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

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


    p.sort()

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

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

        i += 1

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
p=list(map(int,input().split()))
l=[i for i in range(-10,110)]
for i in p:
    l.remove(i)
ans=10**3
a=0
for k in reversed(l):
    z=min(ans,abs(x-k))
    if z==abs(x-k):
        a=k
        ans=z
print(a)

Submission status: Accepted

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

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

inc = 0

if x not in p:
  print(x)
  exit()

while True:
  inc += 1
  if x-inc not in p:
    print(x-inc)
    exit()
  if x+inc not in p:
    print(x+inc)
    exit()

Submission status: Accepted

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

ans = 1000

for i in range(-1,102):
    if abs(i-X) < abs(ans-X) and i not in p:
            ans = i

print(ans)

Submission status: Accepted

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

ans=X
if N!=0:
    k=0
    while True:
        if X-k not in p:
            ans=X-k
            break
        elif X+k not in p:
            ans=X+k
            break
        k+=1
print(ans)

Submission status: Accepted

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

if N == 0:
    print(X)
else:
    a = [int(i) for i in range(-201, 201) if not i in p]
    m = 100
    val = 0
    for i in a:
        if abs(i-X) < m:
            m = abs(i-X)
            val = i
    print(val)

Submission status: Accepted

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

if not(x in ps):
    print(x)
else:
    for i in range(100):
        if x+i in ps:
            b=100
        else:
            a=x+i
            break
    for j in range(100):
        if x-j in ps:
            b=100
        else:
            if a-x>=j:
                a=x-j
                break
    print(a)

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
ans = 0
if n == 0:
    print(x)
else:
    p = sorted(list(map(int,input().split())), reverse=True)
    data = []
    for i in range(200,-100,-1):
        if not(i in p):
            data.append(i)
    #print(data)
    mi = 1000
    for i in data:
        #print(p)
        if mi >= abs(i-x):
            mi = abs(i-x)
            ans = i
    print(ans)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = list(map(int,input().split()))
l = [i for i in range(x+101)]
for pi in p:
    l[pi] = 500
m = 10000
ans = 0
for li in l:
    if m > abs(x-li):
        m = abs(x-li)
        ans = li
print(ans)

Submission status: Accepted

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

l = set(l)
p = set(p)
dif = list(l-p)
dif.sort(reverse=True)
ans_min=1000000
ans = 0
for i in dif:
    if ans_min>=abs(x-i):
        ans_min=abs(x-i)
        ans = i

print(ans)

Submission status: Accepted

Solution code:
import math
def ip():return int(input())
def imp():return map(int,input().split())
def impstr():return map(str,input().split())
def limp():return list(map(int,input().split()))
def limpstr():return list(map(str,input().split()))

x,n=imp()
l=limp()
if n==0:
    print(x)
    exit()
else:
    k=0
    while True:
        if x-k not in l:
            print(x-k)
            exit()
        if x+k not in l:
            print(x+k)
            exit()
        k+=1

Submission status: Accepted

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

#print(seq)

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

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

Submission status: Accepted

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

a = -1
if len(P) > 0:
    for p in range(0, 102):
        if abs(X - p) < abs(X - a) and (p not in P):
            a = p
else:
    a = X

print(a)

Submission status: Accepted

Solution code:
from sys import stdin, stdout

int_in = lambda: int(stdin.readline())
arr_in = lambda: [int(x) for x in stdin.readline().split()]
mat_in = lambda rows: [arr_in() for y in range(rows)]
str_in = lambda: stdin.readline().strip()
out = lambda o: stdout.write("{}\n".format(o))
arr_out = lambda o: out(" ".join(map(str, o)))
bool_out = lambda o: out("YES" if o else "NO")
tests = lambda: range(1, int_in() + 1)
case_out = lambda i, o: out("Case #{}: {}".format(i, o))


def solve(x, n, p):
    p = set(p)
    best = -1
    best_diff = abs(x + 1)
    for item in range(501):
        if item not in p and abs(item - x) < best_diff:
            best_diff = abs(item - x)
            best = item
    return best


if __name__ == "__main__":
    x, n = arr_in()
    if n == 0:
        out(x)
        exit()
    p = arr_in()
    out(solve(x, n, p))

Submission status: Accepted

Solution code:
import bisect
x,n=map(int,input().split())
if n==0:
  print(x)
  exit()
p=sorted(list(map(int,input().split())))
a=bisect.bisect_left(p,x)
if p[a]!=x or n==0:
  print(x)
  exit()
i=0
while True:
  if not (x-i) in p:
    print(x-i)
    break
  elif not (x+i) in p:
    print(x+i)
    break
  else:
    i+=1

Submission status: Accepted

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

p.sort()


ans1 = 300
ans2 = 300

flag = 1

for i in range(100):
    if x-i not in p:
        ans1 = x-i
        flag = 0
    if x+i not in p:
        ans2 = x+i
        flag = 0
    if flag == 0:
        break
    else:
        continue

print(min(ans1, ans2))

Submission status: Accepted

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

if N != 0:
    P=list(map(int,input().split()))
    P.sort()
    if X < P[0]:
        imin = X
    elif X > P[N-1]:
        imin = X 
    else:
        imin = 0
        max_diff = 1000
        for i in range(P[0]-1,P[N-1]+2):
            if i not in P:
                if abs(i-X) < max_diff:
                    max_diff = abs(i-X)
                    imin = i
else:
    imin = X

print(imin)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
if n!=0:
    lst = [i for i in range(102)]
    a = list(map(int, input().split()))

    for i in range(n):
        lst.remove(a[i])
    
    if x in lst:
        print(x)
    else:
        b=x
        c=x
        for i in range(100):
            b-=1
            c+=1
            if b in lst:
                print(b)
                break
            elif c in lst:
                print(c)
                break
    
else:
    print(x)

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
p=list(map(int,input().split()))
ans=10**18
a=[]
for i in range(-101,200):
  if i in p:continue
  d=abs(x-i)
  if d<ans:
    ans=d
    a.append([d,i])

# print(a)
a.sort(key=lambda x: x[0])
# print(a)
mnv=a[0][0]
mnidx=a[0][1]
for ai in a:
  v,idx=ai
  if mnv==v:
    if idx<mnidx:
      mnidx=idx
  else:
    break
print(mnidx)

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
p = set()
if n:
    p = set(map(int,input().split()))
mini = float('inf')
ans = float('inf')
for i in range(-400,400):
    if i not in p:
        if abs(x-i)<mini:
            mini = abs(x-i)
            ans = i
        elif abs(x-i)==mini and ans>i:
            ans=i
print(ans)

Submission status: Accepted

Solution code:
import bisect
import sys
from collections import defaultdict
X, N = [int(x) for x in input().split()]
P = []
if N:
    P = [int(x) for x in input().split()]

Pt = defaultdict(bool)
for p in P:
    Pt[p] = True

if Pt[X] == False:
    print(X)
    sys.exit()

xl = X - 1
xr = X + 1
while True:
    if Pt[xl] == False:
        print(xl)
        break
    elif Pt[xr] == False:
        print(xr)
        break
    xl -= 1
    xr += 1

Submission status: Accepted

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

Ps = sorted(P)

for z in range(0,101):
    if not(X-z in P):
        print(X-z)
        break
    if not(X+z in P):
        print(X+z)
        break

Submission status: Accepted

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

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

Submission status: Accepted

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

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
a_list=list(map(int,input().split()))
current_num=0
while(True) :
  t=x+current_num not in a_list
  s=x-current_num not in a_list
  if s:
    print(x-current_num)
    break
  elif t :
    print(x+current_num)
    break
  else :
    current_num+=1

Submission status: Accepted

Solution code:
import math
import numpy as np
X, N = map(int,input().split())
ans = False
if not N == 0:
  p = list(map(int,input().split()))
else:
  print(X)
  ans = True
if not ans:
  for i in range(101):
    if not (X- i in p):
      print(X-i)
      break
    elif not (X + i in p):
      print(X+i)
      break

Submission status: Accepted

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


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

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

print(ans)

Submission status: Accepted

Solution code:
import numpy as np

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

if N == 0:
  print(X)
  exit()
  
i = sorted(list(set(range(X-N, X+1)) - p_list))[-1]
j = sorted(list(set(range(X, X+N+1)) - p_list))[0]

if X-i <= j-X:
  print(i)
else:
  print(j)

Submission status: Accepted

Solution code:
import sys
from io import StringIO
import unittest
import os

# 再帰処理上限(dfs作成時に設定するのが面倒なので限度近い値を組み込む)
sys.setrecursionlimit(999999999)


# 実装を行う関数
def resolve():
    x, n = map(int, input().split())

    if n == 0:
        print(x)
        return

    p_list = list(map(int, input().split()))
    p_list.sort()
    p_list = set(p_list)

    ans = 9999
    work_abs = 9999
    for i in range(110):
        if i in p_list:
            continue

        work_x = max(x, i)
        work_p = min(x, i)
        if work_abs > work_x - work_p:
            work_abs = work_x - work_p
            ans = i

    print(ans)


# テストクラス
class TestClass(unittest.TestCase):
    def assertIO(self, assert_input, output):
        stdout, sat_in = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(assert_input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, sat_in
        self.assertEqual(out, output)

    def test_input_1(self):
        test_input = """6 5
4 7 10 6 5"""
        output = """8"""
        self.assertIO(test_input, output)

    def test_input_2(self):
        test_input = """10 5
4 7 10 6 5"""
        output = """9"""
        self.assertIO(test_input, output)

    def test_input_3(self):
        test_input = """100 0"""
        output = """100"""
        self.assertIO(test_input, output)

    # 自作テストパターンのひな形(利用時は「tes_t」のアンダーバーを削除すること
    def tes_t_1original_1(self):
        test_input = """データ"""
        output = """データ"""
        self.assertIO(test_input, output)


# 実装orテストの呼び出し
if __name__ == "__main__":
    if os.environ.get("USERNAME") is None:
        # AtCoder提出時の場合
        resolve()

    else:
        # 自PCの場合
        unittest.main()

Submission status: Accepted

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

p_all = set(range(-200, 200)) - set(p)
# print(p_all)

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

print(ans)

Submission status: Accepted

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

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

seen = [0]*(100+2)

for p in ps:
    seen[p] = 1

if seen[x] == 0:
    print(x)
    exit()

count = 1
candidate = []
while True:
    nside = max(0, x - count)
    if seen[nside] == 0:
        candidate.append(nside)
        print(nside)
        exit()

    pside = min(102, x + count)
    if seen[pside] == 0:
        candidate.append(pside)
        print(pside)
        exit()
    count += 1

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
 
## Library
 
import sys
from fractions import gcd
import math
from math import ceil,floor
import collections
from collections import Counter
import itertools
 
## input
 
# n=int(input())
# A,B,C,D=map(int, input().split())
# string = input()
# yoko = list(map(int, input().split()))
# tate = [int(input()) for _ in range(N)]
# N, M = map(int,input().split()) 
#    P = [list(map(int,input().split())) for i in range(M)]
 
X,N=map(int, input().split())
if N==0:
    print(X)
    sys.exit()

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

P.sort()

tmp1 = 0
tmp2 = 0

for i in range(X,102):
    if P.count(i)==0:
        tmp1 = i
        break

j = X
while j >= 0:
    if P.count(j)==0:
        tmp2 = j
        break    
    j -= 1

tmp3 = abs(X - tmp1)
tmp4 = abs(X - tmp2)

if tmp3 >= tmp4:
    print(tmp2)
else:
    print(tmp1)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
x,n = map(int,input().split())
if n == 0:
    print(x)
    exit()
s = sorted(list(map(int,input().split())))


i = x
while True:
    if i not in s:
        res_high = i
        break
    else:
        i += 1


j = x
while True:
    if j not in s:
        res_low = j
        break
    else:
        j -= 1


if abs(res_low - x) <= abs(res_high - x):
    print(res_low)
else:
    print(res_high)

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
p=list(map(int,input().split()))
f=0
ans=[]
for i in range(60):
    if not (x+i) in p or not (x-i) in p:
        ans.append(x-i)
        ans.append(x+i)
if not ans[0] in p and not ans[1] in p:
    print(ans[0])
elif not ans[0] in p and ans[1] in p:
    print(ans[0])
elif ans[0] in p and not ans[1] in p:
    print(ans[1])

Submission status: Accepted

Solution code:
#dt = {} for i in x: dt[i] = dt.get(i,0)+1
import sys
input = sys.stdin.readline
ipnl = lambda n: [int(input()) for _ in range(n)]
inp = lambda :int(input())
ip = lambda :[int(w) for w in input().split()]

k,n = ip()
if n:
    x = ip()
    x = set(x)
    if k not in x:
        print(k)
    else:
        a = k-1
        while a in x:
            a -= 1
        b = k+1
        while b in x:
            b += 1
        if abs(a-k) < abs(b-k):
            print(a)
        elif abs(b-k) < abs(a-k):
            print(b)
        else:
            print(min(a,b))
else:
    print(k)

Submission status: Accepted

Solution code:
(X,N) = map(int,input().split())
if N == 0:
    print(X)
else:
    p = list(map(int,input().split()))
    for i in range(N+1):
        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:
a=300
x,n=map(int, input().split())
if n==0:
    a=x
else:
    p= list(map(int, input().split()))
    ls=[j  for j in range(-100,200)]

    for i in range(len(p)):
        ls.remove(p[i])
    for k in range(len(ls)):
        if abs(x-ls[k])<abs(x-a):
             a=ls[k]
        elif abs(x-ls[k])==abs(x-a):
            if ls[k]<a:
                a=ls[k]
print(a)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:


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

if S[1]==0:
  print(S[0])
else:
  N=list(map(int,input().split()))
  k=S[0]
  t=S[0]
  s=0
  u=1
  while k in N != True:
    if s==0:
      k=t-u
      s=1
    else:
      k=t+u
      s=0
      u+=1
  print(k)

Submission status: Accepted

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

ans = 0
tmp = float("inf")
for i in range(1000):
    if i not in p:
        if abs(x - i) < tmp:
            tmp = abs(x - i)
            ans = i

print(ans)

Submission status: Accepted

Solution code:
import sys
N , M = (map(int , input().split()))
if M == 0:
    print(N)
    sys.exit()
A = list(map(int , input().split()))
aa = [i for i in range(-102,102)]
ans_list = {}
for i in aa:
    if i not in A:
        ans_list.update({i:abs(N-i)})
for i in ans_list:
    if ans_list[i] == min(list(ans_list.values())):
        print(i)
        sys.exit()

Submission status: Accepted

Solution code:
X,N=map(int,input().split())
p=[0]*N
p=list(map(int,input().split()))
mixmix=float('inf')
hozon=-1
if(p.count(X)!=1):
    print(X)
    exit()
for i in range(1,101):
    if(p.count(X-i)!=1):
        print(X-i)
        exit()
    elif(p.count(X+i)!=1):
        print(X+i)
        exit()

Submission status: Accepted

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

for n in range(100):
    if (X - n) not in P:
        print(X-n)
        exit()
    if (X + n) not in P:
        print(X+n)
        exit()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
X,N=map(int,input().split())
if N==0:
  print(X)
  exit()
P=list(map(int,input().split()))
nP=[]
min=10**15
for i in range(-200,200):
  if i not in P:
    nP.append(i)
anlist=[]
for i in nP:
  if min>abs(i-X):
    min=abs(i-X)
    anlist.append(i)
print(anlist[-1])

Submission status: Accepted

Solution code:
import bisect

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

if not p:
    print(X)
    exit()

pos = bisect.bisect_left(p, X)

left, right = p[pos], p[pos]
l_abs, r_abs = 0, 0
while True:
    if left in p:
        left -= 1
        l_abs += 1
    if right in p:
        right += 1
        r_abs += 1
    if left not in p and right not in p:
        break

if l_abs == r_abs:
    print(left)
elif l_abs > r_abs:
    print(right)
else:
    print(left)

Submission status: Accepted

Solution code:
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce


def input(): return sys.stdin.readline().strip()


def INT(): return int(input())


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


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


def ZIP(n): return zip(*(MAP() for _ in range(n)))


sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    X, N = MAP()
    if N == 0:
        print(X)
        exit()

    p = LIST()
    ans = []
    for i in range(200):
        if not X-i in p:
            print(X-i)
            exit()
        if not X+i in p:
            print(X+i)
            exit()
        

if __name__ == '__main__':
    main()

Submission status: Accepted

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

  for i in range(100):
    kouho1=x+i
    kouho2=x-i
    if kouho2 not in p:
      print(kouho2)
      break
    elif kouho1 not in p:
      print(kouho1)
      break
else:
  print(x)

Submission status: Accepted

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

ans=10000
b=0

an=10000

for i in range(0,102):
    b=0

    for _ in p:
        if i==_:
            b=1
            break
    
    if b!=1:
        if ans> abs(x-i):
            ans=abs(x-i)
            an=i

print(an)

Submission status: Accepted

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

if n == 0:
    print(x)
else:
    p = list(map(int, input().split()))
    a = []
    for i in range(102):
        if all([j != i for j in p]):
            a.append(i)
    z = x
    ans = 0
    for i in a:
        if z > abs(x-i):
            z = abs(x-i)
            ans = i
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#atcoder template
def main():
    import sys
    imput = sys.stdin.readline
    #文字列入力の時は上記はerrorとなる。
    #ここにコード
    #input
    X, N = map(int, input().split())
    p = list(map(int, input().split()))

    #output
    answer1 = X
    answer2 = X
    while answer1 in p:
        answer1 -= 1
    while answer2 in p:
        answer2 += 1

    if X - answer1 == answer2 - X:
        print(answer1)
    elif X - answer1 < answer2 - X:
        print(answer1)
    elif X- answer1 > answer2 - X:
        print(answer2) 

    #N = 1のときなどcorner caseを確認！
if __name__ == "__main__":
    main()

Submission status: Accepted

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

cnt = 0
while True:
    big = x + cnt
    small = x - cnt
    if small not in p:
        print(small)
        exit()
    if big not in p:
        print(big)
        exit()
    cnt += 1

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
p=list(map(int,input().split()))
#p.sort(reverse=True)
r=0
while True:
  if not (x-r in p):
    print(x-r)
    exit()
  if not (x+r in p):
    print(x+r)
    exit()
  r+=1
print(1/0) # RE

Submission status: Accepted

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

for i in range(102):
    if i in p:
        pass
    else:
        if abs(i-X) < min_value:
            ans = i
            min_value = abs(i-X)
print(ans)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split())) # list()でリスト化、それを変数に代入。
i = 0
while True:
    if not x-i in p:
        print(x-i)
        break
    elif not x+i in p:
        print(x+i)
        break
    i += 1

Submission status: Accepted

Solution code:
def main():
    x, n = map(int, input().split())
    ps = list(map(int, input().split()))
    anti_ps = [i for i in range(102) if i not in ps]
    anti_ps_abs = [abs(i-x) for i in range(102) if i not in ps]
    ans = anti_ps[anti_ps_abs.index(min(anti_ps_abs))]
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
x, p = map(int,input().split())
N = set(list(map(int, input().split())))
for i in range(100):
    if x-i not in N:
        print(x-i)
        quit()
    if x+i not in N:
        print(x+i)
        quit()

Submission status: Accepted

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

ans=0
minAbs=abs(X-ans)

for i in range(0,102):
    if (i in p)==True:
        continue

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

print(ans)

Submission status: Accepted

Solution code:
from functools import cmp_to_key

x, n = map(int, input().split())
p = set(map(int, input().split()))
for d in range(100):
    if (x - d) >= -101 and (x - d) not in p:
        print(x - d)
        break
    elif (x + d) <= 101 and (x + d) not in p:
        print(x + d)
        break

Submission status: Accepted

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

if N == 0:
  print(X)
else:
  num_list = list(map(int, input().split()))
  sub_list = [x-X for x in num_list]
  
  for i in range(100):
    if -i not in sub_list:
      print(X - i)
      break
    elif i not in sub_list:
      print(X + i)
      break

Submission status: Accepted

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

b = [True for _ in range(0, 102)]

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

for i in range(101):
    if 0 <= x-i <= 101:
        if b[x-i]:
            print(x-i)
            break
    if 0 <= x+i <= 101:
        if b[x+i]:
            print(x+i)
            break

Submission status: Accepted

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

a = 0
for i in range(x-1, -10**9, -1):
  if i not in p:
    a = i
    break
b = 0
for i in range(x, 10**9):
  if i not in p:
    b = i
    break

if abs(x-a) <= abs(x-b):
  print(a)
else:
  print(b)

Submission status: Accepted

Solution code:
import sys

def input():
    return sys.stdin.readline().strip()

def main():
    x, n= map(int, input().split())
    if n == 0:
        print(x)
        return
    P=[]
    P = list(map(int, input().split()))
    
    for i in range(100):
        a = x-i
        b = x+i
        if a not in P:
            print(a)
            return
        elif b not in P:
            print(b)
            return
    


main()

Submission status: Accepted

Solution code:
def main():
    X , N = map(int, input().split())
    Pl = [A for A in input().split()]
    Pl = list(map(int, Pl))
    #print(Pl)
    for i in range(200) :
        Xp = X + i
        Xm = X - i
        if Xp not in Pl and Xm not in Pl :
            ans = min(Xp,Xm)
            break
        elif Xm not in Pl and Xp in Pl :
            ans = Xm
            break
        elif Xp not in Pl and Xm in Pl :
            ans = Xp
            break
        else :
            pass
    print(ans)




if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
x,n,*p = map(int,open(0).read().split())
a = [[i,abs(x-i)] for i in range(0,102) if i not in p ]
a.sort(key=lambda x:x[1]) 
print(a[0][0])

Submission status: Accepted

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



for i in range(102,-1,-1):
    b = abs(X-i)
    if i in a:
        continue
    elif b <= zettai:
        zettai = b
        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()))
  p.sort()

  res = 100000
  ps = 0
  for i in p:
    ab = abs(x - i)
    if res > ab:
      res = ab
      ps = i
    else:
      break
  flug = False
  iter = 1
  while flug == False:
    ans1 = iter + ps
    ans2 = ps - iter
    if (ans2 in p) is False:
      print(ans2)
      flug = True
    elif (ans1 in p) is False:
      print(ans1)
      flug = True
    else:
      iter += 1

Submission status: Accepted

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

Submission status: Accepted

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

check = 1000000
ans = 0

N = list(range(-300, 300))

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)