import Control.Applicative
import Control.Monad
import Data.List

nums :: Int -> Int
nums n = length $ filter judge $ concat $ take (length $ show n) $ iterate ([('7':), ('5':), ('3':)] <*>) ["7", "5", "3"]
  where
    judge s = elem '7' s && elem '5' s && elem '3' s && read s <= n

main = readLn >>= print . nums