main :: IO ()
main = interact $ eachLineWithoutEnd solve

eachLineWithoutEnd :: (String -> String) -> (String -> String)
eachLineWithoutEnd f = unlines . map f . init . lines

solve :: String -> String
solve s = show $ count m n
  where
    [m,n] = map read $ words s

count :: Int -> Int -> Int
count m n = length $ takeWhile (<=n) $ dropWhile (<m) hamming

hamming :: [Int]
hamming = 1 : merge fives (merge threes twos)
  where
    fives  = map (*5) hamming
    threes = map (*3) hamming
    twos   = map (*2) hamming

merge :: Ord a => [a] -> [a] -> [a]
merge xs [] = xs
merge [] ys = ys
merge a@(x:xs) b@(y:ys)
  | x < y     = x : merge xs b
  | x > y     = y : merge a ys
  | otherwise = x : merge xs ys

