from itertools import product

N = int(input())
num_list = ["3", "5", "7"]
count = 0

for i in range(2,10):
    for t in product(num_list, repeat=i):
        check = t.count("3")*t.count("5").t.count("7")
        if int("".join(t)): <= N and check:
            count += 1

print(count)