Problem:


Score : 300 points

Problem Statement

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

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

Constraints

1 \leq X \leq 100

0 \leq N \leq 100

1 \leq p_i \leq 100

p_1, \ldots, p_N are all distinct.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

X N
p_1 ... p_N

Output

Print the answer.

Sample Input 1

6 5
4 7 10 6 5

Sample Output 1

8

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

Sample Input 2

10 5
4 7 10 6 5

Sample Output 2

9

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

Sample Input 3

100 0

Sample Output 3

100

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



Sample input:
6 5
4 7 10 6 5


Sample output:
8

Submission status: Accepted

Solution code:
import sys

(x, n) = list(map(int, input().split()))
arr = list(map(int, input().split()))

if(len(arr) == 0):
    print(x)
    sys.exit()

if(not(x in arr)):
    print(x)
    sys.exit()

i = 1
while True:
    if(not (x - i in arr)):
        print(x - i)
        sys.exit()
    
    if(not (x + i in arr)):
        print(x + i)
        sys.exit()
    i += 1

Submission status: Accepted

Solution code:
x,n=map(int, input().split())
p=list(map(int, input().split()))
koho=[]
abmi=1000
for a in range(101):
    koho.append(x-50+a)
for a in p:
    if a in koho:
        koho.remove(a)
for a in koho:
    ab=abs(a-x)
    if ab<abmi:
        abmi=ab
        ans=a
print(ans)

Submission status: Accepted

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

l = x
while True:
    if l in p:
        l += 1
    else:
        break

r = x
while True:
    if r in p:
        r -= 1
    else:
        break

if abs(x-l) < abs(x-r):
    print(l)
else:
    print(r)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
