using System;

namespace ABC114_C
{
    class Program
    {
        static void Main(string[] args)
        {
            var num = int.Parse(Console.ReadLine());
            var count = 0;
            for (var i = 357; i <= num; i++)
            {
                var t = Convert.ToString(i);
                var flag = true;
                if (!(t.Contains("3") && t.Contains("5") && t.Contains("7")))
                {
                    flag = false;
                    continue;
                }
                foreach (var ch in t)
                {
                    if (ch != '3' && ch != '5' && ch != '7')
                    {
                        flag = false;
                        break;
                    }
                }
                if (flag == true)
                    count++;
            }
            Console.WriteLine(count);
        }
    }
}