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