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 math
import heapq,bisect
import sys
from collections import deque
from fractions import Fraction
mod=10**9+7
mod1=998244353
# ------------------------------warmup----------------------------
import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# -------------------game starts now----------------------------------------------------import math
class SegmentTree1:
    def __init__(self, data, default=9999999, func=lambda a, b: min(a , b)):
        """initialize the segment tree with data"""
        self._default = default
        self._func = func
        self._len = len(data)
        self._size = _size = 1 << (self._len - 1).bit_length()

        self.data = [default] * (2 * _size)
        self.data[_size:_size + self._len] = data
        for i in reversed(range(_size)):
            self.data[i] = func(self.data[i + i], self.data[i + i + 1])

    def __delitem__(self, idx):
        self[idx] = self._default

    def __getitem__(self, idx):
        return self.data[idx + self._size]

    def __setitem__(self, idx, value):
        idx += self._size
        self.data[idx] = value
        idx >>= 1
        while idx:
            self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
            idx >>= 1

    def __len__(self):
        return self._len

    def query(self, start, stop):
        if start == stop:
            return self.__getitem__(start)
        stop += 1
        start += self._size
        stop += self._size

        res = self._default
        while start < stop:
            if start & 1:
                res = self._func(res, self.data[start])
                start += 1
            if stop & 1:
                stop -= 1
                res = self._func(res, self.data[stop])
            start >>= 1
            stop >>= 1
        return res

    def __repr__(self):
        return "SegmentTree({0})".format(self.data)

# -------------------game starts now----------------------------------------------------import math
class SegmentTree:
    def __init__(self, data, default=0, func=lambda a, b: a + b):
        """initialize the segment tree with data"""
        self._default = default
        self._func = func
        self._len = len(data)
        self._size = _size = 1 << (self._len - 1).bit_length()

        self.data = [default] * (2 * _size)
        self.data[_size:_size + self._len] = data
        for i in reversed(range(_size)):
            self.data[i] = func(self.data[i + i], self.data[i + i + 1])

    def __delitem__(self, idx):
        self[idx] = self._default

    def __getitem__(self, idx):
        return self.data[idx + self._size]

    def __setitem__(self, idx, value):
        idx += self._size
        self.data[idx] = value
        idx >>= 1
        while idx:
            self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
            idx >>= 1

    def __len__(self):
        return self._len

    def query(self, start, stop):
        if start == stop:
            return self.__getitem__(start)
        stop += 1
        start += self._size
        stop += self._size

        res = self._default
        while start < stop:
            if start & 1:
                res = self._func(res, self.data[start])
                start += 1
            if stop & 1:
                stop -= 1
                res = self._func(res, self.data[stop])
            start >>= 1
            stop >>= 1
        return res

    def __repr__(self):
        return "SegmentTree({0})".format(self.data)
