{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}

main :: IO ()
main = do
  n <- readLn
  print $ solve n

solve :: Int -> Int
solve n = length $ takeWhile (<= n) n753s

n753s :: [Int]
n753s = filter is753 n753s'

is753 :: Int -> Bool
is753 x = find 3 x && find 5 x && find 7 x

find :: Int -> Int -> Bool
find n x
  | a == n = True
  | b == 0 = False
  | otherwise = find n b
  where
    a = x `mod` 10
    b = x `div` 10

n753s' :: [Int]
n753s' = go [3, 5, 7]
  where
    go xs = xs ++ go ys
      where
        ys = do
          x <- xs
          [append x 3, append x 5, append x 7]

append :: Int -> Int -> Int
append x y = x * 10 + y
