from itertools import product

N = int(input())

_357 = {'3', '5', '7'}

ans = 0
continuous = True
for r in range(3, 10 + 1):
    if r > len(str(N)):
        break
    for numbers in product(('3', '5', '7'), repeat=r):
        if int(''.join(numbers)) >= N:
            continue
        if set(numbers) == _357:
            ans += 1

print(ans)
