"use strict";
function main(input) {
  const inputs = input.split("\n").filter(x => x !== "");
  const N = inputs[0];

  function make(level) {
    if (level === 1) {
      return ["3", "5", "7"];
    }

    let preLevel = make(level - 1);
    return [].concat(
      preLevel.map(num => `3${num}`),
      preLevel.map(num => `5${num}`),
      preLevel.map(num => `7${num}`)
    );
  }

  let wholeArray = [];
  for (let i = 1; i <= 9; i++) {
    wholeArray = wholeArray.concat(make(i));
  }

  wholeArray = wholeArray
    .filter(
      item => item.includes("3") && item.includes("5") && item.includes("7")
    )
    .map(item => Number(item))
    .sort((a, b) => a - b);

  wholeArray.push(Number.MAX_VALUE);
  console.log(wholeArray.findIndex(element => element > N));
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));
