import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons;

void main() {
    auto N = readln.chomp.to!int;
    string[] list = ["7","5","3"];
    foreach (i; 0..8) {
        list ~= list.map!(x => ["7","5","3"].map!(y => x ~ y).array).join;
    }
    list
        .filter!(s => s.canFind("7") && s.canFind("5") && s.canFind("3"))
        .map!(to!int)
        .array
        .sort!"a<b"
        .uniq
        .filter!(x => x <= N)
        .count
        .writeln;
}

