import Data.List
import Data.Char
import Control.Monad
import Data.Ord


is753 n
  | n < 357 = False
  | otherwise = n' == [3,5,7] where
    n' = sort $ map digitToInt $ nub $ show n

main = do
  n <- readLn
  let xs = [x|x<-[1..n],is753 x]
  putStrLn $ show $ length xs