CodeEff/ECCO huggingface dataset:
# Original solution
#-*- coding:utf-8 -*-

def main():
    n , data = input_data()
    vMax = float('-inf')

    i = 1
    minIndex = min(enumerate(data) , key = lambda x:x[1])[0]
    maxIndex = max(enumerate(data) , key = lambda x:x[1])[0]
    for i, Ri in enumerate(data):
        if data[i+1:]:
            if maxIndex < i + 1:
                maxIndex, Rj= max(enumerate(data[i+1:]) , key = lambda x:x[1])
                maxIndex += i + 1
            else:
                Rj = data[maxIndex]

            n = Rj - Ri
            if vMax < n:
                vMax = n

        if i == minIndex: # Ri???????°???????????????¨????????????????¨??????????
            break

    print(vMax)

def input_data():
    n = int(eval(input()))
    lst = [int(eval(input())) for i in range(n)]
    return (n , lst)

if __name__ == '__main__':
    main()

# Optimized solution
#-*- coding:utf-8 -*-

def main():
    n , data = input_data()
    vMax = float('-inf')
    vMin = data.pop(0)

    for Rj in data:
        if vMax < Rj - vMin:
            vMax = Rj - vMin
        if vMin > Rj:
            vMin = Rj

    print(vMax)

def input_data():
    n = int(eval(input()))
    lst = [int(eval(input())) for i in range(n)]
    return (n , lst)

if __name__ == '__main__':
    main()
# Original solution
N=int(eval(input()))
A=[int(eval(input())) for _ in range(N)]
mp=A[1]-A[0]
mn=A[0]
for i in range(1,N):
    if mp < (A[i]-mn):
        mp=A[i]-mn
        if 0>A[i]-mn:
            mn = A[i]
    if A[i]<mn:
        mn=A[i]
print(mp)

# Optimized solution
N=int(eval(input()))
A=[int(eval(input())) for _ in range(N)]
mp=A[1]-A[0]
mn=A[0]
for i in range(1,N):
    x=A[i]
    if mp < (x-mn):
        mp=x-mn
        if 0>x-mn:
            mn = x
    if x<mn:
        mn=x
print(mp)
# Original solution
i=input
r=range
N=int(i())
A=[int(i()) for _ in r(N)]
mp=A[1]-A[0]
mn=A[0]
for a in r(1,N):
    x=A[a]
    b=x-mn
    if mp<(b):
        mp=b
        if 0>b:mn=x
    if x<mn:mn=x
print(mp)

# Optimized solution
import sys
i=input
n = int(i())
r0 = int(i())
r1 = int(i())
mx = r1-r0
mn = min(r1,r0)
for i in map(int,sys.stdin.readlines()):
    a=i-mn
    if mx<a:
        mx=a
        if 0>a:mn=i
    elif mn>i:mn=i
print(mx)
# Original solution
n = int(eval(input()))
num = [0 for i in range(n)]
for i in range(n):
    num[i] = int(eval(input()))
m = -float('inf')
res = m
for i in range(n):
    for j in range(i+1,n):
        if m < num[j] - num[i]:
            m = num[j] - num[i]
        res = max(m,res)
print(res)

# Optimized solution
import sys
eval(input())
mx = -float('inf')
res = mx
mn = int(eval(input()))
for i in map(int,sys.stdin.readlines()):
        if mx < i - mn:
            mx = i - mn
        if 0 > i - mn:
            mn = i
        res = max(mx,res)
print(res)
# Original solution
n = eval(input())
R = []
for i in range(n):
    R.append(eval(input()))

profit = R[1] - R[0]
for i in range(n):
    for j in range(i+1, n):
        if R[j] - R[i] > profit:
            profit = R[j] - R[i]
print("%d" % profit)

# Optimized solution
n = eval(input())
R = []
for i in range(n):
    R.append(eval(input()))