[X,N]=list(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
    else:
        continue

Submission status: Accepted

Solution code:
import sys
import copy
from collections import deque
stdin = sys.stdin

mod = 10**9+7

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

x, n = na()
p = na()

res = 0
for i in range(102):
    if abs(i-x)<abs(res-x):
        if not i in p:
            res = i


print(res)

Submission status: Accepted

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

m = x
ans = 0

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

print(ans)

Submission status: Accepted

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

if N == 0:
    print(X)
    exit()
ans = None
plus = 0
while True:
    if X - plus not in P:
        ans = X-plus
        break
    elif X + plus not in P:
        ans = X + plus
        break
    plus += 1

print(ans)

Submission status: Accepted

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

for j in range(100):
    a1=x-j
    a2=x+j
    if a1 not in p:
        print(a1)
        exit()
    if a2 not in p:
        print(a2)
        exit()

Submission status: Accepted

Solution code:
X,N=map(int,input().strip().split())
if N>=1:
    P=list(map(int,input().strip().split()))
else:
    P=[]

Y=X
while X in P and Y in P:
        X+=1
        Y-=1

if  Y not in P:
    print(Y)
else:
    print(X)

Submission status: Accepted

Solution code:
num=[i for i in range(-100,201)]
X,N=list(map(int,input().split()))
p=list(map(int,input().split()))
for i in p:
    if i in num:
        num.remove(i)
min=[1000,0]
for i in num:
    if abs(i-X)<min[0]:
        min=[abs(i-X),i]
print(min[1])

Submission status: Accepted

Solution code:
from sys import stdin
from copy import deepcopy
from functools import reduce
from fractions import gcd
import math
import itertools
from collections import Counter
from itertools import chain  ##list(chain.from_iterable(l)) ##flatten
from heapq import heappush, heappop
import bisect


"""
N = int(input())
A, B = map(int,input().split())
A = list(map(int,input().split())) ## 横一列
A = [int(input()) for _ in range(N)] ## 縦一列
lst = [list(map(int,input().split())) for i in range(M)] ## 二次元
"""


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

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

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

  
current = 10000 ## big number
ans = 0
for i in range(0, 102):
  if i in P:
    continue
  else:
    var = abs(i - X)
    if current > var:
      current = var
      ans = i
    #print(i, var, ans)
    
print(ans)

Submission status: Accepted

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

for i in range(x,x+200):
    if i not in a:
        ans1=i
        break
for i in range(x,x-200,-1):
    if i not in a:
        ans2=i
        break
if abs(ans1-x)>=abs(ans2-x):
    print(ans2)
else:
    print(ans1)

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import bisect_right
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
from copy import deepcopy
from decimal import Decimal
alf = list("abcdefghijklmnopqrstuvwxyz")
ALF = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
#import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
X,N = map(int,input().split())
if N == 0:
    print(X)
else:

    d = defaultdict(int)
    p = list(map(int,input().split()))
    for i in range(N):
        d[p[i]] += 1
    mmin = 0
    Mmin = 101
    for i in range(X):
        if d[i] == 0:
            mmin = i
    for i in range(X,102):
        if d[i] == 0:
            Mmin = i
            break
    a = X-mmin
    b = Mmin-X
    if a == b or a < b:
        print(mmin)
    else:
        print(Mmin)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
diff = 101 - x
ans = 101
for i in range(-1, 101):
    if i in p:
        continue
    if abs(i - x) < diff:
        diff = abs(i - x)
        ans = i
    elif abs(i - x) == diff:
        ans = min(ans, i)
print(ans)

Submission status: Accepted

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

lst = [(abs(i - X), i) for i in range(0, 102)]
lst.sort()

for a, b in lst:
    if b not in P:
        print(b)
        exit()

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = set(map(int, input().split()))
if n != 0:
    p_all = set([i for i in range(min(p) - 1, max(p) + 2)])
    q = list(p_all - p)
    q.sort(reverse=True)
    d = float('inf')
    for i in q:
        tmp = abs(i - x)
        if tmp <= d:
            d = tmp
            ans = i
else:
    ans = x
print(ans)

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
P = list(map(int, input().split()))
l, r = 0, 0
for i in range(0, X+1):
    if not i in P:
        l = i
for i in range(101, X, -1):
    if not i in P:
        r = i
if abs(X-l) <= abs(X-r):
    print(l)
else:
    print(r)

Submission status: Accepted

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

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

for i in range(100 + 2):
    if not(i in p):
        if abs(x - i) < abs(x - min_num):
            min_num = i

print(min_num)

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(101):
    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:
def input_int():
    return map(int, input().split())

def one_int():
    return int(input())

def one_str():
    return input()

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



X, N = input_int()

P=many_int()

from collections import defaultdict
dicts = defaultdict(bool)
for p in P:
    dicts[p] = True



def serach(X, dicts):
    for i in range(100):
        min_val =X-i
        max_val = X+i
        
        if (not dicts[min_val]):
            return min_val
        if (not dicts[max_val]):
            return max_val
            



if X not in P:
    print(X)
else:
    print(serach(X, dicts))

Submission status: Accepted

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

arr.sort()

if x not in arr:
    print(x)
    sys.exit()

ans = 1000
cnt = 0
while True:
    lower = x - cnt
    upper = x + cnt
    if lower not in arr:
        ans = min(ans, lower)
    if upper not in arr:
        ans = min(ans, upper)
    if ans != 1000:
        break
    cnt += 1

print(ans)

Submission status: Accepted

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

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

    mi = 200
    for i in range(102):
        if not i in p:
            d1 = abs(x-i)
            if d1<mi:
                ans = i
                mi = min(d1,mi)
    print(ans)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
p = list(map(int, input().split()))
for i in range(150):
    if p.count(x + i) == 0 and p.count(x - i) == 0:
        print(min(x + i, x - i))
        break
    elif p.count(x + i) == 0:
        print(x + i)
        break
    elif p.count(x - i) == 0:
        print(x - i)
        break
    else:
        continue

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main(X, N, P):
    st = set(P)
    if N == 0:
        print(X)
    else:
        n = 0
        while True:
            if X - n not in st:
                print(X - n)
                exit()
            elif X + n not in st:
                print(X + n)
                exit()
            else:
                n += 1

if __name__ == '__main__':
    X, N = list(map(int, input().split()))
    P = list(map(int, input().split()))
    main(X, N, P)

Submission status: Accepted

Solution code:
#import numpy as np
#import math

X, N = map(int, input().split())
if N != 0:
    P = list(map(int, input().split()))
    # a,b=map(int, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
    # c=list(map(int, input().split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき
    # s=[list(map(int,list(input()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき
    
    #K = int(input())
    #S = input()
    
    ##一次元配列の初期化
    #a=[0]*5
    #[i for i in range(100) if i%2==1] #奇数のみ
    ##二次元配列の初期化
    #[[float("inf") for i in range(N)] for i in range(N)]
    
    for diff in range(0,102):
        if X-diff not in P:
            print(X-diff)
            break
        elif X+diff not in P:
            print(X+diff)
            break
else:
    print(X)

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()
p.sort()
for i in range(n):
  if p[i] == x:
    d = i
j = 1
while True:
  if d-j < 0:
    print(x-j)
    exit()
  if p[d-j] != x-j:
    print(x-j)
    exit()
  if d+j > n-1:
    print(x+j)
    exit()
  if p[d+j] != x+j:
    print(x+j)
    exit()
  j += 1

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, n+1):
        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())
