fun main(args: Array<String>) {
    val N = readLine()!!.toLong()

    println(rec(0L, N, 0))
}

fun rec(v: Long, n: Long, b: Int): Long {
    if (v > n) {
        return 0L
    }

    return rec(v * 10 + 7, n, b or 4) +
            rec(v * 10 + 5, n, b or 2) +
            rec(v * 10 + 3, n, b or 1) +
            (if (b == 7) 1 else 0)
}