#-------------------------------iye ha chutiya zindegi-------------------------------------
class Factorial:
    def __init__(self, MOD):
        self.MOD = MOD
        self.factorials = [1, 1]
        self.invModulos = [0, 1]
        self.invFactorial_ = [1, 1]

    def calc(self, n):
        if n <= -1:
            print("Invalid argument to calculate n!")
            print("n must be non-negative value. But the argument was " + str(n))
            exit()
        if n < len(self.factorials):
            return self.factorials[n]
        nextArr = [0] * (n + 1 - len(self.factorials))
        initialI = len(self.factorials)
        prev = self.factorials[-1]
        m = self.MOD
        for i in range(initialI, n + 1):
            prev = nextArr[i - initialI] = prev * i % m
        self.factorials += nextArr
        return self.factorials[n]

    def inv(self, n):
        if n <= -1:
            print("Invalid argument to calculate n^(-1)")
            print("n must be non-negative value. But the argument was " + str(n))
            exit()
        p = self.MOD
        pi = n % p
        if pi < len(self.invModulos):
            return self.invModulos[pi]
        nextArr = [0] * (n + 1 - len(self.invModulos))
        initialI = len(self.invModulos)
        for i in range(initialI, min(p, n + 1)):
            next = -self.invModulos[p % i] * (p // i) % p
            self.invModulos.append(next)
        return self.invModulos[pi]

    def invFactorial(self, n):
        if n <= -1:
            print("Invalid argument to calculate (n^(-1))!")
            print("n must be non-negative value. But the argument was " + str(n))
            exit()
        if n < len(self.invFactorial_):
            return self.invFactorial_[n]
        self.inv(n)  # To make sure already calculated n^-1
        nextArr = [0] * (n + 1 - len(self.invFactorial_))
        initialI = len(self.invFactorial_)
        prev = self.invFactorial_[-1]
        p = self.MOD
        for i in range(initialI, n + 1):
            prev = nextArr[i - initialI] = (prev * self.invModulos[i % p]) % p
        self.invFactorial_ += nextArr
        return self.invFactorial_[n]


class Combination:
    def __init__(self, MOD):
        self.MOD = MOD
        self.factorial = Factorial(MOD)

    def ncr(self, n, k):
        if k < 0 or n < k:
            return 0
        k = min(k, n - k)
        f = self.factorial
        return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD
#--------------------------------------iye ha combinations ka zindegi---------------------------------
def powm(a, n, m):
    if a == 1 or n == 0:
        return 1
    if n % 2 == 0:
        s = powm(a, n // 2, m)
        return s * s % m
    else:
        return a * powm(a, n - 1, m) % m
#--------------------------------------iye ha power ka zindegi---------------------------------
def sort_list(list1, list2):
    zipped_pairs = zip(list2, list1)

    z = [x for _, x in sorted(zipped_pairs)]

    return z
#--------------------------------------------------product----------------------------------------
def product(l):
    por=1
    for i in range(len(l)):
        por*=l[i]
    return por
#--------------------------------------------------binary----------------------------------------
def binarySearchCount(arr, n, key):
    left = 0
    right = n - 1

    count = 0

    while (left <= right):
        mid = int((right + left) / 2)

        # Check if middle element is
        # less than or equal to key
        if (arr[mid] <= key):

            # At least (mid + 1) elements are there
            # whose values are less than
            # or equal to key
            count = mid + 1
            left = mid + 1

        # If key is smaller, ignore right half
        else:
            right = mid - 1

    return count
#--------------------------------------------------binary----------------------------------------
def countdig(n):
    c=0
    while(n>0):
        n//=10
        c+=1
    return c
def countGreater(arr, n, k):
    l = 0
    r = n - 1

    # Stores the index of the left most element
    # from the array which is greater than k
    leftGreater = n

    # Finds number of elements greater than k
    while (l <= r):
        m = int(l + (r - l) / 2)

        # If mid element is greater than
        # k update leftGreater and r
        if (arr[m] > k):
            leftGreater = m
            r = m - 1

        # If mid element is less than
        # or equal to k update l
        else:
            l = m + 1

    # Return the count of elements
    # greater than k
    return (n - leftGreater)
#--------------------------------------------------binary----------------------------------------
x,n=map(int,input().split())
l=[]
if n!=0:
    l=list(map(int,input().split()))
l=set(l)
mi=999999999999999999999999
ans=0
for i in range(-200,201):
    if i not in l:
        if abs(i-x)<mi:
            mi=abs(i-x)
            ans=i
print(ans)

Submission status: Accepted

Solution code:
X,N = map(int, input().split())
p = set(map(int, input().split()))
for i in range(102):
    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:
#!/usr/bin/env python3
x, n, *p = map(int, open(0).read().split())
r = [i for i in range(102) if i not in p]
print(sorted(r, key = lambda y: abs(x - y))[0])

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
if n == 0:
  print(x)
  exit()
lis = list(map(int,input().split()))
ans = 100000000000
num = 0
for i in range(102):
    if i not in lis:
        if ans > abs(i-x):
            ans = abs(i-x)
            num = i
print(num)

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
P = list(map(int, input().split()))
ans = 200
num = 0
for i in range(0, 102):
  if i not in P:
    if(ans > abs(i-X)):
      ans = abs(i-X)
      num = i
    
print(num)

Submission status: Accepted

Solution code:
X,N=map(int,input().split())
P=list(map(int,input().split()))
if X not in P:
    print(X)
    exit()
for i in range(1,100):
    if X-i not in P:
        print(X-i)
        exit()
    elif X+i not in P:
        print(X+i)
        exit()

Submission status: Accepted

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

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

x,n = mp()
p = lmp()
for i in range(200):
    if x - i not in p:
        print(x-i)
        exit()
    elif x + i not in p:
        print(x + i)
        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, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_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

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

s = set(p)

mi = INF
ans = None
for i in range(-1, 110):
	if i in s:
		continue
	if abs(X-i) < mi:
		mi = abs(X-i)
		ans = i
print(ans)

Submission status: Accepted

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

temp=0
if n==0:
    print(x)
    exit()
P=list(map(int,input().split())) 
   
while True:
    if not x-temp in P:
        print(x-temp)
        exit()
    if not x+temp in P:
        print(x+temp)
        exit()
    temp+=1

Submission status: Accepted

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

if x not in plst:
    print(x)
    exit()
minus = x
plus = x
while 1:
    minus -= 1
    if minus not in plst:
        print(minus)
        exit()
    plus += 1
    if plus not in plst:
        print(plus)
        exit()

Submission status: Accepted

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


def main():
    X, N = map(int, readline().rstrip().split())
    P = set(map(int, readline().rstrip().split()))

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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


ans = 0
check = 100000000000000000000000
for i in range(-100,201):
    if i in p:pass
    else:
        if check > abs(x-i):
            ans = i
            check = abs(x-i)

print(ans)

Submission status: Accepted

Solution code:
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# import numpy as np
sys.setrecursionlimit(int(pow(10,6)))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]



x,n=l()
p=l()
m=100000000
idx=0
for i in range(-100,201):
    if i not in p:
        if(abs(x-i)<m):
            m=abs(x-i)
            idx=i
print(idx)

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
P = set(map(int, input().split()))
ans = 0
for i in range(1000):
    if not X-i in P:
        ans = X-i
        break
    if 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()))
