'use strict'

function Main(input) {
    // 7,5,3の組み合わせを基底数3の序数と見なしつつ解きます
    const N = parseInt(input.trim())
    const faces = [7, 5, 3]
    const base = faces.length

    let count = 0
    // n桁、i番目の組み合わせを求めます
    for (let len = base; len <= N.toString().length; len++) {
        for (let i = 0; i < Math.pow(base, len); i++) {
            // 組み合わせの作成
            const combo = convertToBaseX(i, base, len).map(x => faces[x])
            // 検証＆カウント
            const condA = parseInt(combo.join('')) <= N
            const condB = faces.every((x) => combo.indexOf(x) !== -1)
            if (condA && condB)
                count += 1

            //console.log([convertToBaseX(i, base, len).join(''), combo.join(''), [condA, condB].join()])
        }
    }
    const output = count
    console.log(output)
}

function convertToBaseX(num, base, minLength) {
    const digits = minLength == null ? [] : new Array(minLength).fill(0)
    let temp = num
    for (let i = 0; temp !== 0; i++) {
        digits[i] = temp % base
        temp = Math.floor(temp / base)
    }
    return digits
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));