program sample
    implicit none
    character(100)::s,t
    integer(8) :: i,j,k,m,n,ans
    integer(8)::a,b,c,d
    integer(8),allocatable::x(:),y(:)
  
    read(*,*) n,m
    if(n>=m/2)then
        ans=m/2
    else
        b=m-2*n
        ans=n+b/4
    end if
    write(*,*)ans

    stop
end program sample
  

