n = int(eval(input()))

import itertools as it

ans = 0

for i in range(11):

  for p in it.product(*['357']*i):

    if len(set(p))>2 and int(''.join(p))<=n:

      ans += 1

print(ans)
n = eval(input())

import itertools as it

print((sum(len(set(p))>2 and int(''.join(p))<=int(n) for i in range(len(n)+1) for p in it.product('357',repeat=i))))
n = int(eval(input()))
import itertools as it

ans = 0
for i in range(11):
    for p in it.product(*["357"] * i):
        if len(set(p)) > 2 and int("".join(p)) <= n:
            ans += 1
print(ans)

n = eval(input())
import itertools as it

print(
    (
        sum(
            len(set(p)) > 2 and int("".join(p)) <= int(n)
            for i in range(len(n) + 1)
            for p in it.product("357", repeat=i)
        )
    )
)

-n = int(eval(input())) +n = eval(input()) -ans = 0 -for i in range(11): -    for p in it.product(*["357"] * i): -        if len(set(p)) > 2 and int("".join(p)) <= n: -            ans += 1 -print(ans) +print( +    ( +        sum( +            len(set(p)) > 2 and int("".join(p)) <= int(n) +            for i in range(len(n) + 1) +            for p in it.product("357", repeat=i) +        ) +    ) +)