import itertools

N = int(input())
nums = [3, 5, 7]
num_357 = set()

# retrieval
candidates = []
for i in range(3, 10):
    candidates += list(itertools.product(nums, repeat=i))
for c in candidates:
    for n in nums:
        if n not in c:
            break
    else:
        # c contains 3 && 5 && 7
        tmp = 0
        for ind, i in enumerate(c):
            tmp += i * pow(10, ind)
        num_357.add(tmp)

# result
ans = 0
for n_357 in num_357:
    if n_357 < N:
        ans += 1
print(ans)