import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;


void main() {
    int n;
    scan(n);

    int[] a = [3, 5, 7];
    long[] nagosan;

    void dfs(int d, int i, long x, int set) {
        if (i == d) {
            if ((set & 1) == 0 || (set & 2) == 0 || (set & 4) == 0) {
                return;
            }
            nagosan ~= x;
            return;
        }
        dfs(d, i + 1, x*10 + 3, set | 1);
        dfs(d, i + 1, x*10 + 5, set | 2);
        dfs(d, i + 1, x*10 + 7, set | 4);
    }

    foreach (d ; 3 .. 10) {
        dfs(d, 0, 0, 0);
    }

    auto ns = nagosan.sort();

    debug {
        writeln(ns);
    }

    int ans = ns.lowerBound(n + 1).length.to!int;

    writeln(ans);
}


























void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}