
import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)

  val n = sc.nextLong()

  val cnt = Stream.from(0)
    .map(i => Integer.toString(i, 4))
    .map(s => "%d".format(s.toLong))
    .filter(s => s.contains('1') && s.contains('2') && s.contains('3') && !s.contains("0"))
    .map(s => s.replaceAll("1", "3")
      .replaceAll("2", "5")
      .replaceAll("3", "7"))
    .map(s => s.toLong)
    .takeWhile(n >= _)

  println(cnt.size)
}
