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 = list(map(int, input().split(" ")))
if n!=0:
    p_list = list(map(int, input().split(" ")))
else:
    print(x)
    exit()

p_set = set(p_list)
for i in range(100):
    test_x = x - i;
    if test_x not in p_set:
        print(test_x)
        break
    test_x = x + i;
    if test_x not in p_set:
        print(test_x)
        break

Submission status: Accepted

Solution code:
X,N = list(map(int, input().split()))
try:
  n = list(map(int, input().split()))
except:
  n = []

c = 0
while(1):
  if X-c not in n:
    print(X-c)
    break
  if X+c not in n:
    print(X+c)
    break
  c+=1

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
l=list(map(int,input().split()))
num=[]
for i in range(-100,102):
    num.append(i)
for i in l:
    num.remove(i)
dif=101
ans=[]
for i in num:
    if dif>abs(i-x):
        dif=abs(i-x)
        ans=[i]
    elif dif==abs(i-x):
        ans.append(i)
print(min(ans))

Submission status: Accepted

Solution code:
#デフォルト
import itertools
from collections import defaultdict
import collections
import math
import sys
sys.setrecursionlimit(200000)
mod = 1000000007

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

sub = [False] * 210
for i in range(n):
    sub[p[i] + 105] = True
sub[x] = True

ans = mod
nn = 0
for i in range(210):
    if not sub[i]:
        if ans > abs((i - 105) - x):
            nn = i - 105
            ans = abs((i - 105) - x)
            

print(nn)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

distance = 0
while True:
    if X -distance not in plist:
        print(X-distance)
        break
    if X + distance not in plist:
        print(X+distance)
        break
    distance += 1

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import sys

X, N = map(int, sys.stdin.readline().strip().split())
P = list(map(int, sys.stdin.readline().strip().split()))

i = 0
while True:
    ans = X - i
    if ans not in P:
        break

    ans = X + i
    if ans not in P:
        break

    i += 1

print(ans)

Submission status: Accepted

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

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
import collections
input = sys.stdin.readline

a,b= map(int,input().split())
if b==0:
    print(a)
    sys.exit()
A = list(map(int,input().split()))
for i in range(100):
    if a - i not in A:
        print(a-i)
        sys.exit()
    if a + i not in A:
        print(a+i)
        sys.exit()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
def resolve():
    x,n=pin()
    p=set(pin())
    dis=100000
    ans=-1
    for i in range(-1,101+1):
        if i in p:continue

        if abs(x-i)<dis:
            ans=i
            dis=abs(x-i)
    print(ans)
#%%submit!
resolve()

Submission status: Accepted

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

table = [True] * 102
for p in ps:
    table[p] = False
if table[x]:
    print(x)
    exit()

i = 1
while True:
    if table[x - i]:
        print(x - i)
        break
    if table[x + i]:
        print(x + i)
        break
    i += 1

Submission status: Accepted

Solution code:
def main():
    x,n = tuple([int(t)for t in input().split()])

    p = tuple([int(t)for t in input().split()])

    nums = set(range(0,102))

    for p_i in p:
        nums.discard(p_i)

    dist = 10**8
    ans = -1

    for i in nums:
        if dist>abs(x-i):
            dist = abs(x-i)
            ans = i

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

Submission status: Accepted

Solution code:
x,n = [int(i) for i in input().split()]
a = []
if n != 0:
    a = [int(i) for i in input().split()]
d = {}
dis = 0
for i in a:
    d[i] = 1
for i in range(102):
    if i in d:
        continue
    if abs(x - dis) > abs(x-i):
        dis = i
print(dis)

Submission status: Accepted

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

diff = {} #diff: num
for num in range(-101, 202):
    if num not in p:
        if abs(X-num) not in diff.keys():
            diff[abs(X-num)] = []
        diff[abs(X-num)].append(num)

diff = list(diff.items())
diff.sort()
ans = min(diff[0][1])
print(ans)

Submission status: Accepted

Solution code:
import sys

X, N = map(int, input().split())
P = list(map(int, sys.stdin.readline().rsplit()))

m = 1000
for i in range(102):
    if i in P:
        continue
    if abs(X - i) < m:
        m = abs(X - i)
        res = i
    else:
        break

print(res)

Submission status: Accepted

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

if n==0:
    print(x)
