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

        internal class Solution
        {
			int N;
          	int counter=0;
          	List<int> items = new List<int>();
            public void Run()
            {
                N = Input.ReadInt();
                if(3<N){items.Add(3);plus(3);}
              	if(5<N){items.Add(5);plus(5);}
              	if(7<N){items.Add(7);plus(7);}
              	foreach(int item in items){
                String temp=""+item;
                if(!temp.Contains("7")) continue;
       			if(!temp.Contains("5")) continue;
        		if(!temp.Contains("3")) continue;
        		counter++;
                }
                Console.WriteLine(counter);
            }
          	public void plus(int num){
              int nextnum=num*10+3;
              if(nextnum<N){items.Add(nextnum);plus(nextnum);}
              nextnum=num*10+5;
              if(nextnum<N){items.Add(nextnum);plus(nextnum);}
              nextnum=num*10+7;
              if(nextnum<N){items.Add(nextnum);plus(nextnum);}
            }
        }

        // libs ----------


        // common ----------

        internal static class Input
        {
            public static string ReadString()
            {
                string line = Console.ReadLine();
                return line;
            }

            public static int ReadInt()
            {
                string line = Console.ReadLine();
                return int.Parse(line);
            }

            public static int[] ReadIntArray()
            {
                string line = Console.ReadLine();
                return line.Split(' ').Select(int.Parse).ToArray();
            }

            public static long ReadLong()
            {
                string line = Console.ReadLine();
                return long.Parse(line);
            }

            public static long[] ReadLongArray()
            {
                string line = Console.ReadLine();
                return line.Split(' ').Select(long.Parse).ToArray();
            }

            public static double[] ReadDoubleArray()
            {
                string line = Console.ReadLine();
                return line.Split(' ').Select(double.Parse).ToArray();
            }
        }

        internal class Program
        {
            public static void Main(string[] args)
            {
                var s = new Solution();
                s.Run();
            }
        }