import qualified Data.Vector.Unboxed as U
import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as C
import Debug.Trace
import Data.List
import Data.Ord
import Control.Monad


r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine

main :: IO ()
main = do
    n <- readLn
    print $ length $ filter (<=n) $ kouho (length $ show n)

kouho :: Int -> [Int]
kouho d
    | d < 3 = []
    | otherwise = kouho (d-1) ++ (map toNumber $ filter ((==[3,5,7]).sort.nub) $ forM [1..d] (\_ -> [3,5,7]))

toNumber :: [Int] -> Int
toNumber = read.concat.map show
