main = do
    n <- read <$> getLine :: IO Int
    print $ length (filter ((<n) . read) (num753Numbers 9 ""))

num753Numbers :: Int -> String -> [String]
num753Numbers maxDigit xs
    | length xs > maxDigit = []
    | otherwise = let list7 = num753Numbers maxDigit ('7':xs)
                      list5 = num753Numbers maxDigit ('5':xs)
                      list3 = num753Numbers maxDigit ('3':xs)
                      includes753 = '7' `elem` xs && '5' `elem` xs && '3' `elem` xs
                      includesOnly753 = and (map (`elem` "753") xs)
                      list = if includes753 && includesOnly753 then [xs] else []
                  in concat [list7, list5, list3, list]
