using System;
using System.Collections.Generic;
using static System.Console;

class Program {
    static int n, ans;

    static void Main() {
        n = NextInt();
        for (var i = 0; ; i++) {
            DFS(i, "0");
        }
    }

    static void DFS(int rest, string s) {
        if (rest == 0) {
            if (long.Parse(s) > n) {
                WriteLine(ans);
                Environment.Exit(0);
            }
            foreach (var v in "357") {
                if (!s.Contains(v)) {
                    return;
                }
            }
            ans++;
        } else {
            foreach (var c in "357") {
                DFS(rest - 1, s + c);
            }
        }
    }

    static int NextInt() {
        return int.Parse(NextString());
    }

    static string NextString() {
        var result = new List<char>();
        while (true) {
            int next = Read();
            if (next < 0)
                break;
            var nextChar = (char)next;
            if (!char.IsWhiteSpace(nextChar))
                result.Add(nextChar);
            else if (nextChar != '\r')
                break;
        }
        return string.Join("", result);
    }
}