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

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():

    X, N = in_nn()
    p = list(in_nn())

    ans = 1000
    for i in range(-5, 105):
        if i in p:
            continue
        else:
            if abs(X - i) < abs(X - ans):
                ans = i

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
X, N = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]
min_abs = 100
for i in range(102):
    if i not in p:
        min_abs = min(min_abs, abs(X-i))

if X - min_abs not in p:
    print(X - min_abs)
else:
    print(X + min_abs)

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
b=float("INF")
ans=0
l=set(map(int,input().split()))
for i in range(-100,200):
    if i in l:continue
    if b>abs(x-i):
        b=abs(x-i)
        ans=i
print(ans)

Submission status: Accepted

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

if N == 0:
  print(X)
  import sys
  sys.exit()
  
i = 0
while 1:
  if (X-i) not in p:
    print(X-i)
    break
  elif (X+i) not in p:
    print(X+i)
    break
  else:
    i += 1

Submission status: Accepted

Solution code:
X,N=map(int,input().split())
p=list(map(int,input().split()))
s = set(p)
i=0
ans = X
found=False
while not found:
    if X+i not in s:
        ans = X+i
        found = True
    if X-i not in s:
        ans=X-i
        found = True
    i+=1
print(ans)

Submission status: Accepted

Solution code:
X,N=map(int,input().split())
if N==0:
    print(X)
else:
    a = list(map(int,input().split()))
    res = 10**9
    mi = 10**9
    for val in range(200,-100,-1):
        if val not in a:
            tmp = abs(X-val)
            if res >= tmp:
                res = tmp
                mi = val
    print(mi)

Submission status: Accepted

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

pli = set(map(int,input().split()))
i = 0

while True:
  if not X-i in pli:
    print(X-i)
    break
  if not X+i in pli:
    print(X+i)
    break
  i += 1

Submission status: Accepted

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

Submission status: Accepted

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

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

for i in range(0,105):
    if x-i not in p:
        print(x-i)
        exit()
    if x+i not in p:
        print(x+i)
        exit()

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**6)

x,n=map(int,input().split())
p=[int(i) for i in input().split()]
ans=0
ansc=100000
for i in range(-200,200):
    if i not in p:
        #print(i,abs(i-x))
        if ansc>abs(i-x):
            ans=i
            ansc=abs(i-x)
        elif ansc==abs(i-x):
            if ans>i:
                ans=i
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
from bisect import bisect_left
INF = float("inf")


def main():
    X, N = map(int, input().split())
    if N > 0:
        p = set(map(int, input().split()))
    else:
        p = set()

    ans = INF
    for n in range(110):
        if n in p:
            continue
        if abs(n-X) < abs(ans-X):
            ans = n

    print(ans)

    return


if __name__ == '__main__':
    main()

Submission status: Accepted

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

ls = [0]*(102)
for p in P:
    ls[p] = 1
# xとのさがi
for i in range(101):
    L, R = X-i, X+i
    if ls[L] == 0:
        print(L)
        break

    if ls[R] == 0:
        print(R)
        break

Submission status: Accepted

Solution code:
from sys import stdin
from collections import defaultdict as dd
from collections import deque as dq
import itertools as it
from math import sqrt, log, log2
from fractions import Fraction

x, n = map(int, input().split())
if n!=0: nums = set(map(int, stdin.readline().split()))

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

ans = 10**9
for i in range(10000):
    t1 = x + i if x+i not in nums else 10**4
    t2 = x - i if x-i not in nums else 10**4
    if t1!=10**4 or t2!=10**4:
        ans = min(t1, t2)
        print(ans)
        exit()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
x,n = list(map(int,input().split()))
p = list(map(int,input().split()))

p.sort()
inf=float("inf")
min_dif =inf
ret=None

for i in range(102):
    if i in p:
        continue
    if abs(x-i)<min_dif:
        min_dif=abs(x-i)
        ret=i

print(ret)

Submission status: Accepted

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

def my_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

i = 0
flag = 0

