import scala.io.StdIn._

object Main  {
  def main(args: Array[String]): Unit = {
    val n: Int = readLine.toInt
    println(solve(n,0,(false,false,false)))
  }
  def solve(n: Int, x: Int,check:(Boolean, Boolean,Boolean)): Int = {
    val (a,b,c): (Boolean ,Boolean, Boolean) = check
    if(x > n) return 0
    val tmp = if(a && b && c && x <= n) 1 else 0
    val sum1 = solve(n, 10*x + 3, (true,b,c))
    val sum2 = solve(n, 10*x + 5, (a,true,c))
    val sum3 = solve(n, 10*x + 7, (a,b,true))
    sum1+sum2+sum3+tmp
  }
}
