import itertools

n = int(input())

count = 0
for i in range(3, 11):
    for itr in itertools.product('357', repeat=i):
        value = 0
        for j in range(i):
            value += int(itr[j])*10**j
        if value <= n:
            count += 1
print(count)