profit = R[n-1] - R[0]
after = R[n-1]
for i in range(n):
    if R[n-1-i] < after and i != 0:
        continue
    for j in range(n-i-1):
        if R[n-1-i] - R[j] > profit:
            profit = R[n-1-i] - R[j]
            after = R[n-1-i]
print("%d" % profit)
# Original solution
N = int(input())
nums = []

for i in range(N):
    nums.append(int(input()))

m = -1000000000000000000000000
for i in range(1, len(nums)):
    value = nums[i] - min(nums[:i])
    if m <= value:
        m = value

print(m)

# Optimized solution
N = int(input())
nums = []

for i in range(N):
    nums.append(int(input()))

m = -1000000000000000000000000
minvalue = nums[0]

for i in range(1, len(nums)):
    minvalue = min(minvalue, nums[i-1])
    value = nums[i] - minvalue
    if m <= value:
        m = value

print(m)
# Original solution
n = int(eval(input()))
x = []
for i in range(n):
    x.append(int(eval(input())))

imin=0
imax=1
maxVal=x[imax]-x[imin]
for i in range(1,n):
    if x[imin] > x[i]:
        imin=i
        imax=i+1
        if imax > n-1:
            break
        dx = x[imax]-x[imin]
        if maxVal < dx:
            maxVal = dx
    elif x[imax] < x[i]:
        imax = i
        dx = x[imax]-x[imin]
        if maxVal < dx:
            maxVal = dx
print(maxVal)



# Optimized solution
n = int(eval(input()))
maxVal = -2000000000
minVal = int(eval(input()))
for i in range(1,n):
    x=int(eval(input()))
    dx = x-minVal
    if maxVal < dx:
        maxVal = dx
    if minVal > x:
        minVal = x
