import scala.collection.mutable._

object Main extends App {
    val ns = ArrayBuffer(
      Array(7,5,3): _*
    )
  
    val n = io.StdIn.readLine.toInt
    
    1.to(9-1).foreach { i => 
      val newNs = ArrayBuffer[Int]()
      List(7,5,3).foreach { suffix =>
        ns.foreach { n =>
		  val m = n * 10 + suffix
          newNs += m
        }
      }
      ns ++= newNs
	}
    
    println(ns.sortBy(identity).distinct.count {
      x => 
        val xs = x.toString
        x <= n &&
        xs.contains("7") && 
        xs.contains("5") && 
        xs.contains("3")
    })
}