import itertools

N = input()
count = 0
list = ["3", "5", "7"]

for i in range(3, len(N)):
    # print(3**i - (2**i) * 3)
    count += 3**i - (2**i) * 3 + 3
# print(count)
for i in itertools.product(list, repeat=len(N)):
    if int("".join(i)) < int(N):
        if "3" in i and "5" in i and "7" in i:
            # print("".join(i))
            count += 1
    else:
        break
print(count)