s = set(p)
d = 10**5

for i in range(102):
    if i not in s:
        if abs(x-i) < d:
            ans = i
            d = abs(x-i)
print(ans)

Submission status: Accepted

Solution code:
import bisect
x,n=map(int,input().split())
p = sorted(map(int,input().split()))
i = 0
judge = 0

while judge != 1:
    if x-i not in p:
        ans = x-i
        judge = 1
        break
    if x+i not in p:
        ans = x+i
        judge = 1
    i += 1

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from sys import exit

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

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

for i in range(10000000):
  f = True
  if x-i in p:
    f = False
  if f:
    print(x-i)
    exit()
  if x+i in p:
    continue
  print(x+i)
  exit()

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
if n == 0:
    print(x)
    exit()
for i in range(100):
    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:
X, N = map(int, input().split())

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

maxP = 0
minP = 0

setP = set(P)

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

Submission status: Accepted

Solution code:
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
# def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  x,n=LI()
  l=LI()

  sa=inf
  ans=inf
  for i in range(-10,200):
    if i in l:
      continue

    _sa=abs(x-i)
    if _sa<sa:
      sa=_sa
      ans=i

  return ans

# main()
print(main())

Submission status: Accepted

Solution code:
X,N=map(int,input().split())
if N==0:
    print(X)
else:
    p=list(map(int,input().split()))
    d=set()
    for P in p:
        d.add(P)
    ans=0
    dmin=100
    for i in range(200):
        if i not in d:
            if abs(X-i)<dmin:
                dmin=abs(X-i)
                ans=i
    print(ans)

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
ar=[int(i) for i in input().split()]
arr=[i for i in range(0,1000) if i not in ar]
arr.sort()
mini=10000000
for i in arr:
    if abs(i-x)<mini:
        mini=abs(i-x)
        ans=i 
print(ans)

Submission status: Accepted

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

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

    if X+i not in ps:
        print(X+i)
        exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, 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 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

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

P.sort()
# print(P)

# for p in P:
#     if 
i = 0
while 1:
    left = X - i
    if left not in P:
        print(left)
        exit()
    right = X + i
    if right not in P:
        print(right)
        exit()
    i += 1

Submission status: Accepted

Solution code:
X, N, *P = map(int, open(0).read().split())

p = set(P)
diff = 100
ans = 0
for i in reversed(range(-1, 105)):
    if i not in p and abs(i - X) <= diff:
        ans = i
        diff = abs(i - X)
        
print(ans)

Submission status: Accepted

Solution code:
def main():
    x, n = map(int, input().split())
    p = list(map(int, input().split()))
    ans = 10**18
    tmp = abs(ans  - n)
    p = set(p)
    for i in range(-1000, 1001):
        if i in p:
            continue
        buf = abs(i - x)
        if buf < tmp:
            ans = i
            tmp = buf
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    import sys
    X,N=list(map(int,sys.stdin.readline().split()))
    P=list(map(int,sys.stdin.readline().split()))
    if not P:
        print(X)
        return
        
    P.sort()
    diff=10**5
    cand=0
    for i in range(min(X,min(P))-1,max(X,max(P))+2):
        if i not in P:
            d=abs(X-i)
            if d<diff:
                diff=d
                cand=i
    print(cand)


main()

Submission status: Accepted

Solution code:
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))

x,n = iim()
p = set(iil())
for i in range(100):
    if x-i not in p:
        print(x-i)
        exit()
    elif x+i not in p:
        print(x+i)
        exit()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys; input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

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

#処理内容
def main():
	X, N = getlist()
	P = getlist()
	P = sorted(P)
	ans = None
	dif = INF
	for i in range(102):
		if not (i in P):
			if abs(X - i) < dif:
				ans = i
				dif = abs(X - i)

	print(ans)

