import Control.Monad
import Data.Char

main = do 
    n <- readLn :: IO Int
    let ln = length $ show n
    let cand = join $ [ replicateM i [7, 5, 3] | i <- [3..ln]]
    print $ length $ filter (\x -> (joinInt x < n) && isSat x) cand

isSat :: [Int] -> Bool
isSat a = (7 `elem` a) && (5 `elem` a) && (3 `elem` a)

joinInt :: [Int] -> Int
joinInt l = read $ map intToDigit l