N = list(map(int, input().split()))

for i in range(101):
    if not(x-i in N):
        ans=x-i
        break
    if not(x+i in N):
        ans=x+i
        break

print(ans)

Submission status: Accepted

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

for i in range(100):
    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:
  P = list(map(int, input().split()))
  c_list = []
  for p in P:
    if p-1 not in P:
      c_list.append(p-1)
    if p+1 not in P:
      c_list.append(p+1)
  c_list.sort()
  ans = c_list[0]
  for c in c_list:
    if abs(c-X) < abs(ans-X):
      ans = c
  print(ans)

Submission status: Accepted

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

a=[(abs(x-X),x) for x in xn]

for d in range(0, 100):
    a1=d+X
    a2=-d+X
    if a2 not in xn:
        print(a2)
        exit(0)
    elif a1 not in xn:
        print(a1)
        exit(0)

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
if n==0:
  print(x)
  exit()
A=set(map(int,input().split()))
for i in range(100):
  if x+i not in A:
    a=x+i
    break
for i in range(100):
  if x-i not in A:
    b=x-i
    break

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

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(200):
    for sgn in [-1, 1]:
        cand = X + sgn * i
        if cand not in p:
            print(cand)
            exit()

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
p=list(map(int,input().split()))
t=[]
a=x-1
b=x+1
if x not in p:
  t.append(x)

while t==[]:
  if a not in p:
    t.append(a)
  if b not in p:
    t.append(b)
  a-=1
  b+=1
print(min(t))

Submission status: Accepted

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

if n==0 or x not in p:
    print(x)
else:
    i = 1
    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()))

for i in range(101):
  if not x-i in p :
    print(x-i)
    exit()
  elif not  x+i in p:
    print(x+i)
    exit()

Submission status: Accepted

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

a=[0]*102
for i in range(n):
    a[p[i]]+=1
l=x
s=x
while True:
    if a[s]==0:
        ans=s
        break
    s-=1
    if a[l]==0:
        ans=l
        break
    l+=1
    
print(ans)

Submission status: Accepted

Solution code:
X,N = map(int,input().split())
P = set(list(map(int,input().split())))
reverseP = []
for i in range(102):
    if i not in P:
        reverseP.append(i)
ans = 0
diff = float("INF")
for a in reverseP:
    if abs(a-X)<diff:
        ans = a
        diff = abs(a-X)
print(ans)

Submission status: Accepted

Solution code:
x,n = map(int, input().split())
l = list(map(int, input().split()))
d = {}
for i in l:
    if i not in d:
        d[i] = 1
left, right = x,x
while left in d and right in d:
    left -= 1
    right += 1
print(left if left not in d else right)

Submission status: Accepted

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

if N!=0:

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

    B = X
    S = X

    while True:
        #print(B,S)
        if P.count(S) == 0:
            print(S)
            break
        elif P.count(B) == 0:
            print(B)
            break
        S -= 1
        B += 1

else:
    print(X)

Submission status: Accepted

Solution code:
def main():
  x, n = map(int, input().split())
  if n:
    p = list(map(int, input().split()))
    i = 0
    while True:
      if not x-i in p:
        print(x-i)
        break
      elif not x+i in p:
        print(x+i)
        break
      i += 1
  else:
    print(x)
      
