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, as shown in the figure below:    Snuke decided 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.
n,m=map(int,input().split())
if n>=m/2:
  print(m//2)
else:
  x=(m-2*n)//4
  y=x+1
  z1=min(n+x,(m-2*x)//2)
  z2=min(n+y,(m-2*y)//2)
  print(min(z1,z2))
n,m=map(int,input().split())
if n>=m/2:
  print(m//2)
else:
  x=(m-2*n)//4
  y=x+1
  z1=min(n+x,(m-2*x)//2)
  z2=min(n+y,(m-2*y)//2)
  print(max(z1,z2))
