qyliang/CodeNanoFix huggingface dataset:
# Buggy code:
import sys
from collections import Counter
input = sys.stdin.readline


N = int(input())
alist = list(map(int, input().split()))
Q = int(input())


sumA = sum(alist)
adict = Counter(alist)

for _ in range(Q):
    b, c = map(int, input().split())

    bnum = adict.pop(b)
    if c in adict:
        adict[c] += bnum
    else:
        adict[c] = bnum

    sumA -= bnum * (b - c)
    print(sumA)


# Fixed code:
import sys
from collections import Counter
input = sys.stdin.readline


N = int(input())
alist = list(map(int, input().split()))
Q = int(input())


sumA = sum(alist)
adict = Counter(alist)

for _ in range(Q):
    b, c = map(int, input().split())

    if b not in adict:
        print(sumA)
        continue

    bnum = adict.pop(b)
    if c in adict:
        adict[c] += bnum
    else:
        adict[c] = bnum

    sumA -= bnum * (b - c)
    print(sumA)
# Buggy code:
import sys
import time
import math
st = time.perf_counter()
def inpl():
    return list(map(int, input().split()))
# ------------------------------

N = int(input())
nl = [0] * 10101
ls = inpl()
ans = 0
for i in ls:
	nl[i] += 1
	ans += i
M = int(input())
for _ in range(M):
	a, b = map(int, input().split())
	ans = ans - nl[a] * a + nl[b] * b
	nl[b] += nl[a]
	nl[a] = 0
	print(ans)

# ------------------------------
ed = time.perf_counter()
print('time:', ed-st, file=sys.stderr)


# Fixed code:
import sys
import time
import math
st = time.perf_counter()
def inpl():
    return list(map(int, input().split()))
# ------------------------------

N = int(input())
nl = [0] * 100100
ls = inpl()
ans = 0
for i in ls:
	nl[i] += 1
	ans += i
M = int(input())
for _ in range(M):
	a, b = map(int, input().split())
	ans = ans - (nl[a] * a) + (nl[a] * b)
	nl[b] += nl[a]
	nl[a] = 0
	print(ans)

# ------------------------------
ed = time.perf_counter()
print('time:', ed-st, file=sys.stderr)
# Buggy code:
n = int(input())
A = [int(x) for x in input().split()]
sumA = sum(A)
counter = [0]*(10**5+1)
for i in range(n):
    counter[A[i]] += 1

print(counter[:30])
q = int(input())

queue = [list(map(int,input().split())) for i in range(q)]

for b,c in queue:    
    b_cnt = counter[b]
    sumA -= (b*b_cnt)
    counter[b] = 0
    c_cnt = counter[c]
    sumA += c*(b_cnt)
    counter[c] = b_cnt+c_cnt
    print(sumA)
    

# Fixed code:
n = int(input())
A = [int(x) for x in input().split()]
sumA = sum(A)
counter = [0]*(10**5+1)
for i in range(n):
    counter[A[i]] += 1

q = int(input())

queue = [list(map(int,input().split())) for i in range(q)]

for b,c in queue:    
    b_cnt = counter[b]
    sumA -= (b*b_cnt)
    counter[b] = 0
    c_cnt = counter[c]
    sumA += c*(b_cnt)
    counter[c] += b_cnt
    print(sumA)
# Buggy code:
n = int(input())
al = list(map(int,input().split()))
q = int(input())

from collections import defaultdict
dic = defaultdict(int)

ans = 0
for a in al:
    dic[a] += 1
    ans += a

print(dic)
for _ in range(q):
    b,c = map(int,input().split())
    ans += dic[b] * (c - b)
    dic[c] += dic[b]
    dic[b] = 0
    print(ans)








# Fixed code:
n = int(input())
al = list(map(int,input().split()))
q = int(input())

from collections import defaultdict
dic = defaultdict(int)

ans = 0
for a in al:
    dic[a] += 1
    ans += a


for _ in range(q):
    b,c = map(int,input().split())
    ans += dic[b] * (c - b)
    dic[c] += dic[b]
    dic[b] = 0
    print(ans)
# Buggy code:
n=int(input())
a=list(map(int,input().split()))
q=int(input())
d=dict()
for i in a:
    if i not in d:
        d[i]=1
    else:
        d[i]+=1
