from itertools import product

from bisect import bisect_left, bisect_right



n = int(eval(input()))

s = []

for i in range(3, 10):

    for v in product('753', repeat=i):

        if len(set(v)) >= 3:

            s.append(int(''.join(v)))



s.sort()



idx = bisect_right(s, n)

print((len(s[:idx])))
n = int(eval(input()))



def dfs(val, A):

    if val > n:

        return

    A.append(val)

    dfs(10 * val + 3, A)

    dfs(10 * val + 5, A)

    dfs(10 * val + 7, A)



A = []

dfs(3, A)

dfs(5, A)

dfs(7, A)



cnt = 0

for v in A:

    if len(set(list(str(v)))) == 3:

        cnt += 1

print(cnt)
from itertools import product
from bisect import bisect_left, bisect_right

n = int(eval(input()))
s = []
for i in range(3, 10):
    for v in product("753", repeat=i):
        if len(set(v)) >= 3:
            s.append(int("".join(v)))
s.sort()
idx = bisect_right(s, n)
print((len(s[:idx])))

n = int(eval(input()))


def dfs(val, A):
    if val > n:
        return
    A.append(val)
    dfs(10 * val + 3, A)
    dfs(10 * val + 5, A)
    dfs(10 * val + 7, A)


A = []
dfs(3, A)
dfs(5, A)
dfs(7, A)
cnt = 0
for v in A:
    if len(set(list(str(v)))) == 3:
        cnt += 1
print(cnt)

-from itertools import product -from bisect import bisect_left, bisect_right +n = int(eval(input())) -n = int(eval(input())) -s = [] -for i in range(3, 10): -    for v in product("753", repeat=i): -        if len(set(v)) >= 3: -            s.append(int("".join(v))) -s.sort() -idx = bisect_right(s, n) -print((len(s[:idx]))) + +def dfs(val, A): +    if val > n: +        return +    A.append(val) +    dfs(10 * val + 3, A) +    dfs(10 * val + 5, A) +    dfs(10 * val + 7, A) + + +A = [] +dfs(3, A) +dfs(5, A) +dfs(7, A) +cnt = 0 +for v in A: +    if len(set(list(str(v)))) == 3: +        cnt += 1 +print(cnt)