else:
    minp = min(min(p),x)
    maxp = max(max(p),x)
    
    mi=200
    ans=0
    for i in range(minp-1,maxp+2):
        if i not in p and abs(i-x)<mi:
                mi=abs(i-x)
                ans=i
    print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
from sys import stdin, setrecursionlimit
input = stdin.buffer.readline
setrecursionlimit(10 ** 7)

from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
from collections import deque, defaultdict, Counter
from itertools import combinations, permutations, combinations_with_replacement
from itertools import accumulate
from math import ceil, sqrt, pi, radians, sin, cos

MOD = 10 ** 9 + 7
INF = 10 ** 18

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

for i in range(1000):
    if X - i not in A:
        print(X - i)
        exit()
    if X + i not in A:
        print(X + i)
        exit()

Submission status: Accepted

Solution code:
[x,n]=list(map(int,input().split()))
plist=list(map(int,input().split()))
nums=[]
for i in range(102):
    if i not in plist:
        nums.append(i)

for i in range(1000):
    if x-i in nums:
        ans=x-i
        break
    if x+i in nums:
        ans=x+i
        break

print(ans)

Submission status: Accepted

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


if N > 0:
    p = list(map(int,input().split()))
    
    for i in range(1000):
        if X-i not in p:
            print(X-i)
            break
        elif X+i not in p:
            print(X+i)
            break
    
    #y = [abs(i - X) for i in p]
    
else:
    input()
    print(X)

Submission status: Accepted

Solution code:
def main():
    X, N = [int(x) for x in input().split()]
    if N == 0:
        print(X)
        return

    PS = [int(x) for x in input().split()]
    for i in range(0, 100):
        for sign in (-1, +1):
            v = X + i * sign
            if v not in PS:
                print(v)
                return


main()

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()

i = 1
while True:
    if not x - i in p:
        print(x - i)
        sys.exit()
    if not x + i in p:
        print(x + i)
        sys.exit()
    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()))
p.sort()
ans = -1
tmp = 1000
for i in range(0, 102):
    cnt = 0
    for j in range(n):
        if i == p[j]:
            cnt += 1001
            break
    cnt += abs(x - i)
    if cnt < tmp:
        tmp = cnt
        ans = i
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()))

p = set(p)

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

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
if n == 0:
    print(x)
else:
    p = [int(i) for i in input().split()]
    q = [x]
    for i in range(200):
        q.append(x - 1 - i)
        q.append(x + 1 + i)
    for i in q:
        if i not in p:
            print(i)
            break

Submission status: Accepted

Solution code:
def LI(): return list(map(int, input().split()))
def I(): return map(int, input().split())
mod = 10**9 + 7

def main():
  x,n =I()
  p = LI()
  for i in range(51):
    if x - i not in p:
      ans = x - i
      break
    if x + i not in p:
      ans = x + i
      break
  print(ans)
if __name__ == '__main__':
  main()

Submission status: Accepted

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

if n == 0:
  print(x)
else:
  p_list = list(map(int,input().split()))
  result_list = []
  for i in range(0,102):
    if i not in p_list:
      result_list.append([i,abs(x - i)])
    
  result_list.sort(key=lambda x: x[1])
  print(result_list[0][0])

Submission status: Accepted

Solution code:
import sys

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

def main():
    X, N = map(int, readline().split())
    p = set(map(int, readline().split()))
    pallset = set(range(-1, 102))
    remain = pallset - p
    dist = 200; ans = []
    for i in remain:
        if dist > abs(i-X):
            dist = abs(i-X)
            ans.append((i, dist))
    ans.sort(key=lambda x: x[1])
    print(ans[0][0])

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

if X in p:
    for i in range(1,1000):
        if not (X-i) in p:
            ans = (X-i)
            break
        if not (X+i) in p:
            ans = (X+i)
            break
else:
    ans = X
    
        
print(ans)

Submission status: Accepted

Solution code:
def main():
    x,n = map(int,input().split())
    p = list(map(int,input().split()))
    now = x
    now2 = x
    while True:
        f1 = now in p
        f2 = now2 in p

        if f1 and f2:
            now += 1
            now2 -= 1
            continue
        if f1 and not f2:
            ans = now2
            break
        if f2 and not f1:
            ans = now
            break
        if not f1 and not f2:
            ans = now2
            break
        # if now in p:
        #     if now2 in p:
        #         now += 1
        #         now2 -= 1
        #     else:
        #         print()
        # if now2 in p:
        #     if now in p:
        #         now += 1
        #         now2 -= 1
        #
    print(ans)
