import itertools

N = int(eval(input()))

D = len(str(N))



ans = 0

for d in range(3,D+1):

    for ptn in itertools.product([3,5,7], repeat=d):

        if len(set(ptn)) < 3: continue

        n = int(''.join(map(str,ptn)))

        if n <= N:

            ans += 1

print(ans)
N = int(eval(input()))

from itertools import product

ans = 0

for n in range(3,10):

    for ptn in product('753', repeat=n):

        if '7' not in ptn: continue

        if '5' not in ptn: continue

        if '3' not in ptn: continue

        v = int(''.join(ptn))

        if v <= N:

            ans += 1

print(ans)
import itertools

N = int(eval(input()))
D = len(str(N))
ans = 0
for d in range(3, D + 1):
    for ptn in itertools.product([3, 5, 7], repeat=d):
        if len(set(ptn)) < 3:
            continue
        n = int("".join(map(str, ptn)))
        if n <= N:
            ans += 1
print(ans)

N = int(eval(input()))
from itertools import product

ans = 0
for n in range(3, 10):
    for ptn in product("753", repeat=n):
        if "7" not in ptn:
            continue
        if "5" not in ptn:
            continue
        if "3" not in ptn:
            continue
        v = int("".join(ptn))
        if v <= N:
            ans += 1
print(ans)

-import itertools +N = int(eval(input())) +from itertools import product -N = int(eval(input())) -D = len(str(N)) -for d in range(3, D + 1): -    for ptn in itertools.product([3, 5, 7], repeat=d): -        if len(set(ptn)) < 3: +for n in range(3, 10): +    for ptn in product("753", repeat=n): +        if "7" not in ptn: -        n = int("".join(map(str, ptn))) -        if n <= N: +        if "5" not in ptn: +            continue +        if "3" not in ptn: +            continue +        v = int("".join(ptn)) +        if v <= N: