import math
N=input()
M=int(N)
NList = [int(n) for n in list(N)]
keta = int(math.log10(M))+1
DP753 = [[0]*2 for i in range(len(N))]#DP[i][smaller]:smaller = 0でi+1桁目までぴったし一致
for k,n in enumerate(NList):
    if k==0:
        if n in (3,5,7):
            DP753[0][0] = 1
        DP753[0][1] = (n>3)+(n>5)+(n>7)
    else:
        equal,miman = DP753[k-1]
        if n in (3,5,7):
            DP753[k][0] = equal
        miman753 = (n>3)+(n>5)+(n>7)+1#0もある
        DP753[k][1] = equal*miman753+miman*4
Num753 = sum(DP753[len(N)-1])

DP75 = [[0]*2 for i in range(len(N))]#DP[i][smaller]:smaller = 0でi+1桁目までぴったし一致
for k,n in enumerate(NList):
    if k==0:
        if n in (5,7):
            DP75[0][0] = 1
        DP75[0][1] = (n>5)+(n>7)
    else:
        equal,miman = DP75[k-1]
        if n in (5,7):
            DP75[k][0] = equal
        miman753 = (n>5)+(n>7)+1
        DP75[k][1] = equal*miman753+miman*3
Num75 = sum(DP75[len(N)-1])

DP73 =  [[0]*2 for i in range(len(N))]#DP[i][smaller]:smaller = 0でi+1桁目までぴったし一致
for k,n in enumerate(NList):
    if k==0:
        if n in (3,7):
            DP73[0][0] = 1
        DP73[0][1] = (n>3)+(n>7)
    else:
        equal,miman = DP73[k-1]
        if n in (3,7):
            DP73[k][0] = equal
        miman753 = (n>3)+(n>7)+1
        DP73[k][1] = equal*miman753+miman*3
Num73 = sum(DP73[len(N)-1])

DP53 =  [[0]*2 for i in range(len(N))]#DP[i][smaller]:smaller = 0でi+1桁目までぴったし一致
for k,n in enumerate(NList):
    if k==0:
        if n in (3,5):
            DP53[0][0] = 1
        DP53[0][1] = (n>3)+(n>5)
    else:
        equal,miman = DP53[k-1]
        if n in (5,3):
            DP53[k][0] = equal
        miman753 = (n>3)+(n>5)+1
        DP53[k][1] = equal*miman753+miman*3
Num53 = sum(DP53[len(N)-1])

def Xonly(X,Y):
    """
    引数２個ともstr
    """
    if int(Y)>int(X*len(Y)):
        return(len(Y))
    else:return(len(Y)-1)

Num7,Num5,Num3 = Xonly("7",N),Xonly("5",N),Xonly("3",N)

Only7,Only5,Only3 = Num753-Num53,Num753-Num73,Num753-Num75

print(Num7+Num5+Num3+Only7+Only5+Only3-2*Num753)