S = input()
D = len(S)
N = int(S)

if D <= 2:
    print(0)
    exit(0)

lst = [[], [], [], ["357", "375", "537", "573", "735", "753"]]
for d in range(4, D + 1):
    prev = lst[d - 1]
    lstd = []
    for si in prev:
        for i in range(len(si) + 1):
            lstd.append(si[:i] + '3' + si[i:])
            lstd.append(si[:i] + '5' + si[i:])
            lstd.append(si[:i] + '7' + si[i:])
    lst.append(list(set(lstd)))

count = 0
for i in range(3, D):
    se = set(lst[i])
    count += len(se)

lstd = [int(i) for i in list(set(lst[D]))]
lstd.sort()

import bisect
count += bisect.bisect_left(lstd, N)
print(count)

