object Main extends App{
  val N = io.StdIn.readLine().toInt
  var sft = 0
  for(x <- 1 to N){
    xs = x.toString.toList.map(_.asDigit)
    var three = 0
    var five = 0
    var seven = 0
    for(i <- 1 to xs.length){
      if(xs(i) == 3){
        three += 1
      }else if(xs(i) == 5){
        fice += 1
      }else if(xs(i) == 7){
        seven += 1
      }
    }
    if(three == 1 && five == 1 && seven == 1){
      sftnum += 1
    }
  }
  println(sftnum)
}