from itertools import product

# 10 ** 9
l753 = []
for i in range(3, 10):
    l = ['753'] * i
    for s in product(*l):
        if '7' in s and '3' in s and '5' in s:
            l753.append(int("".join(s)))
sorted(l753)
N = int(input())
count = 0
for i in l753:
    if i > N:
        break
    count += 1
print(count)

