main = do
  xs <- getLine
  let x = read xs :: Int
  print $ gosu x
  
gosu :: Int -> Int
gosu x = length [y | y <- [1..x], nanago y]

nanago :: Int -> Bool
nanago x = elem '3' sx && elem '5' sx && elem '7' sx && not (elem '1' sx) && not (elem '2' sx) && not (elem '4' sx) && not (elem '6' sx) && not (elem '8' sx) && not (elem '9' sx) && not (elem '0' sx)
  where sx = show x