CodeEff/ECCO huggingface dataset:
# Original solution
N = 0
graphs = []

try:
    N = int(eval(input()))
    nodes = [[abs(i - j) + 1 for i in range(N)] for j in range(N)]
    for i in range(N - 1):
        line = input().split()
        u = min(int(line[0]), int(line[1])) - 1
        v = max(int(line[0]), int(line[1])) - 1
        for u2 in range(0, u + 1):
            for v2 in range(v, N):
                if u2 < v2:
                    nodes[u2][v2] -= 1
except:
  pass

a = 0
for i in range(N):
    a += sum(nodes[i][i:])
print(a)

# Optimized solution
N = 0
a = 0

try:
    N = int(eval(input()))
    for i in range(N + 1):
        a += i * (i + 1) // 2
    for i in range(N - 1):
        line = input().split()
        u = min(int(line[0]), int(line[1])) - 1
        v = max(int(line[0]), int(line[1])) - 1
        a -= (u + 1) * (N - v)        
except:
  pass

print(a)
# Original solution
N=int(eval(input()))
S=list(range(1, N+1))#頂点の数
H = [list(map(int,input().split())) for i in range(N-1)]#辺のリスト
F = 0
tyouten = int(N*(N+1)*(N+2)/6)
for i in range(1,N+1):
    for j in range(i,N+1):	
        Hselect = [H[x] for x in range(N-1) if i <= H[x][0] <= j and i <= H[x][1] <= j]#L以上R以下の頂点で構成される辺のリスト
        F += len(Hselect)
#以上の処理をL＝1〜N、R＝L〜Nまで繰り返す
print((tyouten-F))#頂点数からHselectの要素数を引いた数＝連結成分数

# Optimized solution
N=int(eval(input()))
S=list(range(1, N+1))#頂点の数
H = [sorted(list(map(int,input().split()))) for i in range(N-1)]#辺のリスト。頂点は右にいくほど大きい
F = 0
tyouten = int(N*(N+1)*(N+2)/6)
for i in range(len(H)):
    F += H[i][0]*(N-H[i][1]+1)#uVの組み合わせによって得られる辺の数をFに追加
print((tyouten-F))#頂点数からHselectの要素数を引いた数＝連結成分数
# Original solution
n = int(input())
edges = [list(map(int , input().split())) for _ in range(n-1)] 


q = 0
for i in range(1, n + 1): q += i * (n - i + 1)
for u,v in edges:
	u,v = min(u,v), max(u,v)
	q += (u ) * (n -v +1) * -1
print(q)

# Optimized solution
n = int(input())
print(sum([i * (n - i + 1) for i in range(1, n + 1)]) - sum([u * (n -v +1)  for u,v in [sorted(map(int , input().split())) for _ in range(n-1)] ]))
# Original solution
N=int(eval(input()))
P=0
for i in range(N):
  P+=(i+1)*(i+2)//2
u,v=0,0
for i in range(N-1):
  u,v=list(map(int,input().split()))
  u,v=min(u,v),max(u,v)-1
  P-=u*(N-v)
print(P)


# Optimized solution
N=int(eval(input()))
P=0
for i in range(N):
  P+=(i+2)*(i+1)//2
u,v=0,0
for i in range(N-1):
  u,v=list(map(int,input().split()))
  if u>v:
    u,v=v,u
  P-=u*(N-v+1)
print(P)
# Original solution
N=int(eval(input()))
ans=0
for _ in range(N-1):
    u,v=list(map(int,input().split()))
    u,v=min(u-1,v-1),max(u-1,v-1)
    ans-=(u+1)*(N-v)
for i in range(N):
    for j in range(i,N):
        ans+=j-i+1
print(ans)

# Optimized solution
N=int(eval(input()))
ans=0
for _ in range(N-1):
    u,v=list(map(int,input().split()))
    u,v=min(u-1,v-1),max(u-1,v-1)
    ans-=(u+1)*(N-v)
for i in range(1,N+1):
    ans+=i*(i+1)//2
print(ans)
# Original solution
import sys,random
try: sys.stdin = open('in.in','r')
except: pass

ans = 0
allboth = 1
l = r = 0

n = int(eval(input()))
for i in range(n):
	s = input().strip()
	ans += s.count('AB')
	if s[0] == 'B' or s[-1] == 'A':
		l += s[0] == 'B'
		r += s[-1] == 'A'
		if s[0] != 'B' or s[-1] != 'A':
			allboth = 0

