import scala.io.StdIn

object Main {

  def main(args: Array[String]): Unit = {
    val n = StdIn.readLine().toInt
    println(solve(n))
  }

  def solve(n: Int): Int = {
    only(List("3", "5", "7"), n) -
    only(List("3", "5"), n) -
    only(List("3", "7"), n) -
    only(List("5", "7"), n) +
    only(List("7"), n) + only(List("5"), n) + only(List("3"), n)
  }

  def only(digitSet: List[String], n: Int): Int = {
    (1 to 9).foldLeft(Nil: List[String])((x, _) => digitSet ++: x.flatMap(
      s => digitSet.map(c => c + s))).foldLeft(0)((acc, y) =>
      if (y.toInt <= n) {
        acc + 1
      } else {
        acc
      })
  }

}