if __name__ == '__main__':
	main()

Submission status: Accepted

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

ret = 0
diff = 10 ** 9

if n == 0:
    s = input()
    print(x)
    exit()
else:
    p = set(list(map(int, input().split())))
    for i in range(102):
        if i in p:
            continue
        else:
            tmp_d = abs(x - i)
            if diff > tmp_d:
                ret = i
                diff = tmp_d

print(ret)

Submission status: Accepted

Solution code:
import sys
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(rs())
def rs_(): return [_ for _ in rs().split()]
def ri_(): return [int(_) for _ in rs().split()]

X, N = ri_()
p = ri_()
d = 1000
ans = 1000
for i in range(-500, 501):
    f = 1
    for pi in p:
        if i == pi:
            f = 0
    if f == 1 and d > abs(X - i):
        d = abs(X - i)
        ans = i
print(ans)

Submission status: Accepted

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

for i in range(10**9):
    if (X-i) in A:
        pass
    else:
        print(X-i)
        exit()
    if (X+i) in A:
        pass
    else:
        print(X+i)
        exit()

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline

x,n,*p = map(int,read().split())

p = set(p)

v = x
for i in range(1000):
    if v+i not in p:
        break
v = v+i

w = x
for i in range(1000):
    if w-i not in p:
        break
w = w-i

if abs(v-x) < abs(w-x):
    print(v)
else:
    print(w)

Submission status: Accepted

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

Submission status: Accepted

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

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

flag = True
i=1
while flag:
    if not x-i in plis:
        print(x-i)
        exit()
    elif not x+i in plis:
        print(x+i)
        exit()
    else:
        i += 1

Submission status: Accepted

Solution code:
import sys
x, n = map(int, input().split())
if n == 0:
  print(x)
  sys.exit()
p = [int(x) for x in input().split()]
p.sort()
q = len(p)
index = 0
ans = -1
count = 101
for i in range(0, 102):
  if index < q and p[index] == i:
    index += 1
    continue
  if count > abs(i-x):
    count = abs(i-x)
    ans = i
print(ans)

Submission status: Accepted

Solution code:
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    x,n=map(int,readline().split())
    a=list(map(int,readline().split()))
    s=set(a)

    ans_1=x
    ans_2=x
    while True:
        if ans_1 not in s:
            print(ans_1)
            break
        elif ans_2 not in s:
            print(ans_2)
            break
        else:
            ans_1-=1
            ans_2+=1

if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    x, n = map(int, readline().split())
    p = list(map(int, readline().split()))

    ans = 1000000

    for i in range(101, -100, -1):
        if i in p:
            continue
        else:
            diff = abs(x-i)
            if diff <= abs(x-ans):
                ans = i
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python
from __future__ import division, print_function

import os
import sys
import itertools
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip


def main():
    x, n = map(int, input().split())
    p = {int(pi) for pi in input().split()}

    for i in itertools.count():
        if (x - i) not in p:
            print(x - i)
            break
        if (x + i) not in p:
            print(x + i)
            break


# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()


if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

input = lambda: sys.stdin.readline().rstrip("\r\n")

# endregion

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
p.sort()
q = []
for i in range(102):
	if i not in p:
		q.append(i)
q.sort(key=lambda z: abs(z-x))
if len(q) < 2:
	print(q[0])
else:
	if abs(q[0] - x) == abs(q[1] - x):
		print(min(q[0], q[1]))
	else:
		print(q[0])

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 _ in range(102)]

tmp = 10**5
res = 0

for i in range(N):
    a[P[i]] += 1

for i in range(102):
    if a[i]:
        continue
    if tmp > abs(i - X):
        tmp = abs(i - X)
        res = i
print(res)

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
p = [int(i) for i in input().split()]
for i in range(150):
    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:
    p = list(map(int, input().split()))
else:
    p = []

for i in range(101):
    ans = X - i
    if ans not in p: break
    ans = X + i
    if ans not in p: break
    
print(ans)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    X, N = map(int, rl().split())
    p = set(map(int, rl().split()))
    
    ans = -1
    d_min = 1000
    for i in range(102):
        if i not in p:
            if abs(X - i) < d_min:
                d_min = abs(X - i)
                ans = i
    print(ans)


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
s=1000
ret=-1000
x,n=map(int,input().split())
if n==0:
	print(x)
	exit()
p=list(map(int,input().split()))
p=set(p)
for i in range(-101,202):
	if i not in p:
		if s>abs(x-i):
			s=abs(x-i)
			ret=i
print(ret)