from itertools import product
from bisect import bisect_left
n = int(input())
ns = []
for i in range(9):
    for j in product(["7", "5", "3"], repeat=i + 1):
        ns.append(''.join(j))
ns = sorted([int(i) for i in ns if len(set(i)) == 3])
print(bisect_left(ns, n))