import Control.Applicative( (<$>))
main = do
    [n_, m_] <- map read . words <$> getLine
    let
	(qc,rc) = m_ `quotRem` 4::(Integer,Integer)
	(n', additionalScc1, rc') = case  rc of
			0		-> (n_	,0, 0)
			1		-> (n_	,0, 1)
			2		-> (n_-1,1, 0)
			3		-> (n_-1,1, 1)
	sum1 = qc+additionalScc1
	decompo = min (n'`quot`2) sum1
	additionalScc2 = 2*decompo
	sum2 = sum1-decompo+additionalScc2
    print sum2