import itertools
n = int(input())
l = ["7","5","3"]
c = 0
for i in range(3,10):
    for j in itertools.product(l, repeat=i):
        if len(set(j)) == 3 and int("".join(j)) <=n:
            c += 1
print(c)