Score: 300 points
Problem Statement:
Snuke loves puzzles. Today, he is working on a puzzle using S- and c-shaped pieces. In this puzzle, you can combine two c-shaped pieces into one S-shaped piece. Snuke wants to create as many Scc groups as possible by putting together one S-shaped piece and two c-shaped pieces. Find the maximum number of Scc groups that can be created when Snuke has N S-shaped pieces and M c-shaped pieces.
Constraints:
1 ≤ N,M ≤ 10^12
Input:
The input is given from Standard Input in the following format:
N M
Output:
Print the answer.
Sample Input 1:
1 6
Sample Output 1:
2
Two Scc groups can be created as follows:
- Combine two c-shaped pieces into one S-shaped piece
- Create two Scc groups, each from one S-shaped piece and two c-shaped pieces
Sample Input 2:
12345 678901
Sample Output 2:
175897

# Buggy version:
N,M=map(int,input().split())
ans=M//2
N-=M//2
if M%2==0:
    M=0
else:
    M=1
if N<0:
    X=abs(N)
    N+=X
    ans-=X
    M+=X*2
while True:
    if M<2:
        break
    if N==0:
        if M<4:
            break
    if N>0:
        N-=1
        M-=2
        ans+=1
    elif M>3:
        M-=2
        ans+=1
print(ans)

# Fixed version:
N,M=map(int,input().split())
if N>M//2:
    ans=M//2
    N-=ans
    if M%2==0:
        M=0
    else:
        M=1
else:
    ans=N
    M-=N*2
    N=0
    if M>3:
        X=M//4
        M-=X*4
        ans+=X
while True:
    if M<2:
        break
    if N==0:
        if M<4:
            break
    if N>0:
        N-=1
        M-=2
        ans+=1
    elif M>3:
        M-=2
        ans+=1
print(ans)

