import Data.List
import Control.Monad
import Data.Char (digitToInt)

main :: IO ()
main = print =<< solve <$> readLn

solve :: Int -> Int
solve n = countN + countLessN
  where
    d = length . show $ n
    countN = length . filter (<=n) . map digitsToInt . generateDigits $ d
    countLessN = sum . map (length.generateDigits) $ [0..(d-1)]

generateDigits :: Int -> [[Int]]
generateDigits = filter isValid . go
  where
    go :: Int -> [[Int]]
    go 0 = [[]]
    go d = [x:xs | x <- [3,5,7], xs <- go (d-1)]

isValid :: [Int] -> Bool
isValid xs = and . map (flip elem xs) $ [3,5,7]

digitsToInt :: [Int] -> Int
digitsToInt = foldl1 (\acc x -> acc*10 + x)