while(True):
    if(not((X-i) in p)):
        flag = -1
        break
    if(not((X+i) in p)):
        flag = 1
        break
    i += 1

print(X + i * flag)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
X,N = list(map(int,input().split()))
P = set(map(int,input().split()))
cnt = 0
while True:
    if X-cnt not in P:
        print(X-cnt)
        break
    if X+cnt not in P:
        print(X+cnt)
        break
    cnt += 1

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def main():
    X, N, *P = map(int, read().split())
    P = set(P)
    Q = [i for i in range(-10, 110) if i not in P]
    Q.sort()
    error = INF
    for q in Q:
        if abs(X-q) < error:
            ans = q
            error = abs(X-q)
    
    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
X,N = map(int, input().split())
p_set = set([int(e) for e in input().split()])

ans_abs = abs(X - 300)
ans = 300

for i in range(-300,300):
    if i not in p_set:
        if abs(X - i) < ans_abs:
            ans_abs = abs(X - i)
            ans = i

print(ans)

Submission status: Accepted

Solution code:
def main():
    x, n = list(map(int, input().split()))
    if n == 0:
        print(x)
        exit()
    else:
        P = list(map(int, input().split()))
    S = set(range(102)) - set(P)
    ans = float('inf')
    ans_p = 0
    for s in S:
        r = abs(s - x)
        if r < ans:
            ans = r
            ans_p = s
        elif r == ans:
            if ans_p > s:
                ans_p = s
    print(ans_p)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

X,N=[int(i) for i in input().split(" ")]
if N==0:
    print(X)
    sys.exit(0)
p=[int(i) for i in input().split(" ")]

i=0
while True:
    if (X-i in p)==False:
        print(X-i)
        sys.exit(0)
    elif (X+i in p)==False:
        print(X+i)
        sys.exit(0)
    else:
        i+=1

Submission status: Accepted

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


def answer():
    d = 0

    while True:
        if x - d not in p:
            return x - d
        if x + d not in p:
            return x + d
        d += 1


print(answer())

Submission status: Accepted

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

if not x in p:
  print(x)
else:
  for i in range(1,100):
    if not x-i in p:
      print(x-i)
      break
    if not x+i in p:
      print(x+i)
      break

Submission status: Accepted

Solution code:
x, n = list(map(int, input().split()))
al = list(map(int, input().split()))
INF = float("inf")
ans = INF
sa = INF
for i in range(102):
    if i not in al:
        if sa > abs(x-i):
            sa = abs(x-i)
            ans = i
print(ans)

Submission status: Accepted

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

ab = 0
while 1:
    if not(X-ab in p):
        print(X-ab)
        break
    if not(X+ab in p):
        print(X+ab)
        break
    ab+=1

Submission status: Accepted

Solution code:
import sys
mina=10**10
X,N=map(int,input().split())
if N==0:
  print(X)
  sys.exit()
L=list(map(int,input().split()))
for i in range(52):
  if X-i not in L:
    print(X-i)
    sys.exit()
  if X+i not in L:
    print(X+i)
    sys.exit()

Submission status: Accepted

Solution code:
from collections import Counter

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

if not(X in c):
    print(X)
    exit(0)