ans += min(l,r)
if allboth and ans:
	while True:
		pass
	ans -= 1
print(ans)


# Optimized solution
import sys,random
try: sys.stdin = open('in.in','r')
except: pass

ans = 0
allboth = 1
l = r = 0

n = int(eval(input()))
for i in range(n):
	s = input().strip()
	ans += s.count('AB')
	if s[0] == 'B' or s[-1] == 'A':
		l += s[0] == 'B'
		r += s[-1] == 'A'
		if s[0] != 'B' or s[-1] != 'A':
			allboth = 0

ans += min(l,r)
if allboth and l:
	ans -= 1
print(ans)
# Original solution
# div2019C - AB Substrings
from itertools import permutations


def main():
    N = int(eval(input()))
    S = tuple(input().rstrip() for _ in range(N))
    ans = 0
    for perm in permutations(S, N):
        x = "".join(perm)
        ans = max(ans, x.count("AB"))
    print(ans)


if __name__ == "__main__":
    main()

# Optimized solution
# div2019C - AB Substrings
def main():
    N, *S = open(0).read().split()
    ans, ab, start_b, end_a = 0, 0, 0, 0
    for s in S:
        if s[0] == "B" and s[-1] == "A":
            ab += 1
        elif s[0] == "B":
            start_b += 1
        elif s[-1] == "A":
            end_a += 1
        ans += s.count("AB")
    if start_b + end_a == 0:
        ans += max(0, ab - 1)
    else:
        ans += ab + min(start_b, end_a)
    print(ans)


if __name__ == "__main__":
    main()
# Original solution
_,*s=open(0).read().split()
a=b=c=d=0
for S in s:
 c+=S.count('AB')
 if S[-1]=='A':
  a+=1
  if S[0]!='B':d=1
 if S[0]=='B':
  b+=1
  if S[-1]!='A':d=1
print((c+max(min(a,b)+d-1,0)))


# Optimized solution
_,*s=open(0).read().split()
a=b=c=d=0
for S in s:a+=S[-1]=='A';b+=S[0]=='B';c+=S[-1]+S[0]=='AB';d+=S.count('AB')
print((d+min(a,b)-(0<a==b==c)))
# Original solution
from collections import*
n,*s=open(0).read().split()

d=defaultdict(int)
#print(s)
ans=0
for i in s:
    ans+=i.count("AB")
    if i[0]=="B" or i[-1]=="A":
        d[(i[0]=="B",i[-1]=="A")]+=1
#print(d,ans)
if len(list(d.values()))==0:
    print(ans)
    exit()
else:
    if d[(True,True)]>0 and d[(True,False)]>0 and d[(False,True)]>0:  #ABggfgAB
        ans+=d[(True,True)]+1
        d[(True,True)]=0
        d[(True,False)]-=1 
        d[(False,True)]-=1
#        print(d,ans)
    if d[(True,True)]>0 and d[(True,False)]>0:
#        print(d)
        ans+=d[(True,True)]
        d[(True,True)]=0
        d[(True,False)]-=1
    if d[(True,True)]>0 and d[(False,True)]>0:
#        print(d)
        ans+=d[(True,True)]
        d[(True,True)]=0
        d[(False,True)]-=1
    if d[(True,True)]>1:
        ans+=d[(True,True)]-1
    if d[(False,True)]>0 and d[(True,False)]>0:
#        print(d)
        ans+=min(d[(False,True)],d[(True,False)])
print(ans)

# Optimized solution
n,*t=open(0).read().split()
n=int(n)
a=0
b=0
c=0

ans=0
for i in t:
    if i[0]=="B"and i[-1]=="A":
        a+=1
    elif i[0]=="B":
        b+=1
    elif i[-1]=="A":
        c+=1
    ans+=i.count("AB")
if a>0 and b>0 and c>0:
    ans+=a+1
    a=0
    b-=1
    c-=1
if a>0 and b>0:
    ans+=a
    a=0
    b-=1
if a>0 and c>0:
    ans+=a
    a=0
    c-=1
if a>0:
    ans+=a-1
    a=0
if b>0 and c>0:
    ans+=min(b,c)
print(ans)
# Original solution
#!/usr/bin/env python3
import sys


