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

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

int calc(int n) {

    bool isValid(long m) {
        const b357 = (1 << 3) | (1 << 5) | (1 << 7);
        int b = 0;
        while (m > 0) {
            b |= (1 << (m % 10));
            m /= 10;
        }
        return (b & b357) == b357;
    }

    auto stack = DList!long(0);
    int ans = 0;
    while (!stack.empty) {
        long x = stack.back;
        stack.removeBack();
        if (x > n) continue;

        if (isValid(x)) ans++;

        stack.insertBack(10 * x + 3);
        stack.insertBack(10 * x + 5);
        stack.insertBack(10 * x + 7);
    }
    return ans;
}

void main() {
    int n = readint;
    writeln(calc(n));
}
