function Main(input) {
    var N = input.split("\n")[0] - 0;
    var count = 0;
    for (var n = 1; n <= N; n++) {
        var c753 = new Array(3).fill(0); //7 5 3
        var s = n.toString();
        var exit = false;
        for (var m = 0; !exit && m < s.length; m++) {
            switch (s.charAt(m)) {
            case "7": 
                ++ c753[0];
                break;
            case "5":
                ++ c753[1];
                break;
            case "3":
                ++ c753[2];
                break;
            default:
                exit = true;
            }
        }
        if (!exit && c753.every(function(value) { return value > 0; })) {
            ++count;
        }
    }

    console.log(count);
}

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