fun main(args: Array<String>) {
    val n = readLine()!!.toLong()
    val x = mutableListOf(0, 1, 2)
    var count = 0

    while (n >= toValue(x)) {
        if (x.contains(0) && x.contains(1) && x.contains(2)) {
            count += 1
        }
        countUp(x, x.size - 1)
    }

    println(count)
}

fun countUp(list: MutableList<Int>, digit: Int) {
    list[digit] += 1
    if (list[digit] >= 3) {
        list[digit] = 0
        if (digit > 0) {
            countUp(list, digit - 1)
        } else {
            list.add(0)
        }
    }
}

fun toValue(list: List<Int>): Long {
    var result = 0L
    list.forEach {
        result *= 10
        result += when (it) {
            0 -> 3
            1 -> 5
            else -> 7
        }
    }
    return result
}


