Problem:


Score : 300 points

Problem Statement

Given are an integer X and an integer sequence of length N: p_1, \ldots, p_N.

Among the integers not contained in the sequence p_1, \ldots, p_N (not necessarily positive), find the integer nearest to X, that is, find the integer whose absolute difference with X is the minimum. If there are multiple such integers, report the smallest such integer.

Constraints

1 \leq X \leq 100

0 \leq N \leq 100

1 \leq p_i \leq 100

p_1, \ldots, p_N are all distinct.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

X N
p_1 ... p_N

Output

Print the answer.

Sample Input 1

6 5
4 7 10 6 5

Sample Output 1

8

Among the integers not contained in the sequence 4, 7, 10, 6, 5, the one nearest to 6 is 8.

Sample Input 2

10 5
4 7 10 6 5

Sample Output 2

9

Among the integers not contained in the sequence 4, 7, 10, 6, 5, the ones nearest to 10 are 9 and 11. We should print the smaller one, 9.

Sample Input 3

100 0

Sample Output 3

100

When N = 0, the second line in the input will be empty. Also, as seen here, X itself can be the answer.



Sample input:
6 5
4 7 10 6 5


Sample output:
8

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
p = set(map(int, input().split()))
def main():
    if X not in p:
        print(X)
        return
    for i in range((N-1)//2+2):
        if X-i not in p:
            print(X-i)
            break
        elif X+i not in p:
            print(X+i)
            break

main()

Submission status: Accepted

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

i = 0
while True:
    x_i = x - i
    x_j = x + i

    if x_i not in p_list:
        print(x_i)
        exit()
    if x_j not in p_list:
        print(x_j)
        exit()

    i += 1

Submission status: Accepted

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

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

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

n_p = []

for i in range(-1, 102):
    if i in p:
        continue
    else:
        n_p.append(i)


dif = float("inf")
for i in range(len(n_p)):
    if dif > abs(x - n_p[i]):
        dif = abs(x - n_p[i])
        ans = n_p[i]

print(ans)

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
if n != 0:
    p_list = list(map(int,input().split()))
    num_list = []
    num_list.append(x)
    for i in range(1,51):
        num_list.append(x-i)
        num_list.append(x+i)
    flag = True
    for i in num_list:
        if flag == False:
            break
        if i not in p_list:
            ans = i
            flag = False
    print(ans)
else:
    print(x)

Submission status: Accepted

Solution code:
import sys

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

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

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

Submission status: Accepted

Solution code:
x,n=map(int, input().split())
if(n==0):
  print(x)
else:
  hoge=list(map(int, input().split()))
  ans=0
  flag=0
  val=9999
  for i in range(102):
    if(i in hoge):
      flag+=1
    else:
      if(val>abs(x-i)):
        val=abs(x-i)
        ans=i
  print(ans)

Submission status: Accepted

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

res = -1
i=0
while(res==-1):
    check_low = X - i
    if check_low not in p:
        res = check_low
    else:
        check_high = X + i
        if check_high not in p:
            res = check_high
    i += 1

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()))
    over = x
    bellow = x
    while True:
        if not bellow in p:
            print(bellow)
            break
        if not over in p:
            print(over)
            break
        over += 1
        bellow -= 1

Submission status: Accepted

Solution code:
def main():
    X,N = map(int,input().split())
    if N != 0:
        P = list(map(int,input().split()))
        
        p = [i for i in range(-200,200)]
        q = []
        for i in range(N):
            if not P[i] in q:
                p[p.index(P[i])] = 201
                q.append(P[i])
        
        
        ans = abs(X-p[0])
        ans_p = 0
        for i in range(1,len(p)):
            if abs(X-p[i]) < ans \
            or (abs(X-p[i]) == ans and p[i] < ans_p):
                ans = abs(X-p[i])
                ans_p = p[i]
                
        print(ans_p)
        
    else:
        print(X)
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


def S():
    return input().rstrip()


def I():
    return int(input())


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


x, n = MI()
pl = list(MI())

nums = set(list(range(102))) - set(pl)

dmin = 1000000
for p in nums:
    d = abs(x - p)
    if d < dmin:
        temp = []
        temp.append(p)
        dmin = d
    elif d == dmin:
        temp.append(p)

print(min(temp))

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()
judge = [False] * 102
for pi in p:
    judge[pi] = True
