K=int(input())
N=str(K)


a=[]
S=int(len(str(K)))

T=0
for i in range(3,S-1):
    t=i**3
    t=t-3*(i**2)-3
    T=T+t

for j in range(0,S):
    if int(N[j])>7:
        T=T+(S-j)**3-S(S-j)**2-3
        break
    if int(N[j])>5 and int(N[j])<7:
        T=T+2*(S-1-j)**3-4*(S-1-j)**2-2
        break
    if int(N[j])>3 and int(N[j])<5:
        T=T+1*(S-1-j)**3-2*(S-1-j)**2-1
        break
    if int(N[j])==7:
        T=T+2*(S-1-j)**3-4*(S-1-j)**2-2
        continue
    if int(N[j])==5:
        T=T+1*(S-1-j)**3-2*(S-1-j)**2-1
        continue
    if int(N[j])==3:
        continue
    else:
        break

print(T)

