N = int(input())


ans = 0
for i in range(N):
    char = str(i)
    n = char.count("7")
    m = char.count("5")
    l = char.count("3")

    if (n > 0) and (m > 0) and (l > 0) and (n + m + l == len(char)):
        ans += 1

print(ans)