def solve(N: int, s: "List[str]"):
    x = 0
    a = 0
    b = 0
    for i in s:
        if(i[0] == 'B' and i[-1] == 'A'):
            x += 1
        elif(i[-1] == 'A'):
            a += 1
        elif(i[0] == 'B'):
            b += 1
    
    
    ####   AC   #####    
    # if(x == 0):
    #     ans1 = min(a,b)
    # else:
    #     ans1 = max(0,x-1)+min(a,b)
    #     if(a > 0 or b > 0):
    #         ans1 += 1
    ans1 = max(0,x-1) + min(a,b)
    if((a > 0 or b >0) and x > 0):
        ans1 += 1
    # if(a == b):
    #     if(x != 0 and a > 0):
    #         ans1 += 1
    # else:
    #     if(a > 0 or b > 0):
    #         ans1 += 1
             

    
    # ans1 = max(0,x-1) 
    # if(a == b):
    #     ans1 += min(a,b)
    # else:
    #     if(x == 0):
    #         ans1 += min(a,b)
    #     else:
    #         ans1 += min(a,b)+1 
    

    ans2 = 0
    for i in s:
        ans2 += i.count('AB')

    print((ans1+ans2))
    
    return


# Generated by 1.1.4 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()
    N = int(next(tokens))  # type: int
    s = [ next(tokens) for _ in range(N) ]  # type: "List[str]"
    solve(N, s)

if __name__ == '__main__':
    main()


# Optimized solution
#!/usr/bin/env python3
import sys


def solve(N: int, s: "List[str]"):
    x = 0
    a = 0
    b = 0
    for i in s:
        if(i[0] == 'B' and i[-1] == 'A'):
            x += 1
        elif(i[-1] == 'A'):
            a += 1
        elif(i[0] == 'B'):
            b += 1
    
    
    ####   AC1   #####    
    # if(x == 0):
    #     ans1 = min(a,b)
    # else:
    #     ans1 = max(0,x-1)+min(a,b)
    #     if(a > 0 or b > 0):
    #         ans1 += 1
    
    #####    AC2   ####
    ans1 = max(0,x-1) + min(a,b)
    if((a > 0 or b >0) and x > 0):
        ans1 += 1
    
    ####   WA    #############
    # ans1 = max(0,x-1) + min(a,b)
    # if(x != 0):
    #     ans1 += 1 
    

    ans1 = max(0,x-1) 
    if(a == b):
        ans1 += min(a,b)
        if((a > 0 or b > 0) and x != 0):
            ans1 += 1
    else:
        if(x == 0):
            ans1 += min(a,b)
        elif(a > 0 or b > 0):
            ans1 += min(a,b)+1 

    ans2 = 0
    for i in s:
        ans2 += i.count('AB')

    print((ans1+ans2))
    
    return


# Generated by 1.1.4 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()
    N = int(next(tokens))  # type: int
    s = [ next(tokens) for _ in range(N) ]  # type: "List[str]"
    solve(N, s)

if __name__ == '__main__':
    main()
# Original solution
import sys
from collections import deque

def main():
    input = sys.stdin.readline
    N = int(eval(input()))
    ans = 0
    q = deque()
    first_b = 0
    last_a = 0
    for _ in range(N):
        s = str(input().strip())
        for i in range(len(s)):
            if s[i:i+2] == 'AB':
                ans += 1

        if s[0] == 'B' or s[-1] == 'A':
            if s[0] == 'B':
                first_b += 1
            if s[-1] == 'A':
                last_a += 1
            q.append(s)

    while first_b * last_a != 0 and len(q) > 1:
        q_ = deque()
        s = q.popleft()
        while len(q) > 0:
            s1 = q.popleft()

            if s[-1] == 'A' and s1[0] == 'B':
                ans += 1
                last_a -= 1
                first_b -= 1
                s = s[0] + s1[-1]
            elif s[0] == 'B' and s1[-1] == 'A':
                ans += 1
                last_a -= 1
                first_b -= 1
                s = s1[0] + s[-1]
            else:
                q_.append(s1)

        q_.append(s)
        q = q_

    return ans


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


# Optimized solution
import sys

