using System;
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using System.Linq;

namespace question3
{
    class Program
    {
        static void Main(string[] args)
        {
            var p = new Program();
            p.Run();
        }

        void Run()
        {
            var n = Console.ReadLine();
            var p3 = new Regex("3", RegexOptions.Compiled);
            var p5 = new Regex("5", RegexOptions.Compiled);
            var p7 = new Regex("7", RegexOptions.Compiled);
            var p753 = new Regex("^[357]*$", RegexOptions.Compiled);

            var count = 0;
            var combinations = GetCombinations(new int[] { 0, 3, 5, 7 }, n.Length);

            foreach (var c in combinations)
            {
                if (int.Parse(c) < int.Parse(n) && p3.IsMatch(c) && p5.IsMatch(c) && p7.IsMatch(c) && p753.IsMatch(c))
                {
                    count++;
                }
            }

            Console.WriteLine(count);
        }

        IEnumerable<string> GetCombinations(int[] values, int n)
        {
            var c = values.Length;
            for (int i = 1; i < Math.Pow(c, n); i++)
            {
                var result = "";
                var q = i;

                while (q > 0)
                {
                    result += values[q % c];
                    q = q / c;
                }

                yield return new String(result.Reverse().ToArray());
            }
        }
    }
}