now = 1
Flag = False
while not Flag:
    if not judge[X - now]:
        print(X - now)
        Flag = True
    elif not judge[X + now]:
        print(X + now)
        Flag = True
    else:
        now += 1

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
p = list(map(int,input().split()))
p.sort()
b = []
for i in range(0,102):
    if not (i in p):
        b.append((i,abs(i-x)))

b.sort(key=lambda x:x[1])
print(b[0][0])

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
P = list(map(int,input().split()))
A = []
a = 0
for i in range(200):
    if x+a in P:
        a += 1
    else:
        A.append(x+a)
        break
a = -1
for i in range(200):
    if x+a in P:
        a -= 1
    else:
        A.append(x+a)
        break

if abs(x-A[0]) < abs(x-A[1]):
    print(A[0])
    exit()
elif abs(x-A[0]) > abs(x-A[1]):
    print(A[1])
    exit()
else:
    print(min(A[0],A[1]))

Submission status: Accepted

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

m=100100100
ans=-1
for i in range(1000):
    if(i in p):continue
    if(m>abs(i-x)):
        m=abs(x-i)
        ans=i
print(ans)

Submission status: Accepted

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

p.sort()

if X in p:
    ind=p.index(X)
    i=1
    while True:
        if (X-i) in p and (X+i) in p :
            i+=1
        elif (X-i) not in p:
            print(X-i)
            break
        else:
            print(X+i)
            break
else:
    print(X)

Submission status: Accepted

Solution code:
x, n = [int(s) for s in input().split()]
p_set = set([int(s) for s in input().split()])
if x not in p_set:
    print(x)
    exit()
l = x - 1
while l in p_set:
    l -= 1
r = x + 1
while r in p_set:
    r += 1
print(l if abs(x - l) <= abs(x - r) else r)

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
if n != 0:
    p = list(map(int,input().split()))
else:
    p = []
ans = 1000
x1 = x
x2 = x
while ans == 1000:
    if p.count(x1) == 0:
        ans = x1
    if p.count(x2) == 0:
        ans = min(ans,x2)
    x1 += 1
    x2 -= 1
print(ans)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
if n==0:
    print(x)
    exit()
*p, = map(int, input().split())
num = 0
while True:
    if x-num not in p:
        print(x-num)
        exit()
    elif x+num not in p:
        print(x+num)
        exit()
    num += 1

Submission status: Accepted

Solution code:
X, N = (int(i) for i in input().split())  
if N == 0:
  print(X)
  exit()
P = [int(i) for i in input().split()] 

d = 0

while True:
  num = X - d
  if num not in P:
    print(num)
    exit()
    
  num = X + d
  if num not in P:
    print(num)
    exit()
  
  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()))
tmp = []

for i in range(-1, 103):
    if i not in p:
        tmp.append((abs(i - x), i))

print(min(tmp)[1])

Submission status: Accepted

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

d = 10**10
v = 10**10
for i in range(0, 102):
    if i in P:
        continue
    _d = abs(X - i)
    # print('d, _d', d, _d)
    if _d < d:
        d = _d
        v = i
    if _d == d:
        v = min(i, v)
print(v)

Submission status: Accepted

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

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

num = 0

while True:
    if x-num not in forbidden_list:
        print(x-num)
        break

    if x+num not in forbidden_list:
        print(x+num)
        break

    num += 1

Submission status: Accepted

Solution code:
X, N = map(int,input().split())
p = list(map(int,input().split()))
absans = 10 ** 5
ans = 0
for i in range(200):
    if i not in p:
        if absans > abs(X - i):
            ans = i
            absans = abs(X - i)
print(ans)

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
ps = list( map(int,input().split()))
prob = [True]*103

for p in ps:
    prob[p+1] = False

ans = 200

for i in range(102,-1,-1):
    if prob[i]:
        if abs(ans - x) >= abs(i-1-x):
            ans = i-1

print(ans)

Submission status: Accepted

Solution code:
x, n = map(int,input().split())
if n != 0:
  a = list(map(int,input().split()))
b = [i for i in range(-150,150)]
c = 1000

for i in range(n):
    b.remove(a[i])

for i in range(len(b)):
  if abs(b[i] - x) < abs(c - x):
      c = b[i]
  else:
      pass

print(c)

Submission status: Accepted

Solution code:
INF = float("inf")
MOD = 10 ** 9 + 7
# ----------

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