if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


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

    for diff in range(101):
        test = X - diff
        if test not in p:
            res = test
            break
        test = X + diff
        if test not in p:
            res = test
            break

    print(res)



main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
x, y, *p = map(int, open(0).read().split())
if y == 0:
    print(x)
    quit()
a = []
for i in range(min(p)-1, max(p)+2):
    if i not in p:
        a += [(abs(x-i), i)]
a.sort(key=lambda x: (x[0], x[1]))
print(a[0][1])

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
# debug = lambda *a, **kw: print(*a, **kw, file=sys.stderr)

X, N = inm()
P = inl()


def solve():
    ps = set(P)
    if X not in ps:
        return X

    mv = 1000
    my = 10000
    for y in range(-1, 102):
        if y in ps:
            continue
        if abs(y - X) < mv or abs(y - X) == mv and y < my:
            mv = abs(y - X)
            my = y
    return my


print(solve())

Submission status: Accepted

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

min_m = -1
min_diff = 1e9
for m in range(102):
    diff = abs(m - x)
    if diff < min_diff and m not in ps:
        min_m = m
        min_diff = diff

print(min_m)

Submission status: Accepted

Solution code:
x, n = [int(i) for i in input().split()]
p = set([int(i) for i in input().split()])
for i in range(1000):
    if x-i not in p:
        print(x-i)
        exit()
    if x+i not in p:
        print(x+i)
        exit()

Submission status: Accepted

Solution code:
import sys
from io import StringIO
import unittest


def resolve():
    x, n = map(int, input().split())
    p = list(map(int, input().split()))

    if p == [] or x not in p:
        print(x)
    else:
        p = set(p)
        i = 1
        while 1:
            if x - i not in p:
                print(x - i)
                break
            elif x + i not in p:
                print(x + i)
                break
            else:
                i += 1



class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """6 5
4 7 10 6 5"""
        output = """8"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """10 5
