import Control.Monad (replicateM)

main :: IO ()
main = readLn >>= print . solve

solve :: Int -> Int
solve = length . all753Nums

all753Nums :: Int -> [Int]
all753Nums n = between 1 n [read s | i <- [3..l]
                                   , s <- replicateM i "357"
                                   , contains753 s]
  where l = length $ show n

between :: Ord a => a -> a -> [a] -> [a]
between a b = takeWhile (<=b) . dropWhile (<a)

contains753 :: String -> Bool
contains753 s = and [c `elem` s | c <- "753"]
