import sys
from collections import deque
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = input()
num = int(n)
l = len(n)
li = ['3', '5', '7']
keta = [[] for i in range(l)]
keta[0] = li
for i in range(1, l):
    for kazu in keta[i-1]:
        for n in li:
            keta[i].append(kazu + n)
ct = 0
if l < 3:
    print(0)
else:
    for i in range(2, l):
        for n in keta[i]:
            if '3' in n and '5' in n and '7' in n and int(n) < num:
                ct += 1
    print(ct)

