import java.util.*
import kotlin.system.exitProcess

var n = 0L
var ans = 0

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    n = sc.nextLong()
    for (i in 1..Int.MAX_VALUE) {
        dfs(i, "")
    }

}

fun dfs(rest: Int, s: String) {
    if (rest == 0) {
        if (s.toLong()> n) {
            println(ans)
            exitProcess(0)
        }
        for (v in "357") {
            if (v !in s) {
                return
            }
        }
        ans++
    } else {
        for (c in "357") {
            dfs(rest - 1, s + c)
        }
    }
}
