n=int(eval(input()))

option=[3,5,7]

completed=[]

a=[3,5,7]

ans=0

while option:

    number=option.pop()

    completed.append(number)

    for add_number in a:

        new_number=number*10+add_number

        if new_number<=n:

            option.append(new_number)

for i in completed:

    i=list(str(i))

    i=set(i)

    if len(set(i))==3:

        ans+=1

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

import itertools as it



ans=0

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

    pr=list(it.product("753",repeat=i))

    

    for j in pr:

        s=set(j)

        if len(s)==3:

            num=int(''.join(j))

            if num<=n:

                ans+=1

print(ans)
n = int(eval(input()))
option = [3, 5, 7]
completed = []
a = [3, 5, 7]
ans = 0
while option:
    number = option.pop()
    completed.append(number)
    for add_number in a:
        new_number = number * 10 + add_number
        if new_number <= n:
            option.append(new_number)
for i in completed:
    i = list(str(i))
    i = set(i)
    if len(set(i)) == 3:
        ans += 1
print(ans)

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

ans = 0
for i in range(3, len(str(n)) + 1):
    pr = list(it.product("753", repeat=i))
    for j in pr:
        s = set(j)
        if len(s) == 3:
            num = int("".join(j))
            if num <= n:
                ans += 1
print(ans)

-option = [3, 5, 7] -completed = [] -a = [3, 5, 7] +import itertools as it + -while option: -    number = option.pop() -    completed.append(number) -    for add_number in a: -        new_number = number * 10 + add_number -        if new_number <= n: -            option.append(new_number) -for i in completed: -    i = list(str(i)) -    i = set(i) -    if len(set(i)) == 3: -        ans += 1 +for i in range(3, len(str(n)) + 1): +    pr = list(it.product("753", repeat=i)) +    for j in pr: +        s = set(j) +        if len(s) == 3: +            num = int("".join(j)) +            if num <= n: +                ans += 1