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.f

f::Int->Int
f n = runST $ do
    dp <- newArray ( ((0,False),(False,False,False)), ((k,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,f,d, x,s3,s5,s7) | (i,d)<-zip [0..] s, [f,s3,s5,s7]<-replicateM 4 [False,True]
        , x <- dropWhile ((&& (s3||s5||s7)).(==0)) $ takeWhile ((||f).(<=d)) [0,3,5,7]] $
        \(i,f,d,x,s3,s5,s7) -> do
            let nf = f || x<d
            let n3 = s3 || x==3
            let n5 = s5 || x==5
            let n7 = s7 || x==7
            modifyArray dp ((i+1,nf),(n3,n5,n7)) =<< (+) <$> readArray dp ((i,f),(s3,s5,s7))
    (+) <$> readArray dp ((k,False),(True,True,True)) <*> readArray dp ((k,True),(True,True,True))
    where
        s = map digitToInt $ show n
        k = length s