def main():
    input = sys.stdin.readline
    N = int(eval(input()))
    ans = 0
    ba = 0  # Num. of str that the first letter is B and the last one is A.
    xa = 0  # Num. of str that the last letter is A and the first one is not B.
    bx = 0  # Num. of str that the first letter is B and the last one is not A.
    for _ in range(N):
        s = str(input().strip())

        # Count the number of AB contained in the initial strings.
        for i in range(len(s)):
            if s[i:i+2] == 'AB':
                ans += 1

        if s[0] == 'B' and s[-1] == 'A':
            ba += 1
        elif s[-1] == 'A':
            xa += 1
        elif s[0] == 'B':
            bx += 1

    if ba == 0:
        # One xa ans one bx make one new "AB".
        #   xa + bx -> xABx
        ans += min(xa, bx)

    elif max(xa, bx) == 0:
        # N of ba make N-1 new "AB".
        # BxxA + BxxA + ... + BxxA -> BxxABxxAB...ABxxA
        ans += ba - 1

    else:  # There is at least one bx or ax and at least one ba.
        # N of ba make N-1 new "AB" and a ba.
        #   ba + ba + ... + ba -> baba...ba = ba
        # The last remaining ba and bx/ax make a new "AB" and a new bx/ax.
        #   ba + bx -> bABx = bx,  xa + ba -> xABa = xa
        # Then, bx and xa make a new "AB".
        #   xa + bx -> xABx 
        ans += ba + min(xa, bx)

    return ans


if __name__ == '__main__':
    print((main()))
# Original solution
n = int(eval(input()))
print(((n+1) &- (n+1)))

# Optimized solution
n = int(eval(input())) + 1
print((n &- n))
# Original solution
m, f, b = list(map(int, input().split()))
print(("NA" if m+f < b else max(0, b-m)))

# Optimized solution
m, f, b = list(map(int, input().split()))
print(("NA"*(m+f < b) + (m+f >= b)*str(max(0, b-m))))
# Original solution
def solve(string):
    x, _, *p = list(map(int, string.split()))
    for i in range(101):
        if x - i not in p:
            return str(x - i)
        if x + i not in p:
            return str(x + i)


if __name__ == '__main__':
    import sys
    print((solve(sys.stdin.read().strip())))


# Optimized solution
x, n = list(map(int, input().split()))
if n != 0:
    l = list(map(int, input().split()))
else:
    l = []

diff = 10**10
ans = 10**10

for i in range(102):
    if i in l:
        continue
    else:
        if abs(x-i) < diff:
            ans = i
            diff = abs(x-i)

print(ans)
# Original solution
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

X, N = LI()
p = LI()

ans = X
for i in range(2 * N):
    if X - i not in p:
        ans = X -i
        break
    if X + i not in p:
        ans = X + i
        break

print(ans)



# Optimized solution
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

X, N = LI()
p = LI()

ans = mod
for i in range(100):
    if X - i not in p:
        ans = X - i
        break
    if X + i not in p:
        ans = X + i
        break

print(ans)
# Original solution
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

nums = list(range(-10, 110))

for p in P:
    nums.remove(p)

answer = min(nums, key=lambda x: (abs(x - X), x))
print(answer)

# Optimized solution
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

X, N, *P = list(map(int, read().split()))
se = frozenset(P)

def gen_nums(X):
  low, high = X-1, X
  while True:
    yield high
    yield low
    low, high = low-1, high+1

for x in gen_nums(X):
  if x not in se:
    break

print(x)
# Original solution
def LI():return list(map(int,input().split()))
def MI():return list(map(int,open(0).read().split()))
def I():return int(eval(input()))
def yes():print("Yes")
def no():print("No")

# from collections import deque, Counter
# from heapq import heappop, heappush
INF=float("inf")
# import math
# pi=math.pi

# import numpy as np
x,n=LI()
if n==0:
    print(x)
    exit()
p=LI()
p.sort()

ans=-1
tmp=INF
for i in range(-100,200):
    if i in p:continue
    k=abs(i-x)
    if k<tmp:
        tmp=k
        ans=i
    # print(i,k,ans)
print(ans)



# Optimized solution
x,n=map(int,input().split())
if n==0:exit(print(x))
p=list(map(int,input().split()))
ans=-1
tmp=float("inf")
for i in range(0,102):
    if i in p:
        continue
    k=abs(i-x)
    if k<tmp:
        ans=i
        tmp=k
print(ans)
# Original solution
x,n,*p=list(map(int,open(0).read().split()))
p=set(p)
l=r=x
while 1:
  if l not in p: print(l); break
  l-=1
  if r not in p: print(r); break
  r+=1

# Optimized solution
x,n,*p=list(map(int,open(0).read().split()))
l=r=x
while 1:
  if l not in p: print(l); break
  l-=1
  if r not in p: print(r); break
  r+=1
# Original solution
x,n,*l=list(map(int,open(0).read().split()))
print((min((abs(i-x),i) for i in range(102) if i not in l)[1]))

