i=input("")
i=int(i)
q=0
k=0
j=[]
for k in range(0,i+1) :
    j.clear()
    while k>0 :
        j.append(k%10)
        k //= 10

    
    if 1  not in j and 2  not in j and 4  not in j  and 6  not in j and 8  not in j and 9  not in j not in j:
        if 3 in j:
            if 7 in j :
                if 5 in j :
                    q=q+1


print(q)
