countFigureLength :: Int -> Int
countFigureLength n = (3 ^ n) - (3 * (2 ^ n)) + 3

candidates :: Int -> [String]
candidates 1 = ["3", "5", "7"]
candidates n = [h:s | h <- ['3', '5', '7'], s <- candidates (n - 1)]

isSFT :: String -> Bool
isSFT s = elem '7' s && elem '5' s && elem '3' s

main = do
  s <- getLine
  let len = length s
      cs = takeWhile (<= s) $ candidates len
      sft = filter isSFT cs
      answer = length sft + sum (map countFigureLength [3..len -1])
  print answer
