#!/usr/bin/env python3

n = int(eval(input()))



def dfs(k):  # k : str

    if int(k) > n: return 0

    c = 1 if all(k.count(t) for t in "753") else 0  # k judge

    for t in "753":

        c += dfs(k + t)

    return c

print((dfs("0")))
#!/usr/bin/env python3

from itertools import*

n = int(eval(input()))

c = 0

k = "357"



for i in range(3, -~len(str(n))):

    for j in product(k, repeat = i):

        if all(j.count(h) for h in k):

            if int("".join(j)) <= n:

                c += 1

print(c)
#!/usr/bin/env python3
n = int(eval(input()))


def dfs(k):  # k : str
    if int(k) > n:
        return 0
    c = 1 if all(k.count(t) for t in "753") else 0  # k judge
    for t in "753":
        c += dfs(k + t)
    return c


print((dfs("0")))

#!/usr/bin/env python3
from itertools import *

n = int(eval(input()))
c = 0
k = "357"
for i in range(3, -~len(str(n))):
    for j in product(k, repeat=i):
        if all(j.count(h) for h in k):
            if int("".join(j)) <= n:
                c += 1
print(c)

+from itertools import * + - - -def dfs(k):  # k : str -    if int(k) > n: -        return 0 -    c = 1 if all(k.count(t) for t in "753") else 0  # k judge -    for t in "753": -        c += dfs(k + t) -    return c - - -print((dfs("0"))) +c = 0 +k = "357" +for i in range(3, -~len(str(n))): +    for j in product(k, repeat=i): +        if all(j.count(h) for h in k): +            if int("".join(j)) <= n: +                c += 1 +print(c)