
function Main(arg) {
 
    var N = arg.split("\n")[0]-0;
    var L = arg.split("\n")[1].split(" ").map(v=>v-0);
 
    var ans = 0;

    if (N < 357) {
        console.log(0);
    }

    for (var i = 357; i <= N; i++){
        var tmp = i.toString().split("");
        var a = new Set(tmp);
        if (a.size !== 3) continue;

        if (a.has("3") && a.has("5") && a.has("7")) {
            ans++;
        }

    }

    console.log(ans)

    return;
}

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