
type StrL = (String,Int)
cmp (s1,l1) (s2,l2)
  | l1<l2 = LT
  | l1>l2 = GT
  | otherwise = compare s1 s2

is753 = (==(True,True,True)) . foldl f (False,False,False) where
  f (b7,b5,b3) '7' = (True,b5,b3)
  f (b7,b5,b3) '5' = (b7,True,b3)
  f (b7,b5,b3) '3' = (b7,b5,True)

b2i True = 1
b2i False = 0

solv n = go n ("",0) where
  go n a@(sa,la)
    | a `cmp` n == GT = 0
    | otherwise = 
        b2i (is753 sa) + go n ('7':sa,la+1)+ go n ('5':sa,la+1)+ go n ('3':sa,la+1)

main = do
  n <- getLine
  print $ solv (n, length n)
