import std.algorithm;
import std.bigint;
import std.bitmanip;
import std.concurrency : generator = Generator, yield;
import std.container;
import std.conv;
import std.functional;
import std.format;
import std.math;
import std.meta;
import std.numeric;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.traits;
import std.typecons;


auto solve(long N) {
    generator!string f(size_t d) {
        return new generator!(string)({
            if (d <= 0)
                yield("");
            else foreach (s; f(d - 1)) {
                yield("3" ~ s);
                yield("5" ~ s);
                yield("7" ~ s);
            }
        });
    }

    return iota(N.to!string.length)
        .map!(i => f(i + 1))
        .joiner
        .filter!(s => s.canFind('3'))
        .filter!(s => s.canFind('5'))
        .filter!(s => s.canFind('7'))
        .filter!(s => s.to!long <= N)
        .count;
}


void main() {
    auto input = stdin.byLine.map!split.joiner;

    long N;
    N = input.front.to!long;
    input.popFront;

    static if (is(ReturnType!solve == void))
        solve(N);
    else {
        auto ans = solve(N);

        static if (isFloatingPoint!(ReturnType!solve))
            writeln(format("%.9f", ans));
        else static if (is(ReturnType!solve == bool))
            writeln(ans ? YES : NO);
        else
            writeln(ans);
    }
}
