import scala.io.{StdIn => in}

object Main extends App {
  val S = in.readLine
  val N = S.toInt

  def dfsEnum(d:Int, n:Int):Int = {
    // d進 n個列挙
    val list = Array(7,5,3)
    val enum = Array.ofDim[Int](n)
    var ret = 0
  
    def evalute():Unit = {
      if(enum.distinct.size == 3 && enum.mkString.toInt <= N)
        ret += 1
    }
  
    def dfs(cnt:Int):Unit = {
      if(cnt == n) evalute
      else {
        for(i <- 0 until d) {
          enum(cnt) = list(i)
          dfs(cnt+1)
        }
      }
    }
  
    dfs(0)
    ret
  }

  val ans = if(N < 357) 0 else (1 to S.size).map(i => dfsEnum(3,i)).sum
  println(ans)
}