ans=sum(a)
for i in range(q):
    b,c=map(int,input().split())
    if b not in d:
        continue
    if c not in d:
        d[c]=0
    d[c]+=d[b]
    ans+=(c-b)*d[b]
    print(ans)
    d[b]=0


# Fixed code:
n=int(input())
a=list(map(int,input().split()))
q=int(input())
d=dict()
for i in a:
    if i not in d:
        d[i]=1
    else:
        d[i]+=1
ans=sum(a)
for i in range(q):
    b,c=map(int,input().split())
    if b not in d:
        d[b]=0
    if c not in d:
        d[c]=0
    d[c]+=d[b]
    ans+=(c-b)*d[b]
    print(ans)
    d[b]=0
# Buggy code:
import collections

N = int(input())
A = list(map(int,input().split()))
S = sum(A)
c = collections.Counter(A)

Q = int(input())

for i in range(Q):
    B, C = map(int, input().split())
    ans = S - B * c[B] + C * c[B]
    print(ans)
    S = ans
    c[B] = 0
    c[C] += c[C]

# Fixed code:
import collections

N = int(input())
A = list(map(int,input().split()))
S = sum(A)
c = collections.Counter(A)

Q = int(input())

for i in range(Q):
    B, C = map(int, input().split())
    ans = S - B * c[B] + C * c[B]
    print(ans)
    S = ans
    c[C] += c[B]
    c[B] = 0
# Buggy code:
X, Y = map(int, input().split())
Z = 0
ANS = 'No'
if Y % 2 == 0:
    while X >= 0:
        i = X*2 + Y*4
        if i == Y:
            ANS = 'Yes'
        Z += 1
        X -= 1
print(ANS)


# Fixed code:
X, Y = map(int, input().split())
Z = 0
ANS = 'No'
if Y % 2 == 0:
    while X >= 0:
        i = X*2 + Z*4
        if i == Y:
            ANS = 'Yes'
        X -= 1
        Z += 1
print(ANS)
# Buggy code:
X, Y = map(int, input().split())
t = Y - 2*X
u = 4*X - Y

if (t >= 2) & (t % 2 == 0) & (u >= 2) & (u % 2 == 0):
    print("Yes")
else:
    print("No")

# Fixed code:
X, Y = map(int, input().split())
t = Y - 2*X
u = 4*X - Y

if (t >= 0) & (t % 2 == 0) & (u >= 0) & (u % 2 == 0):
    print("Yes")
else:
    print("No")
# Buggy code:
x,y = map(int,input().split())

for i in range(x):
    if 2*(i-1) + 4*(x-(i-1)) == y:
        print("Yes")
        exit()
        
print("No")
            

# Fixed code:
x,y = map(int,input().split())

for i in range(x + 1):
    if 4*i + 2*(x-i) == y:
        print("Yes")
        exit()
        
print("No")
# Buggy code:
x,y = map(int,input().split())

if 2 <= y <= 4 and (x*y) %2 == 0:
    print('Yes')
else:
    print('No')

# Fixed code:
x,y = map(int,input().split())

if x*2 <= y <= x*4 and y%2 == 0:
    print('Yes')
else:
    print('No')
# Buggy code:
X, Y = map(int, input().split())
ans = 'No'
for a in range(X + 1):
  b = X - a
  if 2 * a + 4 * b == Y:
  ans = 'Yes'
print(ans)

# Fixed code:
X, Y = map(int, input().split())
ans = 'No'
for a in range(X + 1):
  b = X - a
  if 2 * a + 4 * b == Y:
    ans = 'Yes'
print(ans)
# Buggy code:
x,y=map(int,input().split())
t=2*y-4*x
c=y-t
if y<0 or x<0:
  print("No")
else:
  print("Yes")

# Fixed code:
x,y=map(int,input().split())
t=2*y-4*x
c=y-t
if t<0 or c<0 or t%4!=0 or c%2!=0:
  print("No")
else:
  print("Yes")
# Buggy code:
x, y = map(int, input().split())

a = 0

for i in range(x):
    if (x - i)*4 == y:
        a += 1
        break

if a == 1:
    print("Yes")