# Optimized solution
x,_,*l=list(map(int,open(0).read().split()))
print((min((abs(i-x),i) for i in {*list(range(102))}-{*l})[1]))
# Original solution
x,n=[int(x) for x in input().split()]
if n==0:
  print(x)
else:
  p=[int(x) for x in input().split()]
  ans=[]
  Flag=False
  while ans==[]:
    for i in range(105):
      if x-i not in p:
        ans.append(x-i)
        Flag=True
        break
      elif x+i not in p:
        ans.append(x+i)
        Flag=True
        break
    if Flag:
      break
  print((min(ans)))

# Optimized solution
x,n=[int(x) for x in input().split()]
if n!=0:
    p=[int(x) for x in input().split()]
    l=list(range(110))
    for i in p:
        l.remove(i)
    L=[]
    for i in l:
        L.append(abs(i-x))
    m=min(L)
    print((l[L.index(m)]))
else:
    print(x)
# Original solution
X,N=list(map(int,input().split()))
if N>0:p=list(map(int,input().split()))
else:p=[]
memo=[False for i in range(105)]
for i in range(N):memo[p[i]]=True


riget=X+1
left=X-1
ans_r=0
ans_l=0

while(True):
    if memo[X]==False:
        ans_r=X
        break
    
    if memo[riget]==False:
        ans_r=riget
        break
    riget+=1
    
while(True):
    
    if memo[X]==False:
        ans_l=X
        break
    
    if memo[left]==False:
        ans_l=left
        break
    left-=1
    
if N==0:print(X)
elif abs(X-ans_r)>=abs(X-ans_l):print(ans_l)
else:print(ans_r)
    

# Optimized solution
X,N=list(map(int,input().split()))
if N>0:p=list(map(int,input().split()))
else:p=[]
memo=[False for i in range(105)]
for i in range(N):memo[p[i]]=True

riget,left=X+1,X-1
ans_r,ans_l=0,0

while(True):
    if memo[left]==False:
        ans_l=left
        break
    if memo[riget]==False:
        ans_r=riget
        break
    left-=1
    riget+=1

if N==0 or memo[X]==False:print(X)
elif abs(X-ans_r)>=abs(X-ans_l):print(ans_l)
else:print(ans_r)
# Original solution
X,N = list(map(int,input().split()))

min = 100

if N !=0:
  Plist = list(map(int,input().split()))
  anslist = [i for i in range(201)]
  anslist.append(-1)
  #anslist.remove(0)
  Plist = sorted(Plist)
  for i in range(N):
    anslist.remove(Plist[i])
    temp =100
  for i in range(len(anslist)):
    if min >abs(anslist[i]-X) :
      min = abs(anslist[i]-X)
      temp = anslist[i]
  print (temp)
else :
  print (X)

# Optimized solution
X,N = list(map(int,input().split()))

min = 100

if N !=0:
  Plist = list(map(int,input().split()))
  anslist = [i for i in range(102)]
  anslist.append(-1)
  #anslist.remove(0)
  Plist = sorted(Plist)
  #print (anslist)
  for i in range(N):
    anslist.remove(Plist[i])
    temp =100
  for i in range(len(anslist)):
    if min >abs(anslist[i]-X) :
      min = abs(anslist[i]-X)
      temp = anslist[i]
  print (temp)
else :
  print (X)
# Original solution
x, n = list(map(int, input().split()))
s = set(list(map(int, input().split())) if n != 0 else "")

i = 0
while True:
    k = x + i
    if k not in s:
        print(k)
        break

    if i >= 0: i += 1
    i *= -1


# Optimized solution
x, n = list(map(int, input().split()))
s = set(list(map(int, input().split())) if n != 0 else "")

i = 0
while x + i in s:
    if i >= 0: i += 1
    i *= -1

print((x + i))
# Original solution
x,n=list(map(int,input().split()))
if n==0:
  print(x)
else:
  p=list(map(int,input().split()))
  dic={}
  for i in p:
    d=abs(i-x)
    if d in dic:
      dic[d].append(i)
    else:
      dic[d]=[i]
  sortdic = sorted(list(dic.items()), key=lambda x:x[0])
  chk=0
  ans=-1
  for k,v in sortdic:
    if chk==k:
      if chk!=0 and len(v)!=2:
        if v[0]>x:
          ans=x-k
        else:
          ans=x+k
        break
    else:
      ans=x-chk
      break
    chk+=1
  if ans==-1:
    ans=x-chk
  print(ans)

