import Data.List
import Data.Char
-- import Debug.Trace

l = [3,5,7]

scan :: Int -> Int
scan n = iter (log10 n) where
    iter 2 = 0
    iter s = length ts + iter (s-1) where
        ts = filter (\e -> constraint e) (comb l s)
        constraint e = (all (\x -> elem x e) l) && (toN e < n)

toN :: [Int] -> Int
toN = iter 0 where
    iter ac [] = ac
    iter ac (x:xs) = iter (ac*10 + x) xs        

log10 :: Int -> Int
log10 n = iter 0 1 where
    iter e x
        | x >= n = e
        | otherwise = iter (e+1) (x*10)

comb :: [a] -> Int -> [[a]]
comb xs 0 = [[]]
comb xs n = [x:y| x <- xs, y <- (comb xs (n-1))]   

main :: IO() 
main = do
    s <- readLn :: IO Int
    let ans = scan s
    print ans