import Data.Set

main = do
  x <- read <$> getLine
  putStrLn . show . solve' $ x



solve' :: Integer -> Int
solve' x = length . (Prelude.filter check) $ [1..x]

check :: Integer -> Bool
check n =
  let s = fromList . show $ n
  in (length s) == 3 && member '3' s && member '5' s && member '7' s

solve :: Integer -> Int
solve = undefined

findNumOfDigit :: Int -> (Int, Int, Int)
findNumOfDigit x
  | x == 3 = (6,6,1)
  | otherwise =
      let (p3, p2, p1) = findNumOfDigit (x-1)
      in (3 * (p3 + p2), p2 + 2 * p1, 3 * p1)
