import itertools

N=int(eval(input()))

ans=0

S=[]

for i in range(10):

    S+=list(itertools.product("357",repeat=i))

for s in S:

    if len(set(s))>2 and int("".join(s))<=N:

        ans+=1

print(ans)
from itertools import product

N = int(eval(input()))

count = 0

for i in range(3,10):

    a = product(["3","5","7"],repeat=i)

    for b in a:

        if 1<=int("".join(b))<=N and len(set(b))==3:

            count += 1

print(count)
import itertools

N = int(eval(input()))
ans = 0
S = []
for i in range(10):
    S += list(itertools.product("357", repeat=i))
for s in S:
    if len(set(s)) > 2 and int("".join(s)) <= N:
        ans += 1
print(ans)

from itertools import product

N = int(eval(input()))
count = 0
for i in range(3, 10):
    a = product(["3", "5", "7"], repeat=i)
    for b in a:
        if 1 <= int("".join(b)) <= N and len(set(b)) == 3:
            count += 1
print(count)

-import itertools +from itertools import product -ans = 0 -S = [] -for i in range(10): -    S += list(itertools.product("357", repeat=i)) -for s in S: -    if len(set(s)) > 2 and int("".join(s)) <= N: -        ans += 1 -print(ans) +count = 0 +for i in range(3, 10): +    a = product(["3", "5", "7"], repeat=i) +    for b in a: +        if 1 <= int("".join(b)) <= N and len(set(b)) == 3: +            count += 1 +print(count)