def dfs(s):

    global cnt

    if s != "":

        if int(s) > n:

            return

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

        cnt += 1

    dfs(s + "3")

    dfs(s + "5")

    dfs(s + "7")





n = int(eval(input()))

cnt = 0

dfs("")

print(cnt)
from itertools import product



n = int(eval(input()))

cnt = 0

for i in range(3, 10):

    for j in product(["3", "5", "7"], repeat=i):

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

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

                cnt += 1

print(cnt)

def dfs(s):
    global cnt
    if s != "":
        if int(s) > n:
            return
    if len(set(s)) == 3:
        cnt += 1
    dfs(s + "3")
    dfs(s + "5")
    dfs(s + "7")


n = int(eval(input()))
cnt = 0
dfs("")
print(cnt)

from itertools import product

n = int(eval(input()))
cnt = 0
for i in range(3, 10):
    for j in product(["3", "5", "7"], repeat=i):
        if len(set(j)) == 3:
            if int("".join(j)) <= n:
                cnt += 1
print(cnt)

-def dfs(s): -    global cnt -    if s != "": -        if int(s) > n: -            return -    if len(set(s)) == 3: -        cnt += 1 -    dfs(s + "3") -    dfs(s + "5") -    dfs(s + "7") - +from itertools import product -dfs("") +for i in range(3, 10): +    for j in product(["3", "5", "7"], repeat=i): +        if len(set(j)) == 3: +            if int("".join(j)) <= n: +                cnt += 1