import Control.Monad

main = readLn >>= print . solve

solve :: Int -> Int
solve n = length . filter (<= n) $ map read xs

xs = filter check $ replicateM 9 " 753"
check x = '7' `elem` x &&
          '5' `elem` x &&
          '3' `elem` x &&
          ' ' `notElem` (dropWhile (== ' ') x)