4 7 10 6 5"""
        output = """9"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """100 0"""
        output = """100"""
        self.assertIO(input, output)


if __name__ == "__main__":
    # unittest.main()
    resolve()

Submission status: Accepted

Solution code:
X,N=map(int,input().split())
if N!=0:
  ls=list(map(int,input().split()))
  a=0
  for i in range(102):
    if i in ls:
      continue
    else:
      if abs(i-X)<abs(a-X):
        a=i
  else:
    print(a)
else:
  print(X)

Submission status: Accepted

Solution code:
def main():
    x, n = map(int, input().split())
    if n == 0:
        print(x)
        exit(0)
    p = list(map(int, input().split()))
    mx = max(p)
    mn = min(p)
    c = list(set(range(mn-1, mx+2)) - set(p))
    diff = 1000
    ans = 1000
    for i in c:
        if (abs(x-i) < diff) or (abs(x-i) == diff and x < ans):
            diff = abs(x-i)
            ans = i
    print(ans)
    
            
    

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
x, n = map(int, input().split())
p = sorted(map(int, input().split()))
ok = [True] * 300
for y in p:
    ok[y + 150] = False
for i in range(150):
    if ok[x - i + 150]:
        print(x - i)
        exit()
    if ok[x + i + 150]:
        print(x + i)
        exit()

Submission status: Accepted

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

    move = 0
    while True:
        minus_check = X - move
        if minus_check not in p:
            print(minus_check)
            break

        pulus_check = X + move
        if pulus_check not in p:
            print(pulus_check)
            break

        move += 1
else:
    print(X)

Submission status: Accepted

Solution code:

X,N = map(int,input().split())
def seek(X):
    r=map(int,input().split())
    s= set()
    
    for it in r:
        s.add(it)
    for d in range(0,N+1):
        if not X-d in s:
            print(X-d)
            break
        if not X+d in s:
            print(X+d)
            break
if(N>0):
    seek(X)
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()

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

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()

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

Submission status: Accepted

Solution code:
x,n = map(int, input().split())
p = set(map(int, input().split()))
a = set(range(-200, 200))
b = a - p

mi = 10**6
ans = -1
for bi in b:
    if abs(bi - x) < mi:
        mi = abs(bi - x)
        ans = bi
print(ans)

Submission status: Accepted

Solution code:
x, n = list(map(int, input().split()))
p = list(map(int, input().split()))
if x not in p:
    print(x)
    exit()
    
for i in range(1, 51):
    ok1 = False
    ok2 = False
    if x-i not in p:
        ok1 = True
    if x+i not in p:
        ok2 = True
    if ok1 or ok2:
        if not ok2:
            print(x-i)
        elif not ok1:
            print(x+i)
        else:
            print(x-i)
        exit()

Submission status: Accepted

Solution code:
x,n = map(int,input().split())
if n == 0: 
    print(x)
    exit()
p = list(map(int,input().split()))
p = sorted(p)
ans = 100000
for i in range(-10000,10000):
    ok = True
    for j in range(n):
        if i == p[j]: ok = False
    if ok:
        if(abs(ans - x) > abs(x - i)):
            ans = i
print(ans)

Submission status: Accepted

Solution code:
X, N = map(int, input().split())
ps = list(map(int, input().split()))
for i in range(101):
    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:
# coding: utf-8
X, N = map(int, input().split())
if N == 0:
    print(X)
    exit()
P = list(map(int, input().split()))
P.sort()
ans = 10 ** 9
# d = [True for _ in range(0, 101)]
li = []
for i in range(-200, 201, 1):
    if i not in P:
        li.append(i)
for i in range(len(li)):
    if abs(ans - X) > abs(li[i] - X):
        ans = li[i]
print(ans)

Submission status: Accepted

Solution code:
x,n=map(int,input().split())
p=list(map(int,input().split()))
tmp=1000
for i in range(-100,300):
    if not i in p:
        tmp=min(tmp,abs(x-i))
for i in range(-100,300):
    if abs(x-i) == tmp and not i in p:
        print(i)
        exit()

Submission status: Accepted

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

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

Submission status: Accepted

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

li = [0]*(100+2)
for i in range(n):
    li[pi[i]] = 1
    
#print(li)

dif = 10**10
ans = -1
    
for i in range(102):
    if li[i] == 0:
        if dif > abs(x-i):
            dif = abs(x-i)
            ans = i
            
print(ans)

Submission status: Accepted

Solution code:
x, n = map(int, input().split())
P = set([int(x) for x in input().split()])
ans = 10 ** 4
for i in range(-1, 102):
    if i in P:
        continue
    if abs(x - ans) == abs(i - x):
        ans = min(ans, i)
    if abs(x - ans) > abs(i - x):
        ans = i
print(ans)

Submission status: Accepted

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

k = 0
for i in range(N):
    if P[i] == X:
        k = 1
if k == 0:
    print(X)
    sys.exit()

mi = X-1
ma = X+1
while(True):
    k = 0
    for i in range(N):
        if P[i] == mi:
            k = 1
    if k == 0:
        print(mi)
        sys.exit()
    mi -= 1
    k = 0
    for i in range(N):
        if P[i] == ma:
            k = 1
    if k == 0:
        print(ma)
        sys.exit()
    ma += 1

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-


# 入力を整数に変換して受け取る
def input_int():
    return int(input())


# マイナス1した値を返却
def int1(x):
    return int(x) - 1


# 半角スペース区切り入力をIntに変換してMapで受け取る
def input_to_int_map():
    return map(int, input().split())


# 半角スペース区切り入力をIntに変換して受け取る
def input_to_int_tuple():
    return tuple(map(int, input().split()))


# 半角スペース区切り入力をIntに変換してマイナス1した値を受け取る
def input_to_int_tuple_minus1():
    return tuple(map(int1, input().split()))


def main():
    x, n = input_to_int_map()
    p_list = input_to_int_tuple()

    target = []
    for i in range(-1, 102):
        if i not in p_list:
            target.append(i)

    sa = 200
    ret = x
    for val in target:
        t_sa = abs(x - val)
        if sa > t_sa:
            sa = t_sa
            ret = val

    return ret



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

Submission status: Accepted

Solution code:
def main():
    x,n=map(int, input().split())
    p=set(map(int,input().split()))
    for i in range(200):
        if (x - i) not in p:
            print(x-i)
            return
        elif (x + i) not in p:
            print(x+i)
            return

if __name__ == '__main__':
    main()

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()))
ans=1000
for i in range(0,102):
    if i not in p:
        tmp=abs(x-i)
        if tmp<ans:
            ans=tmp
            ansa=i
print(ansa)

Submission status: Accepted

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

for i in range(1000):
    if(not x-i in p):
        print(x-i)
        break
    if(not x+i in p):
        print(x+i)
        break

Submission status: Accepted

Solution code:
from bisect import bisect_left
X, N = map(int, input().split())
P = sorted(list(map(int, input().split())))
i = 0
if N == 0:
  print(X)
else:
  while True:
    x = X-i
    idx = bisect_left(P, x)
    if idx < 0 or idx >= N or P[idx] != x:
      print(x)
      break
    else:
      x = X+i
      idx = bisect_left(P, x)
      if idx < 0 or idx >= N or P[idx] != x:
        print(x)
        break
    i += 1

Submission status: Accepted

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

visited=[False]*102

for a in A:
  visited[a] = True
  
min = 200
ans=-1
for i in range(102):
  if (not visited[i]) and min > abs(i - X):
    min=abs(i-X)
    ans=i
    
print(ans)

Submission status: Accepted

Solution code:
#import sys
#input = sys.stdin.readline
def main():
    X, N = map( int, input().split())
    if N == 0:
        print(X)
        return
    Q = list( map( int, input().split()))
    # P.sort()
    Z = [True]*102
    for q in Q:
        Z[q] = False
    P = []
    for i in range(102):
        if Z[i]:
            P.append(i)
    # print(P)
    now = P[0]
    ab = abs(X-P[0])
    for p in P:
        pab = abs(X-p)
        if pab == ab:
            if p < now:
                now = p
        elif pab < ab:
            now = p
            ab = pab
    print(now)
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys


def solve(X: int, N: int, p: "List[int]"):
    if not X in p:
        print(X)
        return
    for i in range(1, 100):
        left = X - i
        if not left in p:
            print(left)
            return
        right = X + i
        if not right in p:
            print(right)
            return
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    N = int(next(tokens))  # type: int
    p = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(X, N, p)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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


for i in range(x,102):
    if i not in p:
        ans = i
        break

for i in reversed(range(-1,x)):
    if i not in p:
        if ans-x>=x-i:
            ans = i
        break
print(ans)

Submission status: Accepted

Solution code:
x,n = map(int, input().split())
p = [False] * 110
line = list(map(int, input().split()))
for i in range(n):
    p[line[i]] = True

ans = 0
a = 10000
for i in range(110):
    if p[i]:
        continue

    ai = abs(i - x)
    if ai < a:
        a = ai
        ans = i

print(ans)

Submission status: Accepted

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

cands = [True for i in range(0, 102)]

for p in P:
    cands[p] = False

flag = False

if cands[X]:
    result = X
    flag = True

for i in range(1, 102):
    if flag:
        break
    if X + i < 102 and cands[X + i]:
        flag = True
        result = X + i
    if 0 <= X - i and cands[X - i]:
        flag = True
        result = X - i

print(result)

Submission status: Accepted

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

m = 0
d = X
for i in range(1, 102):
    if i in ps:
        continue

    if abs(X - i) < abs(X - m):
        m = i
        d = abs(X - i)

print(m)

Submission status: Accepted

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

for i in range(1000):
    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
from math import factorial
from collections import Counter
from fractions import Fraction
import heapq, bisect, fractions
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
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()))
MOD = 10**9 + 7

x, n = MAP()
p = LIST()
i = 0
while True:
    if x-i not in p:
        print(x-i)
        sys.exit()
    if x+i not in p:
        print(x+i)
        sys.exit()
    i += 1

Submission status: Accepted

Solution code:
x,n=map(int, input().split())
if n==0:
  print(x)
  exit()
p=list(map(int, input().split()))
ans=10**10
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:
x,n = map(int,input().split())
p = list(map(int,input().split()))

for i in range(101):
    li = x - i
    if(li not in p):
        print(li)
        break
    bi = x + i
    if(bi not in p):
        print(bi)
        break

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(102):
    if p.count(X-i) == 0:
        print(X-i)
        break
    if p.count(X+i) == 0:
        print(X+i)
        break

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
#from fractions import gcd
#from itertools import combinations # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
x,n = readInts()
if n == 0:
    print(x)
    exit()
P = readInts()
A = []
for i in range(-1,max(P)+1,1):
    if i + 1 in P:
        pass
    else:
        A.append(i+1)
#print(A)
m = float('inf')
ans = -1
for a in A:
    if abs(x - a) < m:
        ans = a
        m = abs(x-a)
print(ans)