x=input()
n=int(x)
m=len(x)
ans=0
for i in range(1,m+1):
    ans +=3**i-(3*2**i)+3
for i in range(n,8*10**(m-1)):
    j=str(i)
    k=set(j)
    if str(3) in j and str(5) in j and str(7) in j:
        if len(k)==3:
            ans -=1
print(ans)