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

class Cmondai
{
    static void Main()
    {
        var N = Int64.Parse(Console.ReadLine());
        var nKeta = Math.Log10(N)+1;
        var max = (int)Math.Pow(3,9);
        var list = new List<string>();
        var ans = 0;
        for (int i=0;i<nKeta;++i)
        {
            for (int j=0;j<max;++j) {

                var num = j;
                var keta = 0;
                var amari = 0;
                var suji = "";

                while (keta<i+1) {
                    amari = num % 3;
                    switch (amari)
                    {
                        case 0: suji += "3"; break;
                        case 1: suji += "5"; break;
                        case 2: suji += "7"; break;
                    }
                    num /= 3;
                    keta++;
                }
                if (list.Contains(suji)) break;
                list.Add(suji);
                if (Int64.Parse(suji) < N && suji.Contains("3") && suji.Contains("5") && suji.Contains("7")) ans++;
            }
        }
        Console.WriteLine(ans);
    }
}