Problem: 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.

Submission attempts (in order):
x, n = map(int, input().split())
p = list(map(int, input().split()))

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

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

q = []
r = []
min_ = 1000
for i in range(1, 101):
    if not i in p:
        q.append(i)
        
for j in q:
    k = int(abs(x - j))
    if min_ == k:
        r.append(before_j)
        r.append(j)
    min_ = min(k, min_)
    if min_ == k:
        before_j = j

print(min(r))

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

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

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

if n == 0:
    print(x)
else:
    q = []
    r = []
    min_ = 1000
    for i in range(1, 101):
        if not i in p:
            q.append(i)

    for j in q:
        k = int(abs(x - j))
        if min_ == k:
            r.append(before_j)
            r.append(j)
        min_ = min(k, min_)
        if min_ == k:
            before_j = j

    print(min(r))

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

if n == 0:
    print(x)

p = set(p)
else:
    _x = x 
    x_ = x
    while True:
        _x -= 1
        x_ += 1
        if _x not in p:
            print(_x)
            break
        if x_ not in p:
            print(x_)
            break

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

p = set(p)
for i in range(200):
    if x - i not in p:
        print(x - i)
        break
    if n + i not in p:
        print(n + i)
        break

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

if n == 0:
    print(x)
else:
    q = []
    x_ = x
    _x = x
    for i in range(1, 101):
        if not i in p:
            q.append(i)
    while True:
        if _x - 1 in q:
            print(_x - 1)
            break
        elif x_ + 1in q:
            print(x_ + 1)
            break

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

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

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

q = []
r = []
min_ = 1000
for i in range(1, 101):
    if not i in p:
        q.append(i)
        
for j in q:
    k = int(abs(x - j))
    if min_ == k:
        r.append(before_j)
        r.append(j)
    min_ = min(k, min_)
    if min_ == k:
        before_j = j

print(min(r))



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

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

Verdicts: Time Limit Exceeded

Runtime Error

Time Limit Exceeded

Runtime Error

Runtime Error

Wrong Answer

Wrong Answer

Wrong Answer

Runtime Error

Accepted