fun _gen753List(digit: Int): List<String> {
    if (digit <= 1) return listOf("3", "5", "7")

    return _gen753List(digit-1).flatMap { p -> listOf("3", "5", "7").map { p + it } }
}

fun gen753List(digit: Int): List<String> {
    return (1..digit).flatMap {_gen753List(it)}
}

fun main(args: Array<String>) {
    val S = readLine()!!
    val n = S.toInt()
    val list = gen753List(S.length).map { it.toInt() }.sorted()

    println(list.takeWhile { it <= n }.count { i -> val s = i.toString(); ("3" in s && "5" in s && "7" in s) })
}