else:
    print("No")

# Fixed code:
x, y = map(int, input().split())

a = 0

for i in range(x+1):
    if (x - i)*4 + (i * 2) == y:
        a += 1
        break

if a == 1:
    print("Yes")
else:
    print("No")
# Buggy code:
x, y = input().split()

max_num = 4 * x
min_num = 2 * x

if y % 2 == 1:
    print('No')
elif (min_num <= y) and (max_num >= y):
    print('Yes')
else:
    print('No')

# Fixed code:
x, y =  map(int, input().split())

max_num = 4 * x
min_num = 2 * x

if y % 2 == 1:
    print('No')
elif (min_num <= y) and (max_num >= y):
    print('Yes')
else:
    print('No')
# Buggy code:
x, y = map(int, input().split())

# kame = x - turu
# 2*turu + 4*kame = y
# 2*turu + 4*(x - turu) = y
#  -2*turu + 4x - y = 0
# turu = 2x - 1/2*y

turu = 2*x - 1/2*y
print(turu)
if(turu.is_integer() and turu >= 0 and (x-turu) >= 0):
    print("Yes")
else:
    print("No")


# Fixed code:
x, y = map(int, input().split())

# kame = x - turu
# 2*turu + 4*kame = y
# 2*turu + 4*(x - turu) = y
#  -2*turu + 4x - y = 0
# turu = 2x - 1/2*y

turu = 2*x - 1/2*y
if(turu.is_integer() and turu >= 0 and (x-turu) >= 0):
    print("Yes")
else:
    print("No")
# Buggy code:
import sys
animals, legs = [int(i) for i in input().split()]

cranes = 2
turtle = 4

for i in range(1, animals + 1):
    for j in range(1, animals + 1):
        number = (2*i) + (4*j)
        if i + j == animals and number == legs:
            print("Yes")
            sys.exit()

print("No")

# Fixed code:
import sys
animals, legs = [int(i) for i in input().split()]

cranes = 2
turtle = 4

for i in range(0, animals + 1):
    for j in range(0, animals + 1):
        number = (2*i) + (4*j)
        if i + j == animals and number == legs:
            print("Yes")
            sys.exit()

print("No")
# Buggy code:
X, Y = map(int, input().split())

ans = []
for x in range(1,51):
    if Y == 4*x + 2*(X-x-1):
        ans = 1
if ans == 1:
    print("Yes")
else:
    print("No")


# Fixed code:
X, Y = map(int, input().split())

ans = []
for x in range(0,X+1):
    if Y == 4*x + 2*(X-x):
        ans = 1
if ans == 1:
    print("Yes")
else:
    print("No")
# Buggy code:
X, Y = map(int,input().split())

if Y%2!=0:
    print('No')
    exit()

turu = (4*X-Y)/2
kame = (Y-2*X)/2

if turu > 0 and turu.is_integer() and kame > 0 and kame.is_integer():
    print('Yes')
else:
    print('No')

# Fixed code:
X, Y = map(int,input().split())

if Y%2 == 1:
    print('No')
    exit()

turu = (4* X - Y)/2
kame = (Y - 2*X)/2

if turu.is_integer() and turu >= 0 and kame.is_integer() and kame >=0:
    print('Yes')
else:
    print('No')
# Buggy code:
import sys
x, y = input().split(" ")
for i in range(int(x)):
  exp_i = int(x) - i
  if int(i) * 2 + exp_i * 4 == int(y):
    print("Yes")
    sys.exit()

print("No")


# Fixed code:
import sys
x, y = input().split(" ")
for i in range(int(x)+1):
  exp_i = int(x) - i
#  print(i)
#  print(int(i) * 2 + exp_i * 4)
#  print(int(y))
  if int(i) * 2 + exp_i * 4 == int(y):
    print("Yes")
    sys.exit()

print("No")
# Buggy code:
x, y = map(int, input().split())

for i in range(x):
    if 2 * i + 4 * (x - i) == y:
        print("Yes")
        break
else:
    print("No")

# Fixed code:
x, y = list(map(int, input().split()))

for i in range(x+1):
    j = x - i
    if 2*i + 4*j == y:
        print('Yes')
        break
else:
    print('No')
