import itertools
n = input()
dp = [[[[[0] * 2 for i in range(2)] for j in range(2)] for k in range(2)]for l in range(len(n))]
#dp[i桁目][nより小さいかどうか][3がある][5がある][7がある]

for i in range(len(n)):
    dp[i][0][0][0][0] = 1

for j in range(10):
    if int(n[0]) >= j:
        dp[0][int(n[0]) == j][j == 3][j == 5][j == 7] = 1

for i, j, k, l, m in itertools.product(range(len(n)-1), range(2), range(2), range(2), range(10)):
    if m in [3, 5, 7]:
        dp[i + 1][0][j or m == 3][k or m == 5][l or m == 7] += dp[i][0][j][k][l]
        if m <= int(n[i+1]):
            dp[i + 1][m == int(n[i+1])][j or m == 3][k or m == 5][l or m == 7] += dp[i][1][j][k][l]

print(dp[-1][0][1][1][1] + dp[-1][1][1][1][1])