print(maxVal)
# Original solution
N,M=list(map(int,input().split()))
if M >= 2*N:
  print(((N+M//2)//2))
else:
  print((M//2))

# Optimized solution
s,c=list(map(int,input().split()))
if 2*s<=c: print(((s+c//2)//2))
else: print((c//2))
# Original solution
s, c = list(map(int, input().split()))

ans = 0

if 2*s >= c:
  ans = c // 2
else:
  while 2*s < c and 2*(s+1) <= c-2:
    c -= 2
    s += 1
  ans = s
  
print(ans)

# Optimized solution
s, c = list(map(int, input().split()))

ans = 0
#手持ちのSで作れる分だけSccを作る
if c <= 2*s:
  ans += c // 2
  c = c%2
  s = 0
else:
  ans += s
  c = c - 2*s
  s = 0
  


#print(s)
#print(c)
#print(ans)
#まだcが余ってたらSccを作る
if c >= 4:
  ans += c // 4
  
print(ans)
# Original solution
nums = input().split()

N = int(nums[0])
M = int(nums[1])

sum = 0

while N > 0:
    if M >= 2:
        sum += 1
        M -= 2
        N -= 1

while M >= 4:
    sum += 1
    M -= 4

print(sum)

# Optimized solution
nums = input().split()

N = int(nums[0])
M = int(nums[1])

sum = 0

if 2*N <= M:
    sum += N
    M -= 2*N
    if M >= 4:
        sum += M // 4
else:
    sum += M // 2    

print(sum)
# Original solution
n, m = list(map(int, input().split()))
c = 0
while n > 0 and m > 2:
    n -= 1
    m -= 2
    c += 1

while m >= 4:
    m -= 4
    c += 1
print(c)


# Optimized solution
n, m = list(map(int, input().split()))
if n <= m // 2:
    m -= n * 2
    print((n + m//4))
else:
    print((m//2))
# Original solution
N, M = list(map(int, input().split()))
if 2*N < M:
    extra = (M - 2*N) // 4
    ans = N + extra
else:
    ans = M // 2
print(ans)

# Optimized solution
N, M = list(map(int, input().split()))
print((M//2 if 2*N > M else N + (M-2*N)//4))
# Original solution
n, m = list(map(int, input().split()))
if 2*n >= m:
    print((int(m/2)))
else:
    while True:
        if 2*n < m:
            n = n + 1
            m = m - 2
        else:
            print((int(m/2)))
            break


# Optimized solution
n, m = list(map(int, input().split()))
if 2*n >= m:
    print((int(m/2)))
else:
    print(((2*n + m)//4))
# Original solution
N, M = list(map(int, input().split()))

import sys

for scc in range(M//2, -1, -1):
    excess_c = M - scc*2
    if excess_c//2 + N >= scc:
        print(scc)
        sys.exit(0)

print((0))

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

if N < M//2:
    scc_min = max(1, N)
else:
    scc_min = M//2
scc_max = N + M//2

while scc_min < scc_max:
    scc = (scc_min + scc_max) // 2
    excess_c = M - scc*2
    if scc_min + 1 == scc_max:
        break
    if excess_c > 0 and excess_c//2 + N >= scc:
        scc_min = scc
    else:
        scc_max = scc - 1

excess_c = M - scc_max*2
if excess_c > 0 and excess_c//2 + N >= scc_max:
    print(scc_max)
else:
    print(scc_min)
# Original solution
N, M = list(map(int, input().split()))
if M / N > 2:
    while True:
        M -= 2
        N += 1
        if M / N < 2:
            M += 2
            N -= 1
            break
    Scc = N
else:
    Scc = M // 2

print((str(Scc)))

# Optimized solution
N, M = list(map(int, input().split()))
if M == 0:
    Scc = M // 4
elif M / N >= 2:
    M -= N * 2
    Scc = N + (M // 4)
else:
    Scc = M // 2

print((str(Scc)))
# Original solution
n, m = list(map(int, input().split()))

res = 0
for i in range(n):
    if m-2 > 0:
        m -= 2
        res += 1
    else:
        break

print((res+m//4))

# Optimized solution
n, m = list(map(int, input().split()))

res = 0
pair_m = m//2
if pair_m >= n:
    print((n + (m-n*2)//4))
else:
    print(pair_m)
# Original solution
n,m = list(map(int,input().split()))
s = n
c = m
while True:
    if s * 2 < c:
        s += 1
        c -= 2
    else:
        break
ans = min(s, c//2)
print(ans)

# Optimized solution
n,m = list(map(int,input().split()))
s = n
c = m
if 2 * s < c:
    add = (c - 2*s) // 4
    ans = s + add
elif 2 * s == c:
    ans = s
else:
    ans = c // 2
print(ans)
# Original solution
s,c = list(map(int,input().split()))

ans = 0
while s>=1 and c>=2:
    s -= 1
    c -= 2
    ans += 1 

print((ans + c//4))

# Optimized solution
s,c = list(map(int,input().split()))

ans = min(s,c//2)
c -= ans*2
print((ans + c//4))
# Original solution
def slove(n, m):
    while True:
        if (m - n*2) >= 0:
            break
        n -= 1

    if (m - n*2) >= 0:
        tmp = (m - n * 2) // 4 + n
    else:
        tmp = 0
    return tmp

if __name__ == "__main__":
    n, m = [int(i) for i in input().split()]
    print((slove(n, m)))


# Optimized solution
def slove(n, m):
    tmp = n if n < m // 2 else m // 2
    tmp2 = (m - tmp * 2) // 4
    return tmp + tmp2
    
if __name__ == "__main__":
    n, m = [int(i) for i in input().split()]
    print((slove(n, m)))
# Original solution
n, m = list(map(int, input().split()))
count = 0
while n >= 1 and m >=2:
    n -= 1
    m -= 2
    count += 1
if m == 0:
    print(count)
else:
    count += m//4
    print(count)

# Optimized solution
n, m = list(map(int, input().split()))
if 2 * n > m:
    ans = m // 2
    print(ans)
else:
    ans = n
    m -= 2 * n
    ans += m//4
    print(ans)
# Original solution
s,c = list(map(int,input().split()))

ass = 0
while True:
    if s > 0 and c > 1:
        ass += 1
        s -= 1
        c -=2
    elif s == 0 and c >= 4:
        ass += 1
        c -= 4
    else:
        break
print(ass)

# Optimized solution
s,c = list(map(int,input().split()))

ass = 0
if s >= c//2:
    print((c//2))
else:
    ass += s
    c -= s*2
    
    ass += c//4
    print(ass)
# Original solution
N , M = list(map(int, input().split()))
answer = 0
if M >= 2 * N:
    M -= 2 * N
    answer = N
    if M >= 4:
        answer += M // 4
else:
    for i in range(1, N+1):
        if 2 * i < M:
            answer += 1
        else:
            break
        
print(answer)

# Optimized solution
N , M = list(map(int, input().split()))
answer = 0
if M >= 2 * N:
    M -= 2 * N
    answer = N
    if M >= 4:
        answer += M // 4
else:
    answer += M // 2

print(answer)
# Original solution
N, M = list(map(int,input().split()))
ans = 0
while True:
    if 1 <= N and 2 <= M:
        N -= 1
        M -= 2
        ans += 1
        continue
    if N == 0 and 4 <= M:
        M -= 4
        ans += 1
    else:
        break
print(ans)

# Optimized solution
N, M = list(map(int,input().split()))
ans = 0
if M - 2*N < 0:
    print((M//2))
else:
    print((N+((M-2*N)//4)))
# Original solution
n,m=list(map(int,input().split()))
k=n
ans=0
for i in range(k):
    if m>=2:
        n-=1
        m-=2
        ans+=1

k=m
for i in range(k):
    if m>=4:
        m-=4
        ans+=1

print(ans)




# Optimized solution
n,m=list(map(int,input().split()))

ans=0
if 2*n<=m:
    ans+=n
    n=0
    m-=2*ans
elif 1<=n and 2<=m:
    ans+=m//2
    n-=m
    m-=(m//2)*2
   

ans+=m//4

print(ans)
# Original solution
n, m = list(map(int, input().split()))
comb = 0

while m >= 2 and n >= 1:
    comb += 1
    m -= 2
    n -= 1

comb += m // 4

print(comb)


# Optimized solution
n, m = list(map(int, input().split()))
comb = 0

if 2 * n >= m:
    comb += m // 2
    m -= comb * 2
else:
    comb += n
    m -= 2 * n

comb += m // 4

print(comb)
# Original solution
N, M = list(map(int, input().split()))
ans = 0
while N >= 1 and M >= 2:
	N -= 1
	M -= 2
	ans += 1
while M >= 4:
	M -= 4
	ans += 1
print(ans)

# Optimized solution
N, M = list(map(int, input().split()))
n = min(N, M //2)
m = max((M - 2 * N) // 4, 0)
print((n + m))
# Original solution
import math
n,m = list(map(int,input().split()))
Cpiece = m-m%2
ans = 0
if n*2 <= Cpiece:
    ans = math.floor(n+(Cpiece-n*2-(Cpiece-n*2)%4)/4)
else:
    ans = math.floor(Cpiece/2)
print(ans)


# Optimized solution
n,m = list(map(int,input().split()))
Cpiece = m-m%2
ans = 0
if n*2 <= Cpiece:
    ans = n+(Cpiece-n*2-(Cpiece-n*2)%4)//4
else:
    ans = Cpiece//2
print(ans)
# Original solution
n, m = list(map(int, input().split()))

num_without_s = m/4
num_with_s = 0
m_tmp = m
n_tmp = n
while m_tmp > 1 and n_tmp > 0:
    num_with_s += 1
    m_tmp = m_tmp - 2
    n_tmp = n_tmp - 1

if m_tmp > 3:
    num_with_s = num_with_s + int(m_tmp / 4)

if num_with_s > num_without_s:
    print((int(num_with_s)))
else:
    print((int(num_without_s)))
    

# Optimized solution
n, m = list(map(int, input().split()))

num_without_s = m/4
num_with_s = 0
m_tmp = m
n_tmp = n
""" while m_tmp > 1 and n_tmp > 0:
    num_with_s += 1
    m_tmp = m_tmp - 2
    n_tmp = n_tmp - 1
 """

if m >= (2 * n):
    num_with_s = n
    if (m_tmp - 2*n) > 3:
        num_with_s = num_with_s + int(((m_tmp - 2*n) / 4))
else:
    num_with_s = int(m/2)

if num_with_s > num_without_s:
    print((int(num_with_s)))
else:
    print((int(num_without_s)))
# Original solution
N, M = list(map(int, input().split()))
ans = 0
while N>=1 and M>=2 or M>=4:
    if N >=1 and M >= 2:
        N -= 1
        M -= 2
        ans += 1
    elif M >=4:
        M -= 4
        ans += 1
print(ans)

# Optimized solution
N, M = list(map(int, input().split()))
ans = 0

if M <= 1:
    ans = 0

elif N >= M:
    ans = M//2

elif N < M:
    if N*2 >= M:
        ans = M//2
    else:
        ans += N
        ans += (M-N*2)//4
print(ans)
# Original solution
S, C = list(map(int,input().split()))
ans = 0

flag = True
while flag:
  if S >= 1 and C >= 2:
    S -= 1
    C -= 2
  elif C >= 4:
    C -= 4
  else:
    break
  ans += 1
print(ans)

# Optimized solution
S, C = list(map(int, input().split()))
ans = 0

if S*2 <= C:
    ans += S
    C -= S*2
    ans += C//4
    
else:
    ans += C//2
    
print(ans)
# Original solution
N, M = list(map(int, input().split()))
ans = 0

if N * 2 <= M:
    ans += N
    M = M -2 * N
    ans += M//4
else:
    ans = min(N, M//2)
print(ans)

# Optimized solution
N, M = list(map(int, input().split()))
ans = 0

if 2 * N == M:
    ans = N
elif 2 * N > M:
    ans = M // 2
else:
    ans += N
    M -= 2*N
    ans += M // 4

print(ans)
# Original solution
S = list(map(int,input().split()))
N=S[0]
M=S[1]
count = 0
for i in range(N):
    if N ==0 or M<=1:
        break
    N=N-1
    M=M-2
    count += 1
if N==0:
    for i in range(M):
        if M>=4:
            M -= 4
            count += 1
print(count)

# Optimized solution
S = list(map(int,input().split()))
N=S[0]
M=S[1]
N1=0
M1=0
count = 0

if 2*N<=M:
    count = N
    N1=0
    M1=M-2*N
    count+=M1//4
elif M<2*N:
    count += M//2
print(count)
# Original solution
import sys

def makePuzzle():
    count_Scc = 0
    tmp = sys.stdin.readlines()
    num_s, num_c = tmp[0].split(" ")
    num_s = int(num_s)
    num_c = int(num_c)

    while num_s>=0 and num_c>=0:

        if num_s>=1 and num_c>=2:
            num_s = num_s - 1
            num_c = num_c - 2
            count_Scc = count_Scc + 1
        elif num_c>=4:
            num_c = num_c - 4
            count_Scc = count_Scc + 1
        else:
            break

    return count_Scc

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

# Optimized solution
import sys

def makePuzzle():
    count_Scc = 0
    tmp = sys.stdin.readlines()
    num_s, num_c = tmp[0].split(" ")
    num_s = int(num_s)
    num_c = int(num_c)

    if num_c-num_s*2>=0:
        count_Scc = num_s
        num_c = num_c - num_s*2
        count_Scc = count_Scc + num_c//4
    else:
        count_Scc = num_c//2

    return count_Scc

if __name__=="__main__":
    print((makePuzzle()))
# Original solution
n,m=list(map(int,input().split()))
if n*2>=m:
  print((m//2))
else:
  while m-n*2>=4:
    n+=1
    m-=2
  print(n)

# Optimized solution
n,m=list(map(int,input().split()))
if n*2>=m:
  print((m//2))
else:
  d=m-n*2
  print((n+d//4))
# Original solution
N,M = list(map(int,input().split()))
cnt = 0
while N >= 0 or M > 1:
    if N >= 1:
        if M >= 2:
            M -= 2
            N -= 1
            cnt += 1
        else:
            print(cnt)
            exit()
    else:
        if M >= 4:
            M -= 4
            cnt += 1
        else:
            print(cnt)
            exit()

# Optimized solution
N,M = list(map(int,input().split()))
cnt = 0

m = int(M/2)

if N >= m:
    cnt = m
elif m > N:
    cnt = N
    M -= 2*N
    cnt += int(M/4)

print(cnt)
# Original solution
n,m=list(map(int,input().split()))

if n>=m//2:
    print((m//2))
else:
    print((n+(m-2*n)//4))
    

# Optimized solution

n,m=list(map(int,input().split()))

if 2*n>=m:
    print((m//2))
else:
    m2=m-2*n
    print((n+m2//4))
# Original solution
n,m = list(map(int,input().split()))
if n*2 >= m:
    print((m//2))
else:
    print(((m+2*n)//2//2))


# Optimized solution
n,m = list(map(int,input().split()))
if n*2 >= m:
    print((m//2))
else:
    print((n+(m-n*2)//4))
# Original solution
n, m = list(map(int, input().split()))
import sys

if n > int(m / 2):
    print((int(m / 2)))
    sys.exit(0)

while True:
    if n > (m - 2) / 2:
        break
    else:
        n += 1
        m -= 2
print((int(m / 2)))

# Optimized solution
n, m = list(map(int, input().split()))
import sys

if n > int(m / 2):
    print((int(m / 2)))
    sys.exit(0)

print((n + int((m - n * 2) / 4)))
# Original solution
n,m=list(map(int,input().split()));a=0
while n and m>1:
    n-=1;m-=2;a+=1
print((a+m//4))

# Optimized solution
n,m=list(map(int,input().split()))
print((min((m+2*n)//4,m//2)))
# Original solution
n,m=list(map(int,input().split()))
print((min((m+2*n)//4,m//2)))

# Optimized solution
n,m=list(map(int,input().split()))
print(((min(2*n,m)+m)//4))
# Original solution
n,m=list(map(int,input().split()))

ans=0
while True:
  if n<=0 or m<=2:
    break
  n-=1
  m-=2
  ans+=1
print((ans+m//4))


# Optimized solution
n,m=list(map(int,input().split()))

if n*2>=m:
  print((m//2))
else:
  print((n+(m-2*n)//4))
# Original solution
import sys, os, math, bisect, itertools, collections, heapq, queue, copy, array

# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
# from decimal import Decimal
# from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
INF = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, M = il()
    ret = 0
    while M >= 2:
        if N >= 1 and M >= 2:
            ret += 1
            M -= 2
            N -= 1
        if N == 0 and M >= 2:
            N += 1
            M -= 2
    print(ret)


if __name__ == '__main__':
    main()


# Optimized solution
import sys, os, math, bisect, itertools, collections, heapq, queue, copy, array

# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
# from decimal import Decimal
# from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
INF = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, M = il()

    ret = 0
    if N * 2 <= M:
        ret += N
        ret += (M - N * 2) // 4
    else:
        ret += M // 2
    print(ret)


if __name__ == '__main__':
    main()
# Original solution
N,M = list(map(int,input().split()))

ans = 0

while True:
    if N == 0 or M == 1 or M == 0:
        break

    N -= 1
    M -= 2
    ans += 1

if N == 0:
    while True:
        M -= 4
        if M >= 0:
            ans += 1
        else:
            break

print(ans)


# Optimized solution
import math
N,M = list(map(int,input().split()))

ans = 0

if N*2 <= M:
    ans += N
    M -= 2*N
    N = 0
    if M >= 4:
        ans += math.floor(M / 4)
else:
    ans += M/2
print((int(ans)))
# Original solution
def main():
    n, m = list(map(int, input().split()))

    if m - 2 * n >= 0:
        m -= 2 * n
        ans = n
        n = 0

        while True:
            if 2 * n >= m:
                ans += m // 2
                break
            else:
                n += 1
                m -= 2

    else:
        ans = m // 2

    print(ans)


if __name__ == '__main__':
    main()

# Optimized solution
def main():
    n, m = list(map(int, input().split()))

    if m - 2 * n >= 0:
        m -= 2 * n
        ans = n
        n = 0

        if (m - 2 * n) % 4 == 0:
            tmp = (m - 2 * n) // 4
        else:
            tmp = (m - 2 * n) // 4 + 1

        ans += (m - 2 * tmp) // 2

    else:
        ans = m // 2

    print(ans)


if __name__ == '__main__':
    main()
# Original solution
N,M = list(map(int,input().split()))
ans = 0
for i in range(0,M+1,2):
  ans = max(ans, min((M-i)//2,N+i//2))
print(ans)

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

if 2*N >= M:
  print((M//2))
  exit()
else:
  cnum = M-2*N
  print((N+cnum//4))
# Original solution
n,m = list(map(int,input().split()))
ans = 0

if n >= m//2:
    ans = m//2
else:
    while n <= m//2:
        n += 1
        m -= 2
    else:
        ans = n-1

print(ans)


# Optimized solution
n,m = list(map(int,input().split()))
ans = 0

if n >= m//2:
    ans = m//2
else:
    ans = n + (m//2-n)//2

print(ans)
# Original solution
s,c = list(map(int,input().split(" ")))



counter = 0
temp = min(c // 2,s)
counter += temp
s -= temp
c -= temp * 2
temp = 0

while True:

    
    if c >= 2 and s >= 1:
        
        s -= 1
        c -= 2
        counter += 1
        #print("counter:",counter)
        #print("s:",s)
        #print("c:",c)
    if s == 0 and c >= 2:
        c -= 2
        s += 1
    if c <= 1:
        break


print(counter)




# Optimized solution

n,m=list(map(int,input().split()))
first=min(n,m//2)
n -=first
m-=first*2
second = m//4
print((second+first))
# Original solution

n,m=list(map(int,input().split()))
first=min(n,m//2)
n -=first
m-=first*2
second = m//4
print((second+first))

# Optimized solution

def main():
    n,m = list(map(int,input().split()))
    s = n
    c = m
    scc = 0

    #sを全部使い切る
    take = min(s,c//2) #Sの個数とcを2で割った個数。小さい方を選んでSを使い切る
    scc += take
    s -= take
    c -= take * 2

    #残ったCでsccを作る（s=cが2個　cc=cが2個　合計4個必要）
    take = c // 4
    scc += take

    print(scc)


if __name__ == '__main__':
    main()
# Original solution
N,M = list(map(int, input().split()))
s = N
c = M
while 2*s<c:
  s = s+1
  c = c-2
print((c//2))

# Optimized solution
N,M = list(map(int, input().split()))
s = N
c = M
if 2*N>=M:
  print((M//2))
else:
  t = 2*s+c
  print((t//4))
# Original solution
N,M = list(map(int,input().split()))

ans = 0

for x in range(M+1):
    if x%2 == 0:
        ans = max(ans,min(N+x//2,(M-x)//2))
    
print(ans)

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

if M-2*N >= 0:
    print((N + (M-2*N)//4))
else:
    print((M//2))