# Buggy code:
X,Y = input().split()
A=int(Y)/2-int(X)
B=2*int(X)-int(Y)/2
if(A.is_integer and A>0 and B>0 ):
    print("Yes")
else:
    print("No")

# Fixed code:
X,Y = input().split()

A=2*int(X)-int(Y)/2
B=int(Y)/2-int(X)
if(A.is_integer() and A>=0 and B>=0 and B.is_integer):
    print("Yes")
else:
    print("No")
# Buggy code:
X, Y = map(int, input().split())
print("Yes" if 2 * X <= Y <= 4 * Y and (Y % 2 == 0) else "No")

# Fixed code:
X, Y = map(int, input().split())
if(2*X <= Y and Y <= 4*X and Y%2==0):
  print('Yes')
else:
  print('No')
# Buggy code:
a,b = map(int, input().split())
if (b - 2 * a) % 2 == 0 and (4 * a - b) % 2 == 0:
    print("Yes")
else:
    print("No")

# Fixed code:
a,b = map(int, input().split())
if (b - 2 * a) % 2 == 0 and (4 * a - b) % 2 == 0 and (b - 2 * a) / 2 >= 0 and (4 * a - b) / 2 >= 0:
    print("Yes")
else:
    print("No")
# Buggy code:
x, y = map(int, input().split())

ans = 'No'
for i range(x+1):
  if (x*2 + (x-i)*4) == y:
    ans='Yes'
    break
print(ans)

# Fixed code:
x, y = map(int, input().split())

ans = 'No'
for i in range(x+1):
  if (i*2 + (x-i)*4) == y:
    ans='Yes'
    break
print(ans)
# Buggy code:
x, y = map(int, input().split())
ans = "No"
for a in range(0,x + 1):
    if 2 * a + 4 * (y - a):
        ans = "Yes"
        break
print(ans)

# Fixed code:
x,y = map(int,input().split())
ans = 'No'
for i in range(x+1):    
  if i*2+(x-i)*4 == y:
    ans = 'Yes'
    break
print(ans)
# Buggy code:
x, y = map(int,input().split())

for i in range(x+1):
    print(i)
    if 4 * i + 2*(x - i) == y:
        print('Yes')
        exit()

print('No')

# Fixed code:
x, y = map(int, input().split())


def xy(a):
    if a * 2 + (x - a) * 4 == y:
        print("Yes")
        exit()


for i in range(int(x + 1)):
    xy(i)

print("No")
# Buggy code:
X, Y = map(int, input().split())

ans = 'No'
for i in range(X):
  if 2*i + 4*(X-i) == Y:
    ans = 'Yes'
    break

print(ans)

# Fixed code:
X, Y = map(int, input().split())
 
ans = 'No'
for i in range(X+1):
  if 2*i + 4*(X-i) == Y:
    ans = 'Yes'
    break
 
print(ans)
# Buggy code:
a=input().split(" ")
ans=0
x=0
for i in range(1,int(a[0])):
	for j in range(1,int(a[0])):
		ans=(i*2)+(j*4)
		if ans==int(a[1]) and i+j==int(a[0]):
			x=x+1
if x>=1:
	print("Yes")
elif x==0:
	print("No")
		
		

# Fixed code:
a=input().split(" ")
ans=0
x=0
for i in range(1,int(a[0])):
	for j in range(1,int(a[0])):
		ans=(i*2)+(j*4)
		if ans==int(a[1]) and i+j==int(a[0]):
			x=x+1
if int(a[0])*4==int(a[1]):
	x=x+1
if int(a[0])*2==int(a[1]):
	x=x+1
if x>=1:
	print("Yes")
elif x==0:
	print("No")
# Buggy code:
X,Y=map(int, input().split())
if(Y%2==1):
  print("No")
  exit()
