import Data.List
import Data.Char
import Control.Monad
import Data.Ord
  
gen n = [read x|i<-[3..n],x<-sequence $ replicate i "753",null $ "753" \\ x]

main = do
  n <- readLn::IO Int
  let aa = takeWhile (<= n) $ gen $ length $ show n
  putStrLn $ show $ length aa