object Main {
  val ns = mutable.List[Int](7,5,3)
  
  def main {
    val n = io.Stdin.readLine.toInt
    
    1.to.9.foreach { i => 
      List(7,5,3).foreach { suffix =>
        ns.foreach { n => 
          ns += n * 10 + suffix
        }
      }
    }
    
    println(ns.filter(ni => ni <= n).count)å
  }
 
}