using System;
using System.Linq;
using System.Collections.Generic;

namespace Atcoder
{
    class Program2
    {
        public static void Main(string[] args)
        {
            long N = int.Parse(Console.ReadLine());
            List<long> list = new List<long>();
            bool aSign = false;
            bool bSign = false;
            bool cSign = false;
            bool dSign = false;
            bool eSign = false;
            bool fSign = false;

            for (int a = first(aSign); a < 8;a=Generatei(a)){
                for (int b = first(bSign); b < 8; b = Generatei(b))
                {
                    for (int c = first(cSign); c < 8; c = Generatei(c))
                    {
                        for (int d = first(dSign); d < 8; d = Generatei(d))
                        {
                            for (int e = first(eSign); e < 8; e = Generatei(e))
                            {
                                for (int f = first(fSign); f < 8; f = Generatei(f))
                                {
                                    for (int g = 3; g < 8; g = Generatei(g))
                                    {
                                        for (int h = 3; h < 8; h = Generatei(h))
                                        {
                                            for (int i = 3; i < 8; i = Generatei(i))
                                            {
                                                long judgedNumber = a * 100000000 + b * 10000000 + c * 1000000 + d * 100000 + e * 10000 + f * 1000 + g * 100 + h * 10 + i;
                                                if(Judge(judgedNumber)){
                                                    list.Add(judgedNumber);
                                                }
                                            }
                                        }
                                    }
                                    fSign = true;
                                }
                                eSign = true;
                            }
                            dSign = true;
                        }
                        cSign = true;
                    }
                    bSign = true;
                }
                aSign = true;
            }
            int count = 0;
            while(count < list.Count&&list[count]<=N){
                count++;
            }
            Console.WriteLine(count);
        }
        public static int first(bool sign){
            if(sign==true){
                return 3;
            }else{
                return 0;
            }
        }
        public static int Generatei(int i){
            if(i==0){
                return 3;
            }else if(i==3){
                return 5;
            }else if(i==5){
                return 7;
            }else if(i==7){
                return 8;
            }
            return 0;
        }
        public static bool Judge(long b){
            bool is3appear = false;
            bool is5appear = false;
            bool is7appear = false;
            for (int j = 0; j < b.ToString().Length; j++)
            {
                int a = int.Parse(b.ToString().Substring(j, 1));
                if (a == 3)
                {
                    is3appear = true;
                }
                else if (a == 5)
                {
                    is5appear = true;
                }
                else if (a == 7)
                {
                    is7appear = true;
                }
            }

            if (is3appear == true && is5appear == true && is7appear == true)
            {
                return true;
            }else{
                return false;
            }
        }
    }
}


Measured memory_bytes: 15572