import std;

ulong MAX = 100_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "money", long, "stack");
alias PQueue(T, alias less = "a>b") = BinaryHeap!(Array!T, less);

void main()
{
    auto N = sread();
    auto digit = N.length;
    auto p = new string[](0);

    void dfs(string s)
    {
        if (!s.empty())
            p ~= s;

        if (s.length == digit)
        {
            return;
        }

        dfs(s ~ '3');
        dfs(s ~ '5');
        dfs(s ~ '7');
    }

    dfs([]);
    p.sort!"a.to!(long)<b.to!(long)"();
    // p.writeln;
    long cnt;
    foreach (i; iota(p.length))
    {
        if (p[i].to!(long) > N.to!(long))
            break;

        bool has753()
        {
            bool seven, five, three;
            foreach (e; p[i])
            {
                switch (e)
                {
                case '7':
                    seven = true;
                    break;
                case '5':
                    five = true;
                    break;
                case '3':
                    three = true;
                    break;
                default:
                    break;
                }
            }
            return seven && five && three;
        }

        cnt += has753();
    }
    cnt.writeln();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}
