import Control.Monad

main = do
    n <- readLn :: IO Integer
    let seq753 = [1..] >>= (\r -> replicateM r [3, 5, 7])
    let fil753 = filter (\s -> all (\i -> elem i s) [3, 5, 7]) seq753
    let num753 = map (foldl (\a b -> 10 * a + b) 0) fil753
    print $ length $ takeWhile (<= n) num753