n = int(input())
from collections import deque
d = deque([0])
cnt = 0
while d[-1] < n:
    x = d.popleft()
    for i in range(3,8,2):
        d.append(x * 10 + i)
        cnt += 1 if all(str(x * 10 + i).count(c)>0 for c in "753") else 0
ans=0
if d[-3] > n:
    for i in range(1,4):
        ans += 1 if all(str(d[-i]).count(c) > 0 for c in "753") else 0
    print(cnt - ans)
elif d[-2] > n:
    for i in range(1,2):
        ans += 1 if all(str(d[-i]).count(c) > 0 for c in "753") else 0
    print(cnt - ans)
elif d[-1] > n:
    if all (str(d[-1]).count(c) > 0 for c in "753"):
        print(cnt - 1)
    else:
        print(cnt)

