{-# LANGUAGE BangPatterns, FlexibleContexts #-}

import Control.Applicative
import Control.Monad
import Control.Monad.ST
import Data.Array
import Data.Array.ST
import Data.List
import Debug.Trace (traceShow, traceShowM)
import qualified Data.ByteString.Char8 as B

readi b | Just (n, _) <- B.readInt b = n

f1 :: Int -> [Int]
f1 n = do
    xs <- sequence (replicate n "357")
    guard (check xs)
    return $ read xs

check :: String -> Bool
check xs
    | null ("753" \\ xs) = True
    | otherwise          = False

main :: IO ()
main = do
    n <- readLn :: IO Int
    let xs = concatMap f1 [3 .. 9]
    print $ length $ takeWhile (<= n) xs
    return ()