N = int(input())
i = 1
count = 0
if N <= 777777777:
    while i <= N:
        I = str(i)
        I = list(I)
        if I.count("3")>0 and I.count("5")>0 and I.count("7")>0:
            if I.count("0")+I.count("1")+I.count("2")+I.count("4")+I.count("6")+I.count("8")+I.count("9")==0:
                count+=1
                i+=2
            else:
                i+=2
        else:
            i+=2
    print(count)
else:
    print(26484)