var N;
function c753(s) {
    if ((s - 0) > N) return 0;

    var f = new Array(8).fill(false);
    for (var n = 0; n < s.length; n++) { f[s.charAt(n) - 0] = true; }
    var count = (f[7] && f[5] && f[3]) ? 1 : 0;
    for (var c of ['7', '5', '3']) { count += c753(s + c); }
    return count;
}

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

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