for i in range(200):
    tmp1 = X-i
    if not(tmp1 in c):
        print(tmp1)
        exit(0)

    tmp2 = X+i
    if not(tmp2 in c):
        print(tmp2)
        exit(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
a = sorted(list(map(int,input().split())))
dif = 10**10
ans = -1
for i in range(102):
    if not i in a:
        if dif>abs(x-i):
            dif = abs(x-i)
            ans = i

print(ans)

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
l = list(map(int,input().split()))
ans = 10**10
if n == 0:
    print(x)
    exit()
for i in range(-100,1000):
    if i in l:
        continue
    if ans > abs(i-x):
        ans1 = i
        ans = abs(i-x)
print(ans1)

Submission status: Accepted

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

    SA=10**9
    num=-10**9
    for i in range(102):
        if i not in p:
            if abs(X-i)<SA:
                SA=abs(X-i)
                num=i
    print(num)
else:
    print(X)

Submission status: Accepted

Solution code:
x,n=map(int, input().split())
p = list(map(int, input().split()))
p=sorted(p)
last=1000
zettai=1000
for i in range(102, -1, -1):
    if i not in p:
        if zettai>=abs(i-x):
            zettai=abs(i-x)
            last=i
print(last)

Submission status: Accepted

Solution code:
num,length = list(map(int,input().split()))
if length != 0:
  lst = list(map(int,input().split()))
else:
  pass

if length == 0:
  print(num)
else:
  sett = set(lst)
  for i in range(100):
    if not (num-i in lst):
      print(num-i)
      break
    if not (num+i in lst):
      print(num+i)
      break

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

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

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。
def get_all_int():
    return map(int, open(0).read().split())

def rangeI(it, l, r):
    for i, e in enumerate(it):
        if l <= i < r:
            yield e
        elif l >= r:
            break

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

INF = 999999999999999999999999
MOD = 10**9+7

x,n = get_nums_l()
if n == 0:
    print(x)
    exit()
P = set(get_nums_l())

log(P)

min_ = INF
ans = INF

for a in range(-1, 102):
    if a not in P:
        y = abs(x-a)
        # log(a, y)
        if y < min_:
            min_ = y
            ans = a

print(ans)

Submission status: Accepted

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

for i in range(102):
  xl = x - i
  xr = x + i
  if xl not in P:
    print(xl)
    break
  elif xr not in P:
    print(xr)
    break

Submission status: Accepted

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

P.sort()
for d in range(101):
    r = X + d
    l = X - d
    if l not in P:
        ans = l
        break
    if r not in P:
        ans = r
        break

print(ans)

Submission status: Accepted

Solution code:
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    x,n=INTM()
    p=LIST()
    
    for i in range(101):
        if not x-i in p:
            print(x-i)
            break
        if not x+i in p:
            print(x+i)
            break
        
            
    
if __name__ == '__main__':
    do()

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
if N == 0:
    print(X)
    exit()
P = list(map(int, input().split()))
ans = float('inf')

for i in range(102):
    if i in P:
        continue
    if abs(ans - X) > abs(i - X):
        ans = i

print(ans)

Submission status: Accepted

Solution code:
def main():
    X, N = map(int, input().split())
    A = list(map(int, input().split()))
    A_s = set(A)
    candidate = []
    for i in range(-1, 102):
        if i not in A_s:
            candidate.append(i)

    ans = 10**6
    ans_val = 0
    for c in candidate:
        temp = abs(c-X)
        if temp < ans:
            ans = temp
            ans_val = c
    print(ans_val)

        
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    X, N = (int(i) for i in input().split())
    P = {int(i) for i in input().split()}

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans = 0

for i in range(1000):
    if x - i not in p:
        ans = x - i
        break
    elif x + i not in p:
        ans = x + i
        break

print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
X, N = map(int, input().split())
a = set(list(map(int, input().split())))
res = 0
for i in range(400):
  x = i - 200
  if x in a: continue
  if abs(res - X) > abs(x - X): res = x
print(res)

Submission status: Accepted

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


diff=float('inf')
ans=-1
for i in range(-100,110):
    if i in P:
        continue
    d = abs(X-i)
    if d<diff:
        diff=d
        ans=i
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

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

ans = 1e9
for i in range(-105, 105):
    if i in P_set:
        continue
    if abs(ans - X) > abs(i - X):
        ans = i
print(ans)

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline

def solve():
    X, N = map(int, readline().split())
    P = list(map(int, readline().split()))

    a = set(P)

    for i in range(1000):
        if not X - i in a:
            print(X - i)
            break
        
        if not X + i in a:
            print(X + i)
            break

solve()

Submission status: Accepted

Solution code:
import sys


def _ia(): return map(int, sys.stdin.readline().strip().split())


def main():
    x, n = _ia()
    p = {i: 1 for i in _ia()}

    for i in range(101):
        if p.get(x-i) is None:
            return x-i
        if p.get(x+i) is None:
            return x+i


if __name__ == "__main__":
    print(main())

Submission status: Accepted

Solution code:
from sys import stdin


def main():
    _in = [_.rstrip() for _ in stdin.readlines()]
    X, N= list(map(int, _in[0].split(' ')))  # type:list(int)
    try:
        p_arr = list(map(int, _in[1].split(' ')))  # type:list(int)
    except:
        p_arr = []
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    cnt = float('inf')
    memo = None

    abs_ = 0
    while True:
        if X-abs_ not in p_arr:
            ans = X-abs_
            break
        if X+abs_ not in p_arr:
            ans = X+abs_
            break
        abs_ += 1
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
if N == 0:
    print(X)
else:
    *p, = map(int, input().split())
    ans = -1
    d = 10**10
    for i in range(-101, 102):
        if i in p:
            continue
        m = abs(i-X)
        if m < d:
            d = m
            ans = i
    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p_list = [int(i) - x for i in input().split()]
p_list.sort()
for i in range(200):
    if i * (-1) not in p_list:
        print(i * (-1) + x)
        exit()
    elif i not in p_list:
        print(i + x)
        exit()

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
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
#import numpy as np
#from decimal import *

X, N = MAP()
p = LIST()

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

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

i = 1
while 1:
	if not X-i in p:
		print(X-i)
		exit()
	elif not X+i in p:
		print(X+i)
		exit()
	i += 1

Submission status: Accepted

Solution code:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))