if __name__ == "__main__":
  main()

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()
    # 左
    left = p
    for i in range(x, -100, -1):
        if i not in p:
            left = i
            break
    # 右
    right = p
    for i in range(x, 110):
        if i not in p:
            right = i
            break

    leftabs = abs(x - left)
    rightabs = abs(right - x)

    if leftabs == rightabs:
        print(left)
    elif leftabs > rightabs:
        print(right)
    else:
        print(left)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
X,N=map(int,input().split())
if N!=0:
  P=list(map(int,input().split()))
else:
  P=[]
if X not in P:
  print(X);exit()

r=1000
ans=0
for i in range(200,-200,-1):
  if i not in P:
    if r>=abs(i-X):
      r=abs(i-X)
      ans=i
print(ans)

Submission status: Accepted

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

p_s.sort()
ans = 0
tmp_diff = float('inf')

for num in range(-300,301):
    if(num not in p_s):
        diff = abs(X - num)
        if (diff < tmp_diff):
            ans = num
            tmp_diff = diff
            
print(ans)

Submission status: Accepted

Solution code:
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
# from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
# from statistics import mean,median,mode

INF = float("inf")

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

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

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

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

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

def MS():
    return input().split()

def RS():
    return list(input().split())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input().split()) for _ in range(n) ]

x,n = MI()
p = RI()

m = INF
ans = INF
for i in range(-102,102):
    if i in p:
        pass
    else:
        sa = abs( x - i )
        if sa<m:
            ans = i
            m = sa
        elif sa==m:
            ans = min(i,ans)
        else:
            pass
print(ans)

Submission status: Accepted

Solution code:
import sys
X,N = map(int,input().split())
if N == 0:
	print(X)
	sys.exit()
P = list(map(int,input().split()))
i = 0
while True:
	if not X-i in P:
		print(X-i)
		break;
	if not X+i in P:
		print(X+i)
		break;
	i += 1

Submission status: Accepted

Solution code:
x,y=map(int,input().split())
if y==0:
    print(x)
    exit(0)
s=list(map(int,input().split()))
res=100
mn=110
for n in range( 110):
    if n not in s:
        v=abs(x-n)
        if v<res:
            res=v
            mn=n

print(mn)

Submission status: Accepted

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

mi = 1000
ans = -1
for i in range(-1, 105):
    if i not in P:
        if mi > abs(X - i):
            mi = abs(X - i)
            ans = i
print(ans)

Submission status: Accepted

Solution code:
import sys
X,N =  map(int,input().split())
if N == 0:
  print(X)
  sys.exit()
p = list( map(int,input().split()))
gans = X
gx = X
lans = X
lx = X
for i in range(100+1):
  if gx not in p:
    gans = gx
    break
  else:
    gx += 1
for i in range(100+1):
  if lx not in p:
    lans = lx
    break
  else:
    lx -= 1

if abs(X-gans) < abs(X-lans):
  print(gans)
else:  
  print(lans)

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
pn = list(map(int, input().split()))
diff = 100
ans = X
if pn:
    for i in range(min(pn)-1, max(pn)+2):
        if i in pn:
            continue
        if abs(X-i) < diff:
            diff = abs(X-i)
            ans = i
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7


#############
# Main Code #
#############

X, N = getNM()
P = sorted(getList())
P = set(P)

for i in range(500):
    opt1 = X + i
    ans = []
    if not opt1 in P:
        ans.append(opt1)
    opt2 = X - i
    if not opt2 in P:
        ans.append(opt2)
    if len(ans) > 0:
        print(min(ans))
        break

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
s=input()
if n!=0:
  l=list(map(int,s.split()))
  cnt=0
  ans=0
  while True:
    if x-cnt in l:
      if x+cnt in l:
        cnt=cnt+1
      else:
        ans=x+cnt
        break
    else:
      ans=x-cnt
      break
  print(ans)
else:
  print(x)

Submission status: Accepted

Solution code:
# 2108
# 解法,せいぜい１００何だから範囲を増やしつつ全探索でいいのでは？
# 実装， 範囲をiとしてiを100まで買えつつX-iとX+iについて，Pにあるかを判定してなければそれが答えになる
X, N = map(int,input().split())
P = list(map(int,input().split()))
P = set(P)

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:
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
# from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np
# from numpy import cumsum  # accumulate

