import itertools

N = eval(input())

keta = len(N)

s = 0

for i in range(3,keta+1):

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

    for j in a:

        if 3 in j and 5 in j and 7 in j:

            if int("".join(map(str,j)))<= int(N):

                s +=1

print(s)
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)
import itertools

N = eval(input())
keta = len(N)
s = 0
for i in range(3, keta + 1):
    a = itertools.product([3, 5, 7], repeat=i)
    for j in a:
        if 3 in j and 5 in j and 7 in j:
            if int("".join(map(str, j))) <= int(N):
                s += 1
print(s)

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)

-N = eval(input()) -keta = len(N) -s = 0 -for i in range(3, keta + 1): -    a = itertools.product([3, 5, 7], repeat=i) -    for j in a: -        if 3 in j and 5 in j and 7 in j: -            if int("".join(map(str, j))) <= int(N): -                s += 1 -print(s) +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)