ans=9999
diff=9999

x,n=nm()
p=set(nl())

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

print(ans)

Submission status: Accepted

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

count = 0

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

Submission status: Accepted

Solution code:
# coding: utf-8


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

    if X not in p:
        return X

    for i in range(1, 100):
        if X-i not in p:
            return X-i
        
        if X+i not in p:
            return X+i


print(main())

Submission status: Accepted

Solution code:
x, n = [int(v) for v in input().split()]
ps = {int(v) for v in input().split()}

upper = x
for i in range(n + 1):
    if x + i not in ps:
        upper = x + i
        break

lower = x
for i in range(n + 1):
    if x - i not in ps:
        lower = x - i
        break

if upper - x < x - lower:
    print(upper)
else:
    print(lower)

Submission status: Accepted

Solution code:
import sys
# input = sys.stdin.buffer.readline
def main():
    x, n = map(int, input().split())
    if n == 0:
        print(x)
        sys.exit()
    p = tuple(map(int, input().split()))
    cnt = 0
    while True:
        xt = x - cnt
        if xt not in p:
            print(xt)
            sys.exit()
        xt2 = x + cnt
        if xt2 not in p:
            print(xt2)
            sys.exit()
        cnt += 1

if __name__ == '__main__':
    main()

Submission status: Accepted

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

res = 10000

for i in range(-200, 200):
    if i in P:
        continue

    if abs(X - res) > abs(X - i):
        res = i

print(res)

Submission status: Accepted

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

Submission status: Accepted

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

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

mindiff = 10*10
ans=-1
for i in range(-10,200):
    if i in p:
        continue
    if abs(i - x) < mindiff:
        ans = i
        mindiff = abs(i-x)
print(ans)

Submission status: Accepted

Solution code:
from collections import *
from math import *

x,n = list(map(int,input().split()))
a = list(map(int,input().split()))
a.sort()
for i in range(55):
	y = x - i
	if y not in a:
		print(y)
		break
	y = x + i
	if y not in a:
		print(y)
		break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
ans = sorted(list(set(range(-50, 51)) - set([Y - X for Y in list(map(int, input().split()))])), key=lambda x: abs(x))
if len(ans) == 1:
    print(X + ans[0])
elif ans[0] == - ans[1]:
    print(X + min(ans[0], ans[1]))
else:
    print(X + ans[0])

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
P=list(map(int,input().split()))
if not X in P:
  print(X)
  exit()
for i in range(1,100):
  #小さい方向を探す
  if not X - i in P:
    print(X - i)
    exit()
  if not X + i in P:
    print(X + i)
    exit()

Submission status: Accepted

Solution code:
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
	return list(map(int,input().split()))