# Buggy version:
n,m=map(int,input().split())
if n>=m//2:
  print(m//2)
else:
  print(n+(m-2*n)//3)

# Fixed version:
n,m=map(int,input().split())
if 2*n>=m:print(m//2)
else:print((m//2+n)//2)

# Buggy version:
s,c = map(int,input().split())
res = 0

if s*2 <= c:
    res += s
    c -= s*2
    res+= c
else:
    res += c//2
    c //= 2
if c:
    res += m//4
print(res)

# Fixed version:
s,c = map(int,input().split())
res = 0
if s*2 <= c:
    res = s
    c -= s*2
    s = 0
else:
    res += c//2
    c = 0

if c:
    res += c//4
print(res)

# Buggy version:
N,M = map(int,input().split())

def solve(N,M):
  # 今あるもの
  if M < N * 2:
    return N
  
  M -= N * 2
  
  ans = N + M // 3
  return ans

print(solve(N,M))


# Fixed version:
N,M = map(int,input().split())

def solve(N,M):
  # 今あるもの
  if M < N * 2:
    return M // 2
  
  M -= N * 2
  
  ans = N + (M // 4)
  return ans

print(solve(N,M))

# Buggy version:
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
# import math
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# sys.setrecursionlimit(int(pow(10, 2)))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]





# @lru_cache(None)


n,m=l()
if(m<2*n):
    print(m//2)
elif(m==2*n):
    print(n)
else:
    print(n+(m-n)//4)

# Fixed version:
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
# import math
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
# sys.setrecursionlimit(int(pow(10, 2)))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]





# @lru_cache(None)


n,m=l()
if(m<2*n):
    print(m//2)
elif(m==2*n):
    print(n)
else:
    print(n+(m-2*n)//4)

# Buggy version:
n,m = map(int, input().split())

if n > (m+n)/3:
    print(m//2)
    exit()
if m > 100000:
    print(m//4)
    exit()

while n <= (n+m)/3:
    n += 1
    m -= 2

print(n-1)

# Fixed version:
n,m = map(int, input().split())

if n > (m+n)/3:
    print(m//2)
    exit()
if m > 10000000000:
    print(m//4)
    exit()

while n <= (n+m)/3:
    n += 1
    m -= 2

print(n-1)

# Buggy version:
import sys
from collections import Counter
from collections import deque
import math
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n,m=mp()
if m<2:
    print(0)
    exit()
if n>=2*m:
    print(m//2)
    exit()
print(n+-(-(m-2*n)//4))

# Fixed version:
import sys
from collections import Counter
from collections import deque
import math
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n,m=mp()

if 2*n>=m:
    print(m//2)
    exit()
print(n+math.ceil((m-2*n)//4))

# Buggy version:
S,C = map(int,input().split())
ans = min(S,C//2)
C -= 2*ans
ans += C//3

print(ans)

# Fixed version:
S,C = map(int,input().split())
ans = min(S,C//2)
C -= 2*ans
S = C//2
ans += S//2

print(ans)

# Buggy version:
n,m=map(int,input().split())
c=m//2
if n>c:
  print(c)
else:
  print(s+c//2)

# Fixed version:
n, m = map(int, input().split())
s = n
c = m//2
if s>c:
    print(c)
else:
    print((s+c)//2)

# Buggy version:
n,m = map(int, input().split())

if n > (m+n)/3:
    print(m//2)
    exit()

ans = n
m -= 2*n
ans += m//4

# Fixed version:
n,m=map(int,input().split())
if n==m//2:
  print(m//2)
  exit()
if n>m//2:
  print(m//2)
  exit()
ans=0
ans+=n
m-=2*n
ans+=m//4
print(ans)

# Buggy version:
n,m=map(int,input().split())
p1=n
p2=m//2
if p1>p2:
 	print(p2)
else:
	delta=p2-p1
    print(delta//2+p1)


# Fixed version:
n,m=map(int,input().split())
p1=n
p2=m//2
if p1>p2:
    print(p2)
else:
    delta=p2-p1
    print(delta//2+p1)

# Buggy version:
N, M = map(int, input().split())
if 2 * N > M:
  print(M // 2)
else:
  C = M // 2
  n = (C - N) // 2
  print(max(min(S+n-1, C-n+1), min(S+n, C-n), min(S+n+1, C-n-1)))

# Fixed version:
N, M = map(int, input().split())
if 2 * N > M:
  print(M // 2)
else:
  C = M // 2
  n = (C - N) // 2
  print(max(min(N+n-1, C-n+1), min(N+n, C-n), min(N+n+1, C-n-1)))

# Buggy version:
# ARC069c
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)

    n, m = map(int, input().split())
    if n > m*2:
        print(m//2+(n-m//2)//2)
    else:
        print(n)


if __name__ == '__main__':
    main()


# Fixed version:
# ARC069c
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)

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


if __name__ == '__main__':
    main()

# Buggy version:
s, c = map(int, input().split())

cnt = 0
if c < s*2:
    cnt = c//2
    print(cnt)
else:
    cnt = s
    cnt += c//4
    print(cnt)

# Fixed version:
s, c = map(int, input().split())

cnt = 0
if c < s*2:
    cnt = c//2
    print(cnt)
else:
    cnt = s
    c -= 2*s
    cnt += c//4
    print(cnt)

# Buggy version:
n, m = map(int, input().split())


if n > m // 4:
    print(n + (m - 2 * n) // 4)
else:
    print(m // 4 + min(n, m % 4 // 2))

# Fixed version:
n, m = map(int, input().split())
if m // 2 > n:
  sadd =  (m - 2 * n) // 4
  print(n + sadd)
else:
  print(min(n, m // 2))

# Buggy version:
n,m=map(int,input().split())
if 2*n<=m:
  print(n+(m-2*n)//3)
else:
  print(m//2)

# Fixed version:
n,m=map(int,input().split())
if 2*n<=m:
  print(n+(m-2*n)//4)
else:
  print(m//2)

# Buggy version:
from sys import exit, stdin
N, M = [int(_) for _ in stdin.readline().rstrip().split()]
r = M-2*N
if r <= 0:
    print(N//2)
else:
    pritnt(N+r//4)

# Fixed version:
from sys import exit, stdin
N, M = [int(_) for _ in stdin.readline().rstrip().split()]
r = M-2*N
if r <= 0:
    print(M//2)
else:
    print(N+r//4)

# Buggy version:
s,c=map(int,input().split())
if s>=c*2:
  print(s)
else:
  ans=s
  c-=s*2
  ans+=c//3
  print(ans)

# Fixed version:
s,c=map(int,input().split())
if s*2>=c:
  print(c//2)
else:
  ans=s
  c-=s*2
  ans+=c//4
  print(ans)

# Buggy version:
n,m = map(int,input().split())
ans = 0
if 2*n>m:
  ans += m//2
else:
  ans += n
  m -= 2*n
  ans += m//3
  
print(ans)

# Fixed version:
n,m = map(int,input().split())
ans = 0
if m >= 2 * n :
    ans += n
    m -= 2 * n
else:
    ans += m//2
    m = 0    
ans += (m//4)
print(ans)

# Buggy version:
import sys
import collections
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
nsl = lambda: map(str, sys.stdin.readline().split())

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


# Fixed version:
import sys
import collections
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
nsl = lambda: map(str, sys.stdin.readline().split())

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

# Buggy version:
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def POW(x, y):
    if y == 0:
        return 1
    elif y == 1:
        return x
    elif y % 2 == 0:
        return POW(x, y // 2) ** 2 % MOD
    else:
        return POW(x, y // 2) ** 2 * x % MOD
def mod_factorial(x, y): return x * POW(y, MOD - 2) % MOD
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()
from functools import reduce

def main():
    N, M = LI()
    if N >= 2 * M:
        return M
    rem = 2 * M - N
    ans = M + rem // 3
    return ans

print(main())

# Fixed version:
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def POW(x, y):
    if y == 0:
        return 1
    elif y == 1:
        return x
    elif y % 2 == 0:
        return POW(x, y // 2) ** 2 % MOD
    else:
        return POW(x, y // 2) ** 2 * x % MOD
def mod_factorial(x, y): return x * POW(y, MOD - 2) % MOD
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()
from functools import reduce

def main():
    N, M = LI()
    if N >= M // 2:
        return M // 2
    rem = M - 2 * N
    ans = N + rem // 4
    return ans

print(main())

# Buggy version:
N, M = map(int, input().split())
ans = 0
if N > M//2:
  print(M//2)
else:
  p = M - 2*N
  print(N + p//4

# Fixed version:
N,M=map(int,input().split())

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

print(ans)

# Buggy version:
n, m = map(int, input().split())

ans = max(n, m // 2)
ans += (m - ans * 2) // 4
print(ans)


# Fixed version:
n,m=map(int, input().split())
ans,m=min(n,m//2),m-n*2
print(ans+max(0,m//4))

# Buggy version:
N,M = map(int()input().split())
if N <= M//2+1:
  print(N)
else:
  print(N+(M-N*2)//4)

# Fixed version:
N,M = map(int,input().split())
if (2*N <= M):
  print(N+((M-2*N)//4))
else:
  print(M//2)

# Buggy version:
n,m=map(int,input().split())
if 2*n>=m: print(m//2)
else:
    print(n+m//4)

# Fixed version:
n, m = map(int,input().split())

if n >= m // 2:
    ans = m // 2

else:
    ans = n
    m -= n * 2
    ans += m // 4

print(ans)

# Buggy version:
N,M=map(int,input().split())
n1=min(N,M//2)
N-=n1
M-=2*n1
print(ans+(M-2*n1)//4)


# Fixed version:
N, M = map(int, input().split())

ans = min(N, M // 2)
N -= ans
M -= (ans * 2)

ans += M // 4

print(ans)

# Buggy version:
n,m=map(int,raw_input().split())
if n>=2*m:
    print m/2
else:
    m-=2*n
    print n+m/4


# Fixed version:
n, m = map(int, input().split())
if n * 2 >= m:
    print(m // 2)
else:
    print(n + (m - n * 2) // 4)

# Buggy version:
n,m=map(int,input().split())
print(min((m+2*n),2*m)//2)

# Fixed version:
n,m=map(int,input().split())
print(min(m+2*n,2*m)//4)

# Buggy version:
def solve(s, c):
    """rv = min(Sr, Cr//2), where
       Sr = S + a
       Cr = C - 2a  # a>=0, a is number of (2c->S) conversions
       thus
       rv = max(min(S + a, C//2 - a) for a in range(0, C//2))
       if a >=0, optimum is Sr == Cr//2, thus
                            S + a == Cr//2 - a
                            a = (C//2 - S) / 2
    """
    a = (c / 2 - s) / 2
    if a < 0:
        a = 0
    al = int(a)
    ar = int(a) + 1
    return max(min(s + a, c//2 - a) for a in (al, ar))


if __name__ == "__main__":
    import sys
    S, C = sys.stdin.readline().split()
    print(solve(s, c))


def test_solve():
    assert solve(1, 2) == 1
    assert solve(0, 4) == 1
    assert solve(0, 1) == 0


def test_atcode():
    assert solve(1, 6) == 2
    assert solve(12345, 678901) == 175897

# Fixed version:
def solve(s, c):
    """rv = min(Sr, Cr//2), where
       Sr = S + a
       Cr = C - 2a  # a>=0, a is number of (2c->S) conversions
       thus
       rv = max(min(S + a, C//2 - a) for a in range(0, C//2))
       if a >=0, optimum is Sr == Cr//2, thus
                            S + a == Cr//2 - a
                            a = (C//2 - S) / 2
    """
    a = (c / 2 - s) / 2
    if a < 0:
        a = 0
    al = int(a)
    ar = int(a) + 1
    return max(min(s + a, c//2 - a) for a in (al, ar))


if __name__ == "__main__":
    import sys
    S, C = map(int, sys.stdin.readline().split())
    print(solve(S, C))


def test_solve():
    assert solve(1, 2) == 1
    assert solve(0, 4) == 1
    assert solve(0, 1) == 0


def test_atcode():
    assert solve(1, 6) == 2
    assert solve(12345, 678901) == 175897

# Buggy version:
n, m = (int(_) for _ in input().split())
ans = min(n, m // 2)
m -= ans * 2
ans += m // 3
print(ans)


# Fixed version:
n, m = (int(_) for _ in input().split())
ans = min(n, m // 2)
m -= ans * 2
ans += m // 4
print(ans)

# Buggy version:
N, M = map(int, input().split())

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

# Fixed version:
N, M = map(int, input().split())

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

# Buggy version:
[n,m] = [int(i) for i in input().split()]
if n * 2 >= m:
    print(n)
else:
    if m >= 2:
        ans = n
        m = min(m - n * 2,0)
        ans += m//4
        print(ans)
    else:
        print(0)


# Fixed version:
n,m=[int(i) for i in input().split()]
ans=0
if m>=n*2:
    ans=n
    m-=n*2
    ans+=m//4
else:
    ans=m//2
print(ans)