n=input()
ans=0
n_len=len(n)
a=[0]
for i in range(1,n_len):
    a_i=3*(a[i-1]+2**(i)-2)
    a.append(a_i)
buf=1
check=[0]*3
for i in range(n_len-3):
    a_sum=sum(a[:n_len-i-1])
    n_i=int(n[i])
    if n_i<=2:
        ans=a_sum
        buf=0
        break
    elif n_i==3:
        ans+=a_sum
        if check[0]==0:
            check[0]=1
    elif n_i==4:
        ans+=a_sum+a[n_len-i-1]//3
        buf=0
        break
    elif n_i==5:
        ans+=a_sum+a[n_len-i-1]//3
        if check[1]==0:
            check[1]=1
    elif n_i==6:
        ans+=a_sum+2*(a[n_len-i-1]//3)
        buf=0
        break
    elif n_i==7:
        ans+=a_sum+2*(a[n_len-i-1]//3)
        if check[2]==0:
            check[2]=1
    elif n_i>7:
        ans+=a_sum+a[n_len-i-1]
        buf=0
        break
if buf==0:
    print(ans)
else:
    n_3=int(n[-3:])
    check0=[0]*3
    for i in range(333,n_3+1):
        for j in range(3):
            check0[j]=check[j]
        i_s=str(i)
        buf=0
        for j in range(3):
            if i_s[j]=="3":
                check0[0]=1
                buf+=1
            elif i_s[j]=="5":
                check0[1]=1
                buf+=1
            elif i_s[j]=="7":
                check0[2]=1
                buf+=1
        if check0==[1,1,1] and buf==3:
            ans+=1
    print(ans)