S = set([i for i in range(102)])
S = S - P

ans = -1
diff = INF
for s in sorted(S):
    if abs(s - X) < diff:
        ans = s
        diff = abs(s - X)

print(ans)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
from math import floor, sqrt, factorial, hypot, log  # log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter, defaultdict, deque
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint


def ceil(a, b): return (a + b - 1) // b


inf = float('inf')
mod = 10 ** 9 + 7


def pprint(*A):
    for a in A:     print(*a, sep='\n')


def INT_(n): return int(n) - 1


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


def MF(): return map(float, input().split())


def MI_(): return map(INT_, input().split())


def LI(): return list(MI())


def LI_(): return [int(x) - 1 for x in input().split()]


def LF(): return list(MF())


def LIN(n: int): return [I() for _ in range(n)]


def LLIN(n: int): return [LI() for _ in range(n)]


def LLIN_(n: int): return [LI_() for _ in range(n)]


def LLI(): return [list(map(int, l.split())) for l in input()]


def I(): return int(input())


def F(): return float(input())


def ST(): return input().replace('\n', '')

def main():
    MAX = 10000
    X, N = MI()
    P = LI()
    ans = {}
    for i in range(102):
        ans[i] = i
    for p in P:
        ans[p] = MAX
    answer = MAX
    ab = MAX
    for i in range(102):
        if ans[i] == MAX:
            continue
        if ab > abs(ans[i] - X):
            ab = abs(ans[i] - X)
            answer = i
    print(answer)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

p = list(map(int , input().split()))
ps = set(p)
o = []
for i in range(110):
    if i in ps:
        continue
    o.append(i)

m = 1000
ans = -1
for oi in reversed(o):
    if abs(x - oi) <= m:
        ans = oi
        m = abs(x - oi)

print(ans)

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
p=input().split()
if p.count(str(x))==0:
  print(x)
  exit()
i=1
while True:
 x=x-i
 if p.count(str(x))==0:
  print(x)
  exit()
 x=x+2*i
 if p.count(str(x))==0:
  print(x)
  exit()
 x=x-i
 i=i+1

Submission status: Accepted

Solution code:
X, N = [int(x) for x in input().split()]
P = [int(x) for x in input().split()]
ans = -1
tmp = 1000
for i in range(0, 102):
    if i in P: continue
    if abs(X-i) < tmp:
        ans = i
        tmp = abs(X-i)
print(ans)

Submission status: Accepted

Solution code:
import sys
import os
import itertools
from collections import deque

def main():
    if os.getenv("ENV")=='LOCAL':
        sys.stdin = open(os.path.dirname(__file__)+'/input.txt', 'r')

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

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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


P = list(map(int, input().split()))
A = []
for a in range(-1, 102):
    A.append(a)

for a in P:
    A.remove(a)

if X not in P:
    print(X)
    exit()
else:
    A.append(X)

A.sort()
C = A.index(X)
D = A[C+1]
E = A[C-1]

if D-X == X-E:
    print(E)
elif D-X > X-E:
    print(E)
else:
    print(D)

Submission status: Accepted

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

pp = set(pp)

for i in range(102):
    if not X-i in pp:
        print(X-i)
        exit(0)
    if not X+i in pp:
        print(X+i)
        exit(0)

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
p=list(map(int,input().split()))
p1=list(range(-150,150))
l= set(p) ^ set(p1)

for i in range(150-x):
    if x-i in l:
        print(x-i)
        exit()
    if x+i in l:
        print(x+i)
        exit()

Submission status: Accepted

Solution code:
# C - Forbidden List

X, N = map(int, input().split())
P = list(int(p) for p in input().split())
P = set(P)
INF = 10**18

ans = 0
tmp = INF
for i in range(102):
    if i not in P:
        if abs(i-X) < tmp:
            tmp = abs(i-X)
            ans = i

print(ans)

Submission status: Accepted

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

counter = 0
if n == 0:
    print(x)
else:
    while True:
        if x - counter not in p:
            print(x - counter)
            break
        elif x + counter not in p:
            print(x + counter)
            break
        counter += 1

Submission status: Accepted

Solution code:
def resolve():
    x, n = map(int, input().split())
    P = []
    while 1:
        try:
            k = map(int, input().split())
            P.extend(k)
        except EOFError:
            break

    if P == []:
        print(x)
        return

    P = set(P)

    diff = 0

    while True:
        if not (x - diff in P):
            print(x - diff)
            return
        if not (x + diff in P):
            print(x + diff)
            return
        diff += 1