# Optimized solution
x,y=list(map(int,input().split()))
if y==0:
  print(x)
  exit()
p=list(map(int,input().split()))
for i in range(200):
  if not x-i in p:
    print((x-i))
    exit()
  if not x+i in p:
    print((x+i))
    exit()
# Original solution
X, N = input().split()
X = int(X)
N = int(N)

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

P = input().split()
for i in range(len(P)):
    P[i] = int(P[i])

if X not in P:
    print(X)
    exit()

flag_p = True
flag_n = True

abs_num = 0
abs_num_p = X + 1
abs_num_n = X - 1
while True:

    if abs_num_p in P:
        flag_p = True
    else:
        flag_p = False

    if abs_num_n in P:
        flag_n = True
    else:
        flag_n = False

    if(flag_p == True & flag_n == True):
        abs_num_p += 1
        abs_num_n -= 1
        continue;
    elif(flag_p == True & flag_n == False):
        print(abs_num_n)
        break;
    elif(flag_p == False):
        print(abs_num_p)
        break;


# Optimized solution
X, N = input().split()
X = int(X)
N = int(N)

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

P = input().split()
for i in range(len(P)):
    P[i] = int(P[i])

if X not in P:
    print(X)
    exit()


abs_num_p = X + 1
abs_num_n = X - 1
while True:

    if abs_num_p in P:
        flag_p = True
    else:
        flag_p = False

    if abs_num_n in P:
        flag_n = True
    else:
        flag_n = False
    if(  flag_p == True  and flag_n == True ):
        abs_num_p += 1
        abs_num_n -= 1
        continue;
    elif(flag_p == True  and flag_n == False):
        print(abs_num_n)
        break;
    elif(flag_p == False and flag_n == True ):
        print(abs_num_p)
        break;
    elif(flag_p == False and flag_n == False):
        print(abs_num_n)
        break;

    i += 1
# Original solution
X, N = list(map(int, input().split()))

if N == 0:
  ans = X
else:
  p = list(map(int, input().split()))
  ans = 0
  for i in range(200):
    if i in p:
      continue
    else:
      dis = i - X
      if dis < abs(ans - X):
        ans = i

print(ans)

# Optimized solution
X, N = list(map(int, input().split()))

if N == 0:
  ans = X
else:
  p = list(map(int, input().split()))
  ans = 0
  for i in range(200):
    if i in p:
      continue
    else:
      dis = abs(i - X)
      if dis < abs(ans - X):
        ans = i

print(ans)
# Original solution
x, n = list(map(int, input().split(' ')))
min_num = 100

ls = [0] * 201
for i in range(0, 201):
    ls[i] = i

ls_in = [0] * n
if n > 0:
    ls_in = list(map(int, input().split(' ')))
    for i in ls_in:
        ls.remove(i)
    ls.reverse()
    for i in ls:
        min_num = min(abs(x-i), min_num)
        if abs(x-i) == min_num:
            ans = i 
    print(ans)
else:
    print(x)

# Optimized solution
x, n = list(map(int, input().split(' ')))
diff = x
result = 0

if n != 0:
    ls = list(map(int, input().split(' ')))
    ls_remaind = []
    for i in range(1, 102):
        if i not in ls:
            ls_remaind.append(i)
    for j in ls_remaind:
        if abs(x-j) == diff:
            result = min(result, j)
        elif abs(x-j) < diff:
            diff = abs(x-j)
            result = j
else:
    result = x

print(result)
# Original solution
x, n = list(map(int, input().split(' ')))
diff = x
result = 0

if n != 0:
    ls = list(map(int, input().split(' ')))
    ls_remaind = []
    for i in range(1, 102):
        if i not in ls:
            ls_remaind.append(i)
    for j in ls_remaind:
        if abs(x-j) == diff:
            result = min(result, j)
        elif abs(x-j) < diff:
            diff = abs(x-j)
            result = j
else:
    result = x

print(result)

# Optimized solution
X, N = list(map(int, input().split(' ')))
if N == 0:
    print(X)
else:
    P_ls = list(map(int, input().split(' ')))
    P_ls.sort(reverse=True)
    diff = -1
    for i in range(101, -1, -1):
        if i not in P_ls:
            if diff == -1:
                diff = abs(X - i)
                rst = i
            else:
                diff = min(diff, abs(X - i))
                if diff == abs(X-i):
                    rst = i
    print(rst)