import std.stdio, std.math, std.algorithm, std.array, std.string, std.conv, std.container, std.range;
T Read(T)() { return readln.chomp.to!(T); }
T[] Reads(T)() { return readln.split.to!(T[]); }
alias read = Read!(int);
alias reads = Reads!(int);


bool valid(long x) {
    string s = x.to!string;
    return "357".all!(c => s.count(c) > 0)
        && "0124689".all!(c => s.count(c) == 0);
}

int n;
long[] nums;
void dfs(long x) {
    if (x > n) return ;
    if (valid(x))
        nums ~= x;
    dfs(10 * x + 3);
    dfs(10 * x + 5);
    dfs(10 * x + 7);
}

int solve(int x) {
    dfs(0);
    return nums.length.to!int;
}

void main() {
    read.solve.writeln;
}