if(2*X-Y//2<0):
  print("No")
if(Y//2-X<0):
  print("No")
print("Yes")  

# Fixed code:
X,Y=map(int, input().split())
if(Y%2==1):
  print("No")
  exit()
if(2*X-Y//2<0):
  print("No")
  exit()
if(Y//2-X<0):
  print("No")
  exit()
print("Yes")
# Buggy code:
target = list(map(int, input().split()))

num = target[0]
total = target[1]

flg = False
for i in range(target[0]):
    tori = i * 2
    kame = (target[0]-i) * 4
    if (tori + kame) == total:
        print('Yes')
        break
else:
    print('No')


# Fixed code:
target = list(map(int, input().split()))

num = target[0]
total = target[1]

for i in range(num + 1):
    tori = i
    kame = (num - i)
    if (tori * 2 + kame * 4) == total:
        print('Yes')
        break
else:
    print('No')
# Buggy code:
x,y = map(int,input().split())
flag = 0
for i in range (100):
  for j in range (100):
    if ((i+j == x) and(2*i+4*j == y))  :
      print("Yes")
      flag = 1
if flag == 0:
print("No")

# Fixed code:
x,y = map(int,input().split())
flag = 0
for i in range (100):
  for j in range (100):
    if ((i+j == x) and(2*i+4*j == y)):
      print("Yes")
      flag = 1
if (flag == 0):
    print("No")
# Buggy code:
x,y = map(int,input().split())

l = []
c = 2 * x
l.append(c)
for nn in range(x):
    c += 2
    l.append(c)
print(l)

flag = False
for ll in l:
    if ll == y:
        print("Yes")
        flag = False
        break

    else:
        flag = True

if flag:
    print("No")

# Fixed code:
x,y = map(int,input().split())

l = []
c = 2 * x
l.append(c)
for nn in range(x):
    c += 2
    l.append(c)

flag = False
for ll in l:
    if ll == y:
        print("Yes")
        flag = False
        break

    else:
        flag = True

if flag:
    print("No")
# Buggy code:
x, y = map(int,input().split())
min = 2 * x
gap = y - min

if gap < 0 & gap > min:
  print("No")
else:
  if gap % 2 == 0:
    print("Yes")
  else:
    print("No")


# Fixed code:
x, y = map(int,input().split())
min = 2 * x
gap = y - min

if gap < 0 or gap > min:
  print("No")
else:
  if gap % 2 == 0:
    print("Yes")
  else:
    print("No")
# Buggy code:
x, y = map(int,input().split())
t , k = 2 , 4
ans = 0
for i in range(x+1):
    print(i, x-i)
    if y == (t*i + k*(x-i)):
        ans += 1

if ans == 0:
    print('No')
else:
    print('Yes')

# Fixed code:
x, y = map(int,input().split())
t , k = 2 , 4
ans = 0
for i in range(x+1):
    if y == (t*i + k*(x-i)):
        ans += 1

if ans == 0:
    print('No')
else:
    print('Yes')
# Buggy code:
x, y = map(int, input().split())
for i in range(x+1):
  z = y - x*2
  if z%4==0:
    print("Yes")
    exit()
print("No")


# Fixed code:
x, y = map(int, input().split())
for i in range(x+1):
  z = y - i*2
  if z%4==0 and 4*(x-i)==z:
    print("Yes")
    exit()
print("No")
# Buggy code:
X, Y = map(int,input().split)
ans = "No"
for a in range(X + 1):
    b = X - a
    if 2 * a + 4 * b == Y:
        ans = "Yes"
print(ans)

# Fixed code:
X, Y = list(map(int, input().split()))
ans = "No"
for a in range(X + 1):
    b = X - a
    if 2 * a + 4 * b == Y:
        ans = "Yes"
print(ans)
# Buggy code:
1, n = map(int,input().split())

if n != 0:
    p = list(map(int,input().split()))
else:
    p = []

result = []

i = 0

while len(result) == 0:
    if not (x - i in p):
        result.append(x - i)
    if not (x + i in p):
        result.append(x + i)
    
    i += 1

print(int(min(result)))

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

if n != 0:
    p = list(map(int,input().split()))
else:
    p = []

result = []

i = 0

while len(result) == 0:
    if not (x - i in p):
        result.append(x - i)
    if not (x + i in p):
        result.append(x + i)
    
    i += 1

print(int(min(result)))
# Buggy code:
x,n = map(int, input().split())
if n != 0:
    p = list(map(int, input().split()))

smaller = 0
for i in range(x):
    if x - i in p:
        pass
    else:
        smaller = x-i
        break

bigger = 2*x
for j in range(x):
    if x + j in p:
        pass
    else:
        bigger = x + j
        break

ans = smaller if x - smaller <= bigger - x else bigger
#print(bigger)
print(ans)

# Fixed code:
x,n = map(int, input().split())
if n != 0:
    p = list(map(int, input().split()))
    smaller = 0
    for i in range(x):
        if x - i in p:
            pass
        else:
            smaller = x-i
            break

    bigger = 2*x
    for j in range(x):
        if x + j in p:
            pass
        else:
            bigger = x + j
            break

    ans = smaller if x - smaller <= bigger - x else bigger
    #print(bigger)
    print(ans)
else:
    print(x)
# Buggy code:
x, n = map(int, input().split(" "))
p = list(map(int, input().split(" ")))

p_under = list(filter(lambda v: v<x, p))
p_upper = list(filter(lambda v: v>x, p))
p_under.sort(reverse=True)
p_upper.sort()

cnt = 0
while(True):
    if x - cnt not in p_under:
        print(x - cnt)
        break
    if x + cnt not in p_upper:
        print(x + cnt)
        break
    cnt += 1


# Fixed code:
x, n = map(int, input().split(" "))

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

    p_under = list(filter(lambda v: v<=x, p))
    p_upper = list(filter(lambda v: v>=x, p))
    p_under.sort(reverse=True)
    p_upper.sort()

    cnt = 0
    while(True):
        if x - cnt not in p_under:
            print(x - cnt)
            break
        if x + cnt not in p_upper:
            print(x + cnt)
            break
        cnt += 1
# Buggy code:
X, N = map(int, input().split())
if N == 0:
    print(X)
    exit()

p = set(map(int,input().split()))
not_p = list(set(range(0,100)) - p)
print(not_p)

minV = 101
ans = 0
for i in not_p:
    if abs(X - i) < minV:
        minV = abs(X - i) 
        ans = i
print(ans)

# Fixed code:
X, N = map(int, input().split())
if N == 0:
    print(X)
    exit(0)

p = set(map(int,input().split()))
not_p = list(set(range(0,102)) - p)

minV = 101
ans = 0
for i in not_p:
    if abs(X - i) < minV:
        minV = abs(X - i)
        ans = i
print(ans)
# Buggy code:
import math
input_a= input().split(" ")
X=int(input_a[0])
N=int(input_a[1])
dis=X+3
if N!=0:
  array= input().split(" ")
else:
  array=[0,0]

num=X
num2=-100
for i in range(101-X):

  
  if str(num) not in array:
    dis=abs(X-num)
    num2=X-dis
    num1=num
    if str(num2) not in array:
    	numa=min([num,num2])
    else:
      numa=num1
    break
  num=num+1
    

num=X
i=0
for i in range(dis):
  
  if str(num) not in array:
    
    dis2=abs(X-num)
    num3=X+dis2
    #print(num,dis2,num3)
    if str(num3) not in array:
    	numb=min([num,num3])
    else:
      numb=num
      break
  num=num-1
#print(numa,numb,dis,dis2)
if dis<dis2:
  print(numa)
elif dis==dis2:
  print(numb)
else:
  print(numb)

# Fixed code:
import math
input_a= input().split(" ")
X=int(input_a[0])
N=int(input_a[1])
dis=X+3
dis2=100
if N!=0:
  array= input().split(" ")
else:
  array=[0,0]

num=X
num2=-100
for i in range(N+1):

  
  if str(num) not in array:
    dis=abs(X-num)
    num2=X-dis
    num1=num
    if str(num2) not in array:
    	numa=min([num,num2])
    else:
      numa=num1
    break
  num=num+1
    

num=X
i=0
for i in range(dis):
  
  if str(num) not in array:
    
    dis2=abs(X-num)
    num3=X+dis2

    if str(num3) not in array:
    	numb=min([num,num3])
    else:
      numb=num
      break
  num=num-1

if dis<dis2:
  print(numa)
elif dis==dis2:
  print(numb)
else:
  print(numb)
# Buggy code:
X,N = map(int,input().split())
P = [int(input()) for i in range(N)]

L = sorted([abs(X-p) for p in P])
if 0 not in L :
    print(X)
    exit()

DL = list(set([x for x in L if L.count(x) > 1]))

ans_abs = 1
for i,x in enumerate(DL) :
    if x == i+1 :
        ans_abs += 1
    else :
        break

if X-ans_abs in P :
    print(X+ans_abs)
else :
    print(X-ans_abs)


# Fixed code:
import itertools
X,N = map(int,input().split())

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

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

L = sorted([abs(X-p) for p in P])
if 0 not in L :
    print(X)
    exit()

DL = list(set([x for x in L if L.count(x) > 1]))

ans_abs = 1
for i,x in enumerate(DL) :
    if x == i+1 :
        ans_abs += 1
    else :
        break

if X-ans_abs in P :
    print(X+ans_abs)
else :
    print(X-ans_abs)
# Buggy code:
a = input().split()
if a[1] == "0":
  print(a[0])
else:
  number_list = input().split()
  n = 1
  number = int(a[0])
  while True:
    num = number + n
    num2 = number - n
    if str(num) not in number_list or str(num2) not in number_list:
      if str(num) in number_list:
        print(num2)
      else:
        print(num1)
      break
    n += 1
    

# Fixed code:
a = input().split()
if a[1] == "0":
  print(a[0])
else:
  number_list = input().split()
  n = 0
  number = int(a[0])
  while True:
    num = number + n
    num2 = number - n
    if str(num) not in number_list or str(num2) not in number_list:
      if str(num) not in number_list and str(num2) not in number_list:
        print(num2)
        break
      if str(num) in number_list:
        print(num2)
      else:
        print(num)
      break
    n += 1
# Buggy code:
x,n = map(int,input().split())
a = list(map(int,input().split()))
if x == n:
    print(x)
    quit()
k = 1
while(True):
    if not x-k in a:
        print(x-k)
        quit()
    if not x+k in a:
        print(x+k)
        quit()
    k += 1

# Fixed code:
x,n = map(int,input().split())
if n == 0:
    print(x)
    quit()
a = list(map(int,input().split()))

k = 0
while(True):
    if not x-k in a:
        print(x-k)
        quit()
    if not x+k in a:
        print(x+k)
        quit()
    k += 1
# Buggy code:
x, n = map(int, input().split())
if n != 0:
    p = list(map(int, input().split()))
    if x in p:
        for i in range(-1000, 1001):
            print(i)
            if i == -100:
                mini = i
            if i in p:
                pass
            else:
                if abs(x - mini) > abs(x - i):
                    mini = i
                elif abs(x - mini) == abs(x - i):
                    mini = min(mini, i)
        else:
            print(mini)
    else:
        print(x)
else:
    print(x)


# Fixed code:
x, n = map(int, input().split())
if n != 0:
    p = list(map(int, input().split()))
    if x in p:
        for i in range(-1000, 1001):
            if i == -1000:
                mini = i
            if i in p:
                pass
            else:
                if abs(x - mini) > abs(x - i):
                    mini = i
                elif abs(x - mini) == abs(x - i):
                    mini = min(mini, i)
        else:
            print(mini)
    else:
        print(x)
else:
    print(x)
# Buggy code:
x, n = map(int, input().split())
if n == 0:
  print(x)
  exit()
else:
  ps = list(map(int, input().split()))
counters = [0 for _ in range(len(ps))]
counters[0] = 1

for i,p in enumerate(ps):
  distance = abs(x - p)
  if distance < len(ps):
    counters[distance] += 1

print(counters)
for i,counter in enumerate(counters):
  if counter == 0:
    print(x-i)
    break
  elif counter == 1:
    if x-i in ps:
      print(x+i)
    else:
      print(x-i)
    break

# Fixed code:
x, n = map(int, input().split())
if n == 0:
  print(x)
  exit()
else:
  ps = list(map(int, input().split()))
counters = [0 for _ in range(len(ps)+1)]
counters[0] = 1

for i,p in enumerate(ps):
  distance = abs(x - p)
  if distance < len(ps):
    counters[distance] += 1

for i,counter in enumerate(counters):
  if counter == 0:
    print(x-i)
    break
  elif counter == 1:
    if x-i in ps:
      print(x+i)
    else:
      print(x-i)
    break