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

    var f7 = false, f5 = false, f3 = false;
    S.split('').forEach(function(value) { 
        switch (value - 0) {
        case 7: 
            f7 = true;
            break;
        case 5:
            f5 = true;
            break;
        case 3:
            f3 = true;
            break;
        default:
        }
    });
    var count = (f7 && f5 && f3) ? 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"));
