import Data.Char
import Control.Monad
import Control.Monad.ST
import Data.Array.ST

modifyArray :: (Ix i) => STUArray s i Int -> i -> (Int->Int) -> ST s ()
modifyArray a i f = writeArray a i =<< f <$> readArray a i

main = readLn >>= print.sol

keta = 9

sol :: Int -> Int
sol n = runST $ do
    dp <- newArray (((0,False),(False,False,False)),((keta,True),(True,True,True))) 0 :: ST s (STUArray s ((Int,Bool),(Bool,Bool,Bool)) Int)
    writeArray dp ((0,False),(False,False,False)) 1
    --
    forM_ [(i,b,d,x,e3,e5,e7)|(i,d)<-zip [0..] nd, b<-[False,True], x<-[0,3,5,7], [e3,e5,e7]<-replicateM 3 [False,True], b || x<=d, not (e3||e5||e7) || x/=0] $ \(i,b,d,x,e3,e5,e7) -> do
        let nb = b || x<d
        let n3 = e3 || x==3
        let n5 = e5 || x==5
        let n7 = e7 || x==7
        modifyArray dp ((i+1,nb),(n3,n5,n7)) =<< (+) <$> readArray dp ((i,b),(e3,e5,e7))
    (+) <$> readArray dp ((keta,False),(True,True,True)) <*> readArray dp ((keta,True),(True,True,True))
    where
        ns = show n
        nd = map digitToInt $ replicate (keta - length ns) '0' ++ ns