object Main extends App {
  val NN = io.Source.stdin.getLines.toIndexedSeq.head.toInt
  private def func(i:Int):String={
    var t=i
    var str=""
    do{
      val rem = t%4
      val c = if(rem==1) "3" else if(rem==2) "5" else if(rem==3) "7" else "x"
      str = c + str
      t = t/4
    }while(t>0)
    str
  }
  private def check(s:String):Boolean={
    s.contains('3') && s.contains('5') && s.contains('7') //&& !s.contains('x')
  }  
  //println(NN)
  
  var ii=1
  var ret=0
  var n=0L
  do{
    val str = func(ii)
    if(!str.contains('x')){
      n = str.toLong
      if(n <= NN && check(str)){
        //println(str + "+")
        ret += 1
      } //else println(str)
    }
    ii += 1
  }while(n <= NN)

  println(ret)
}
