# coding: utf-8
str_N=input()
list_N=list(map(int,str_N))
N=int(str_N)
k=len(list_N)
ans=0

def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)

for i in range(k**4+1):
    s_tri=Base_10_to_n(i,4)
    tri=list(map(int,list(s_tri)))
    
    
    num=s_tri.replace("3","7")
    num=num.replace("1","3")
    num=num.replace("2","5")
   
    
    num=int(num)
    
    if num>N:
        break
    
    flg0=True
    flg3=False
    flg5=False
    flg7=False
    for t in tri:
        if t==0:
            flg0=False
        if t==1:
            flg3=True
        if t==2:
            flg5=True
        if t==3:
            flg7=True
            
    if flg0 and flg3 and flg5 and flg7:

        ans+=1
        
print(ans)