using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
#if DEBUG
            ReadLine();
#endif
        }

        public void Solve(ConsoleInput cin)
        {
            int n = cin.ReadInt;

            Dictionary<int, HashSet<string>> resultDict = new Dictionary<int, HashSet<string>>();

            {
                // 3桁
                HashSet<string> result = new HashSet<string>();
                if (357 <= n)
                    result.Add("357");
                if (375 <= n)
                    result.Add("375");
                if (537 <= n)
                    result.Add("537");
                if (573 <= n)
                    result.Add("573");
                if (735 <= n)
                    result.Add("735");
                if (753 <= n)
                    result.Add("753");
                resultDict.Add(3, result);
            }


            int digit = n.ToString().Length;
            for (int i = 4; i <= digit; i++)
            {
                // i桁
                bool end = false;
                HashSet<string> result = new HashSet<string>();
                foreach (String seed in resultDict[i - 1])
                {
                    calc(n, seed, "3", result);
                    calc(n, seed, "5", result);
                    calc(n, seed, "7", result);
                }

                resultDict.Add(i, result);
                if (end)
                {
                    break;
                }
            }

            int sum = 0;
            foreach (KeyValuePair<int, HashSet<string>> keyValue in resultDict)
            {
                sum += keyValue.Value.Count();
            }

            Console.WriteLine(sum);
        }

        private HashSet<string> calc(int n, String seed, String insert, HashSet<string> result)
        {
            for (int i = 0; i <= seed.Length; i++)
            {
                String s = seed.Insert(i, insert);
                int now = int.Parse(s);
                if(now <= n)
                {
                    result.Add(s);
                }
            }

            return result;
        }
    }

    class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;

        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }

        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }

        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}


Measured memory_bytes: 23256