N = input()
L = len(N)
dp = [[[[[0]*2 for _ in range(2)] for _ in range(2)] for _ in range(2)] for _ in range(L+1)]
dp[0][0][0][0][0] = 1
# dp[i][j][k][l][m]: iは桁数、j,k,lは3, 5, 7が一回以上でたかどうか、mは未満フラグ(未満ならば1)


for i in range(L):
    n = int(N[i])
    for j in range(2): #3
        for k in range(2): #5
            for l in range(2): #7
                for smaller in range(2):
                    for a in [0, 3, 5, 7]:
                        nj, nk, nl, ns = j, k, l, 1
                        if i > 0 and a == 0:
                            continue
                        if smaller==0 and n < a:
                            continue
                        if smaller==0 and n == a:
                            ns = 0
                        elif smaller == 0 and n > a:
                            ns = 1
                        
                        if a == 3:
                            nj = 1
                        elif a == 5:
                            nk = 1
                        elif a == 7:
                            nl = 1
                        else:
                            pass

                        dp[i+1][nj][nk][nl][ns] += dp[i][j][k][l][smaller]

print(sum(dp[L][1][1][1]))

