import itertools

from sys import stdin

N=int(stdin.readline().rstrip())

ans=0

for i in range(3,11):

    for j in list(itertools.product("753",repeat=i)):

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

            ans+=1

print(ans)
import itertools

from sys import stdin

N=int(stdin.readline().rstrip())

ans=0

for i in range(3,10):

    for j in list(itertools.product("753",repeat=i)):

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

            ans+=1

print(ans)
import itertools
from sys import stdin

N = int(stdin.readline().rstrip())
ans = 0
for i in range(3, 11):
    for j in list(itertools.product("753", repeat=i)):
        if int("".join(j)) <= N and len(set("".join(j))) == 3:
            ans += 1
print(ans)

import itertools
from sys import stdin

N = int(stdin.readline().rstrip())
ans = 0
for i in range(3, 10):
    for j in list(itertools.product("753", repeat=i)):
        if int("".join(j)) <= N and len(set("".join(j))) == 3:
            ans += 1
print(ans)

-for i in range(3, 11): +for i in range(3, 10):