resolve()

Submission status: Accepted

Solution code:
# 2020/06/14
# AtCoder Beginner Contest 170 - C

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

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

    # Make NG List (1 is NG, 0 is OK)
    nglist = [0] * 102
    for i in range(n):
        nglist[p[i]] = 1

    # Search
    minval = 10000
    ans = -1
    for i in range(0, 102):
        wkmin = abs(x - i)
        if nglist[i] == 0 and wkmin < minval:
            minval = wkmin
            ans = i

# Output
print(ans)

Submission status: Accepted

Solution code:
import math
from collections import deque
from collections import defaultdict
import itertools as it

#自作関数群
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):#階乗
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):#コンビネーション
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def combmod(n,r,mod):
	return (fact(n)/fact(n-r)*pow(fact(r),mod-2,mod))%mod
def printQueue(q):
	r=copyQueue(q)
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.parents = [-1]*n

	def find(self, x): # root
		if self.parents[x]<0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]

	def union(self,x,y):
		x = self.find(x)
		y = self.find(y)

		if x==y:
			return

		if self.parents[x]>self.parents[y]:
			x,y = y,x

		self.parents[x]+=self.parents[y]
		self.parents[y]=x

	def size(self,x):
		return -1*self.parents[self.find(x)]

	def same(self,x,y):
		return self.find(x)==self.find(y)

	def members(self,x): # much time
		root = self.find(x)
		return [i for i in range(self.n) if self.find(i)==root]

	def roots(self):
		return [i for i,x in enumerate(self.parents) if x<0]

	def group_count(self):
		return len(self.roots())

	def all_group_members(self):
		return {r: self.members(r) for r in self.roots()} # 1~n
def bitArr(n):#ビット全探索
	x = 1
	zero = "0"*n
	ans = []
	ans.append([0]*n)
	for i in range(2**n-1):
		ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
		x+=1
	return ans;
def arrsSum(a1,a2):
	for i in range(len(a1)):
		a1[i]+=a2[i]
	return a1
