import java.util.Scanner

import scala.collection.mutable.ArrayBuffer

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

  def taskA() = {
    val ans = sc.nextInt() match {
      case 7 | 5 | 3 => "YES"
      case _ => "NO"
    }
    println(ans)
  }

  def taskB() = {
    val s = sc.next()
    val n = s.length
    val ans = 0.until(n - 2).fold(10000) { (acc, x) =>
      val y = s.substring(x, x + 3).toInt
      Math.min(acc, Math.abs(y - 753))
    }
    println(ans)
  }

  def taskC() = {
    val s = sc.next()
    val n = s.toInt

    def rec(pos: Int, l: Int, ab: ArrayBuffer[Int]): Int = {
      if (pos == l) {
        val ok = Seq(7, 5, 3).forall(ab.contains(_)) && ab.mkString.toInt <= n
        if (ok) 1 else 0
      } else {
        Seq(7, 5, 3).map { i =>
          ab(pos) = i
          rec(pos + 1, l, ab)
        }.sum
      }
    }

    val l = s.length

    val ans = 3.to(l).map { i =>
      println(i)
      val ab = ArrayBuffer.fill(i)(0)
      rec(0, i, ab)
    }.sum
    println(ans)
  }


  taskC()
}
