using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC114_C
{
    class Program
    {
        const int Digits = 9;

        static int Add3(int[] numbers753, ref int index, int digits, int number, int[] _357eachCount)
        {
            ++digits;
            if (digits >= Digits)
            {
                return number;
            }

            int[] _357eachCount_ = new int[3];
            _357eachCount_[0] = _357eachCount[0];
            _357eachCount_[1] = _357eachCount[1];
            _357eachCount_[2] = _357eachCount[2];

            number += (int)Math.Pow(10, digits) * 3;

            ++_357eachCount_[0];

            if (_357eachCount_[0] >= 1 && _357eachCount_[1] >= 1 && _357eachCount_[2] >= 1)
            {
                numbers753[index] = number;

                ++index;
            }

            return Add753(numbers753, ref index, digits, number, _357eachCount_);
        }
        static int Add5(int[] numbers753, ref int index, int digits, int number, int[] _357eachCount)
        {
            ++digits;
            if (digits >= Digits)
            {
                return number;
            }

            int[] _357eachCount_ = new int[3];
            _357eachCount_[0] = _357eachCount[0];
            _357eachCount_[1] = _357eachCount[1];
            _357eachCount_[2] = _357eachCount[2];

            number += (int)Math.Pow(10, digits) * 5;

            ++_357eachCount_[1];

            if (_357eachCount_[0] >= 1 && _357eachCount_[1] >= 1 && _357eachCount_[2] >= 1)
            {
                numbers753[index] = number;

                ++index;
            }

            return Add753(numbers753, ref index, digits, number, _357eachCount_);
        }
        static int Add7(int[] numbers753, ref int index, int digits, int number, int[] _357eachCount)
        {
            ++digits;
            if (digits >= Digits)
            {
                return number;
            }

            int[] _357eachCount_ = new int[3];
            _357eachCount_[0] = _357eachCount[0];
            _357eachCount_[1] = _357eachCount[1];
            _357eachCount_[2] = _357eachCount[2];

            number += (int)Math.Pow(10, digits) * 7;

            ++_357eachCount_[2];

            if (_357eachCount_[0] >= 1 && _357eachCount_[1] >= 1 && _357eachCount_[2] >= 1)
            {

                numbers753[index] = number;

                ++index;
            }

            return Add753(numbers753, ref index, digits, number, _357eachCount_);
        }


        static int Add753(int[] numbers753, ref int index, int digits, int number, int[] _357eachCount)
        {
            int number3 = number;
            int number5 = number;
            int number7 = number;

            number3 = Add3(numbers753, ref index, digits, number, _357eachCount);
            number5 = Add5(numbers753, ref index, digits, number, _357eachCount);
            number7 = Add7(numbers753, ref index, digits, number, _357eachCount);

            return number;
        }

        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            int numberCount = 0;
            int numberCount_ = 1;
            for (int j = 1; j <= Digits; ++j)
            {
                numberCount_ *= 3;
                numberCount += numberCount_;
            }

            int[] numbers753 = new int[numberCount];

            int index = 0;
            int digits = -1;
            int[] _357eachCount = new int[3];

            Add753(numbers753, ref index, digits, 0, _357eachCount);

            int i = 0;
            int number = 0;
            int count = 0;
            while((number = numbers753[i]) != 0)
            {
                if (n >= number)
                {
                    ++count;
                }

                ++i;
            }

            Console.WriteLine("{0}", count);
        }
    }
}


Measured memory_bytes: 13144