var N;
function c753(S) {
    var s = S - 0;
    if (s > N) return 0;
    var a753 = new Array(3).fill(0);
    var f = S.length >= 3 && S.split('').every(function(value) { 
        switch (value - 0) {
            case 7: 
                ++ a753[0];
                return true;
            case 5:
                ++ a753[1];
                return true;
            case 3:
                ++ a753[2];
                return true;
            default:
            return false;
            }
    });
    var result = (f && a753.every(function(value) { return value > 0; })) ? 1 : 0;
    for (var c of ['7', '5', '3']) result += c753(S + c);
    return result;
}

function Main(input) {
    N = input.split("\n")[0] - 0;
    var count = c753("");
    console.log(count);
}

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