def m(): #複数文字
	return map(int,input().split())
def onem(): #Nとかの取得
	return int(input())
def s(x): #圧縮
	a = []
	if len(x) == 0:
		return []
	aa = x[0]
	su = 1
	for i in range(len(x)-1):
		if aa != x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a
def jo(x): #listをスペースごとに分ける
	return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
	return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
	ll = 0
	rr = r
	while True:
		mid = (ll+rr)//2

	if rr == mid:
		return ll
	if (ここに評価入れる):
		rr = mid
	else:
		ll = mid+1
"""

x,n = m()

p = l()



ans = Max
ab = Max
dp = [0 for i in range(102)]
for i in p:
	dp[i] = 1

for i in range(102):
	if dp[i] != 1 and abs(x - i) < ab:
		ab = abs(x - i)
		ans = i
print(ans)

Submission status: Accepted

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

p = set(p)

now = 10**29
for i in range(102):
    if not i in p:
        if abs(i-X)<now:
            now = abs(i-X)

if not X-now in p:
    print(X-now)
else:
    print(X+now)

Submission status: Accepted

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

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

tmp = -1
for i in range(-1, 110):
    if i not in p:
        tmp = i if abs(X - tmp) > abs(X - i) else tmp
    
print(tmp)

Submission status: Accepted

Solution code:
import sys
x,n = map(int,input().split())
p = list(map(int,input().split()))
val = x
val_neg = x
val_pos = x
i = 1
while True:
    if val not in p:
        print(val)
        sys.exit()
    else:
        if val_neg not in p:
            print(val_neg)
            sys.exit()
        elif val_pos not in p:
            print(val_pos)
            sys.exit()
        else:
            val_neg -= i
            val_pos += i

Submission status: Accepted

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

L = []
for k in range(0,200):
    if k not in p:
        L.append(k)

temp = 100000
ans = -1
for e in L:
    if temp > abs(e-X):
        temp = abs(e-X)
        ans = e
print(ans)

Submission status: Accepted

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

    ans = [10**4, 10**4]
    for i in range(102):
        if i not in p:
            if ans[1] == abs(x-i):
                ans[0] = min(ans[0], i)
            elif ans[1] > abs(x-i):
                ans[0] = i
                ans[1] = abs(x-i)
    print(ans[0])

Submission status: Accepted

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

def Z(): return int(input())
def ZZ(): return [int(_) for _ in input().split()]

def main():
    X, N = ZZ()
    P = set(ZZ())
    sa, ans = 200, 0
    for i in range(105):
        if i in P: continue
        if abs(X-i) < sa:
            sa = abs(X-i)
            ans = i
    print(ans)

    return

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

    a = x + diff
    if a not in p:
        print(a)
        exit()

Submission status: Accepted

Solution code:
def get_ints():
    return list(map(int, input().split()))

x, n = get_ints()
ps = get_ints()
ps.sort()
ans = 10000000
d = 1000000
for i in range(102):
    if i in ps:
        continue
    nd = abs(x - i)
    if nd < d:
        ans = i
        d = nd

print(ans)

Submission status: Accepted

Solution code:
x, n = [int(i) for i in input().split()]
tmp = input()
if len(tmp) == 0:
  print(x)
else:
  ps = set([int(i) for i in tmp.split()])
  e = 0
  while True:
    if (x - e) not in ps:
      print(x - e)
      break
    if (x + e) not in ps:
      print(x + e)
      break
    e += 1

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

X, N = mapint()
Ps = set(list(mapint()))
now = X
for i in range(1000):
    if not now-i in Ps:
        print(now-i)
        break
    if not now+i in Ps:
        print(now+i)
        break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub


import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()

def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(X, N, P):
    cand = sorted(list(set(range(1000)) - set(P)))
    ans = (INF, 0)
    for n in cand:
        y = abs(X-n)
        ans = min(ans, (y, n))
    return ans[1]





def main():
    X, N = read_int_n()
    P = read_int_n()
    print(slv(X, N, P))


if __name__ == '__main__':
    main()