def solve():
    X, N = MI()
    P = LI()

    ans = X
    if P == []:
        print(ans)
        return

    #
    # P = [i for i in range(1, 99)]
    # N = 100
    # X = 50

    mn = INF
    for i in range(X-110, X+110):
        # if i == X: continue
        if i not in P:
            if mn > abs(X - i):
                mn = abs(X - i)
                ans = i
            # print(i, abs(X - i), ans)
    print(ans)

if __name__ == '__main__':
    solve()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
ps=list(map(int,input().split()))
i=0
while 1:
    m=x-i
    if not m in ps:
        print(m)
        exit()
    p=x+i
    if not p in ps:
        print(p)
        exit()
    i+=1

Submission status: Accepted

Solution code:
###################################################
#                                                 #
#   author: raghav_0901 (Raghav Dalmia)           #
#   updated on: Sunday, 14-06-2020, 17:43:43 pm   #
#                                                 #
###################################################

from math import *


def _in():
    return [int(x) for x in input().split(' ')]


def main():
    x, n = _in()
    if(n == 0):
        print(x)
        return
    arr = _in()

    diff = 0
    while(True):
        l = x - diff
        if not(l in arr):
            print(l)
            return
        r = x + diff
        if not(r in arr):
            print(r)
            return
        diff = diff + 1


if __name__ == "__main__":
    tt = 1
    # tt = int(input())
    for _ in range(tt):
        main()

Submission status: Accepted

Solution code:
x,N=list(map(int,input().split()))
if N==0:
    print(x)
else:
    ps=list(map(int,input().split()))
    n=[0]*300

    for p in ps:
        n[p+100]+=1
    if n[x+100]==0:
        print(x)
    else:
        ans=0
        for i in range(1,200):
            if n[x-i+100]==0:
                ans=x-i
                break
            elif n[x+i+100]==0:
                ans=x+i
                break
        print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Jun 14 21:08:40 2020

@author: NEC-PCuser
"""

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
X,N=input().split()
P=list(map(int, input().split()))
X=int(X)
N=int(N)
a1=X
a2=X
while (a1 in P)and(a2 in P):
    a1-=1
    a2+=1
if a1 in P:
    print(a2)
elif a2 in P:
    print(a1)
else:
    print(a1)

Submission status: Accepted

Solution code:
import sys


x, n = map(int, input().split())
p = {int(i): True for i in input().split()}

i = 0

while True:
    try:
        if p[x-i]:
            pass
            
    except KeyError:
        print(x-i)
        sys.exit()
    
    try:
        if p[x+i]:
            pass
    except KeyError:
        print(x+i)
        sys.exit()
    
    i += 1

Submission status: Accepted

Solution code:
from sys import exit
x, n = map(int, input().split())
if n == 0:
  print(x)
  exit()
ban = set(map(int, input().split()))
diff = 200
for i in range(102):
  if i in ban:
    continue
  if abs(x - i) < diff:
    diff = abs(x - i)
    ans = i
print(ans)

Submission status: Accepted

Solution code:
"""
~~ Author : Bhaskar
~~ Dated : 07~06~2020
"""

import sys
from bisect import *
from math import floor,sqrt,ceil,factorial as F,gcd,pi,log
from itertools import chain,combinations,permutations,accumulate
from collections import Counter,defaultdict,OrderedDict,deque
from array import array
INT_MAX = sys.maxsize
INT_MIN = -(sys.maxsize)-1
mod = 1000000007
ch = "abcdefghijklmnopqrstuvwxyz"
lcm = lambda a,b : (a*b)//gcd(a,b)
setbit = lambda x : bin(x)[2:].count("1")

def solve():
    x,n = map(int,sys.stdin.readline().split())
    a = list(map(int,sys.stdin.readline().split()))
    if n == 0:
        print(x)
    else:
        a.sort()
        ans = []
        for i in range(150):
            if i not in a:
                ans.append(i)
        ans.sort(key = lambda i : abs(x-i))
        print(ans[0])




if __name__ == "__main__":
    # try:
    #     sys.stdin = open("input.txt","r")
    # except :
    #     pass
    solve()