import itertools

n = int(eval(input()))

cnt = 0

for i in range(3,len(str(n))+1):

    for v in itertools.product(["3","5","7"], repeat=i):

        if len(set(v))!=3: continue

        x = int("".join(v))

        if n >= x: cnt += 1



print(cnt)
import itertools

import bisect

n = int(eval(input()))

numbers = []

for i in range(3,10):

    for v in itertools.product(["7","5","3"], repeat=i):

        if "5" in v and "7" in v and "3" in v:numbers.append(int("".join(v)))

numbers.sort()

print((bisect.bisect_right(numbers,n)))
import itertools

n = int(eval(input()))
cnt = 0
for i in range(3, len(str(n)) + 1):
    for v in itertools.product(["3", "5", "7"], repeat=i):
        if len(set(v)) != 3:
            continue
        x = int("".join(v))
        if n >= x:
            cnt += 1
print(cnt)

import itertools
import bisect

n = int(eval(input()))
numbers = []
for i in range(3, 10):
    for v in itertools.product(["7", "5", "3"], repeat=i):
        if "5" in v and "7" in v and "3" in v:
            numbers.append(int("".join(v)))
numbers.sort()
print((bisect.bisect_right(numbers, n)))

+import bisect -cnt = 0 -for i in range(3, len(str(n)) + 1): -    for v in itertools.product(["3", "5", "7"], repeat=i): -        if len(set(v)) != 3: -            continue -        x = int("".join(v)) -        if n >= x: -            cnt += 1 -print(cnt) +numbers = [] +for i in range(3, 10): +    for v in itertools.product(["7", "5", "3"], repeat=i): +        if "5" in v and "7" in v and "3" in v: +            numbers.append(int("".join(v))) +numbers.sort() +print((bisect.bisect_right(numbers, n)))