import Data.List
import qualified Data.IntSet as S

main=do
    [x,y]<-map read.words<$>getLine
    print $ sol 0 S.empty (S.singleton x) y
sol::Int->S.IntSet->S.IntSet->Int->Int
sol c m q y
    | S.member y q = c
    | otherwise = sol (c+1) (S.union m $ S.fromList nl) (S.fromList nl) y
    where
        nl = filter (`S.notMember` m) $ concatMap (\x->[-x, x+1]) $ S.toList q