f :: Int->[Char]->Int
f m s | s /= "" && m < read(s) = 0
f m s = ret + sum(map (f m) as) where 
    ret = if and $ map (\a->elem a s) "357" then 1 else 0
    as = map (:s) "357"
main :: IO ()
main = do
    n <- getLine
    putStrLn $ show (f (read n) "")