def maxValue(a,b,v):
	v2 = v
	for i in range(v2,-1,-1):
		for j in range(v2//a+1): #j:aの個数
			k = i-a*j
			if k%b==0:
				return i
	return -1
def copyQueue(q):
	nq = queue.Queue()
	n = q.qsize()
	for i in range(n):
		x = q.get()
		q.put(x)
		nq.put(x)
	return nq
def get_sieve_of_eratosthenes(n):
	#data = [2]
	data = [0,0,0]
	for i in range(3,n+1,2):
		data.append(i)
		data.append(0)
	for i in range(len(data)):
		interval = data[i]
		if interval!=0:
			for j in range(i+interval,n-1,interval):
				data[j] = 0
	#ans = [x for x in data if x!=0]
	ans = data[:]
	return ans

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

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

for i in range(1,101):
	l = x-i
	r = x+i
	if l not in p:
		print(x-i)
		exit()
	if r not in p:
		print(x+i)
		exit()

Submission status: Accepted

Solution code:
x, n = map(int,input().split())
if n==0:
  print(x)
else:
  a = input().split(" ")
  lista = [int(n) for n in a]
  for i in range (200):
    for j in range(100):
      if x-j not in lista:
        print(x-j)
        exit()
      if x+j not in lista:
        print(x+j)
        exit()

Submission status: Accepted

Solution code:
x, y = map(lambda x: int(x), input().split(' '))

mass = []

if(y > 0):
    mass = list(map(lambda x: int(x), input().split(' ')))

d = 1000
j = -1

for i in range(0, 102):
    if(not i in mass):
        if(abs(x - i) < d):
            d = abs(x - i)
            j = i

print(j)

Submission status: Accepted

Solution code:
X,N = map(int,input().split())
p = list(map(int,input().split()))
if p == []:
    print(X)
    exit()
for i in range(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:
#!/usr/bin/env python3

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

P2 = []

for i in range(-100, 201):
    if i in P:
        continue
    P2.append(i)
sa = 10**9
ret = -1
for p in P2:
    if abs(X-p) < sa:
        sa = abs(X-p)
        ret = p

print(ret)

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
if n!=0:
  pp=list(map(int,input().split()))
else:
  pp=[]
q=True
r=True
i=0
a=0
b=0
while q:
  if x+i not in pp:
    a=x+i
    q=False
  else:
    i+=1
i=0
while r:
  if x-i not in pp:
    b=x-i
    r=False
  else:
    i+=1  

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

Submission status: Accepted

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

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

_,res = min((abs(X-y),y) for y in range(-1,102) if y not in P)
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(200):
    if i%2==0:
        X+=i
    else:
        X-=i
    if X not in p:
        break
    else:
        continue
print(X)

Submission status: Accepted

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-
x, n = map(int, input().split())
p_list = list(map(int, input().split()))
for i in range(0, n // 2 + 2):
    if x - i not in p_list:
        print(x - i)
        break
    if x + i not in p_list:
        print(x + i)
        break

Submission status: Accepted

Solution code:
X,N=list(map(int, input().split(' ')))
if N>0:
    p=list(map(int, input().split(' ')))
else:
    p=[]
A=0
A2=400
A3=0
for i in range(0,200):
    if i in p:
        v=0
    else:
        A=abs(i-X)
        if A<A2:
            A2=A
            A3=i
        else:
            print(A3)
            exit()

Submission status: Accepted

Solution code:
X, N = list(map(int, input().split()))
p = set(map(int, input().split()))
d = 0
while True:
    x_n = X - d
    x_p = X + d
    if x_n not in p:
        print(x_n)
        break
    elif x_p not in p:
        print(x_p)
        break
    d += 1

Submission status: Accepted

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

d = {i : abs(X - i) * 1000 + i for i in range(-110, 110, 1)}

for p in P:
  if p in d:
    d[p] = 10000000

d = sorted(d.keys(), key=lambda x: d[x])

print(d[0])

Submission status: Accepted

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

ans = None
for r in range(100):
    for i in [-r, r]:
        if (X + i) not in p:
            ans = X+i
            break

    if ans is not None:
        break

print(ans)

Submission status: Accepted

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

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

arr = set(map(int, input().split()))

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

Submission status: Accepted

Solution code:
X,N = map(int,input().split())
import sys
p = list(map(int,input().split()))
if N == 0:
    print(X)
    sys.exit()
    
for i in range(101):  
    tmp_r = 10**9+7
    tmp_l = 10**9+7
    r_flag = 0
    l_flag = 0
    
    if X+i not in p:
        tmp_r = X+i
        r_flag = 1
    if X-i not in p:
        tmp_l = X-i
        l_flag = 1
        
    if r_flag == 1 or l_flag == 1:
        print(min(tmp_r,tmp_l))
        sys.exit()

Submission status: Accepted

Solution code:
x,n = map(int, input().split(" "))
if n == 0:
  print(x)
else:  
  plist = list(map(int, input().split(" ")))
  s = 0
  while x+s in plist and x-s in plist:
    s += 1
  if x-s in plist:
    print(x+s)
  else:
    print(x-s)

Submission status: Accepted

Solution code:
#3問目
X, N = map(int, input().split())
p = list(map(int, input().split()))
p.sort()
resultPlus = X
resultMinus = X
flag = True
if(N == 0):
    print(X)
else:
    if X in p:
        while flag == True:
            resultMinus -= 1
            resultPlus += 1
            if resultMinus not in p:
                flag = False
                print(resultMinus)
                break
            if resultPlus not in p:
                flag = False
                print(resultPlus)
                break
    else:
        print(X)

Submission status: Accepted

Solution code:
data = input().rstrip().split(" ")
X = int(data[0])
N = int(data[1])
if N != 0:
    num = input().rstrip().split(" ")
    number = []
    for i in num:
        number.append(int(i))

    k = 0
    while True:
        if not X-k in number:
            ans = X-k
            break
        else:
            if not X+k in number:
                ans = X+k
                break
        k +=1
else:
    ans = X        
print(ans)

Submission status: Accepted

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

P = set(P)
ans = 0
tmp = 1000000
setlist = range(-1,102)
for ele in setlist:
    if ele in P:
        continue
    if abs(ele-X) < tmp:
        ans = ele
        tmp = abs(ele-X)
    

print(ans)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
s = []
for i in range(202):
    s.append(i)
for i in range(n):
    s.remove(p[i])

for i in range(202):
    if (x-i) in s:
        print(x-i)
        break
    elif (x+i) in s:
        print(x+i)
        break

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
X, N = map(int,input().split())
if N == 0:
  print(X)
else:
  q = list(map(int,input().split()))
  q = list(set(q))
  p = [i for i in range(-2 , 102)]
  for i in range(len(q)):
    p.remove(q[i])

  S = 103
  for i in range(len(p)):
    if abs(X - p[i]) < S :
      ans = p[i]
      S = X - ans
    elif abs(X - p[i]) == S :
      if p[i] < ans :
        ans = p[i]
  print(ans)

Submission status: Accepted

Solution code:
#関数リスト
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

x,n = MI()
mylist = tuple(MI())

num = 0
while True:
    if not(x - num in mylist):
        print(x- num)
        sys.exit()
    if not(x + num in mylist):
        print(x+ num)
        sys.exit()
    num += 1

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
a=[int(i) for i in input().split()]
ans=float("inf")
anss=0
for i in range(-200,200):
    if i not in a:
        if abs(x-i)<ans:
            ans=abs(x-i)
            anss=i
print(anss)

Submission status: Accepted

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

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

mae = x-1
ushiro = x+1
for i in range(n):
    if mae not in p:
        print(mae)
        exit()
    elif ushiro not in p:
        print(ushiro)
        exit()
    mae = mae -1
    ushiro = ushiro +1

Submission status: Accepted

Solution code:
from collections import deque

X, N = map(int, input().split())
p = list(map(int, input().split()))
ans = X
queue = deque()
queue.append(X)
done_list = []
ans = []
while queue:
    var = queue.popleft()
    if var in p:
        done_list.append(var)
        if var - 1 not in done_list:
            queue.append(var-1)
        if var + 1 not in done_list:
            queue.append(var+1)
        continue
    else:
        ans = var
        break
print(ans)

Submission status: Accepted

Solution code:
input = raw_input

exists = [False] * 203

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

inputs = input()
try:
    mid = 101
    ps = map(int, inputs.split(" "))
    for p in ps: 
        if abs(x-p) <= 100:
            diff = p - x
        #print(p, diff)
        exists[mid+diff] = True


    #print("exists", [i for i in range(203) if exists[i]])
    for i in range(0, 102):
        if not exists[mid-i]:
            out = x -i 
            break
        if not exists[mid+i]:
            out = x +i 
            break
except:
    out = x


print(out)

Submission status: Accepted

Solution code:
import numpy as np

X, N = map(int, input().split())
P = set(map(int, input().split()))
Q = set(range(102))
P = np.array(list(Q - P))
Q = np.abs(P - X)
Q = np.where(Q == Q.min())

print(P[Q].min())

Submission status: Accepted

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

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

aln = list(map(lambda y: abs(y-x),al))

if 0 in aln:
    pass
else:
    print(x)
    exit()

for i in range(1,300):
    if aln.count(i) ==2:
        pass
    else:
        if x-i in al:
            print(x+i)
            exit()
        else:
            print(x-i)
            exit()

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
L = list(map(int,input().split()))
ans = 10**10
li = []
for i in range(-200,201):
    if i not in L:
        ans = min(ans,abs(x-i))
        li.append((ans,i))
li.sort()
print(li[0][1])

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()
    mi = 101
    chk = [1 for i in range(0, 102)]
    for i in range(n):
        chk[p[i]] = 0

    for i in range(0, 102):
        if chk[i] == 1:
            if abs(i - x) < mi:
                mi = abs(i - x)
                ans = i
    print(ans)

Submission status: Accepted

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

ans = 0

if N == 0:
  ans = X
else:
  p = list(map(int, input().split()))
  for i in range(1, 102):
    if p.count(i)==0 and abs(ans-X) > abs(i-X):
      ans = i
print(ans)

Submission status: Accepted

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

N_set = set(p)
flag = True
i = 1

if X not in N_set:
    print(X)
    flag = False
while flag:
    if X-i not in N_set:
        print(X-i)
        break
    if X+i not in N_set:
        print(X+i)
        break
    i += 1

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
y = None
if x in p:
    for i in range(102):
        if i in p:
            continue
        if y is None or abs(x - i) < y:
            y = abs(x - i)
            ans = i
else:
    ans = x
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

res = 1000
for i in range(-1, 102):
    if i not in p:
        res = min(res, abs(x - i))

if x - res in p:
    print(x + res)
else:
    print(x - res)