from itertools import product

n = int(eval(input()))

i = len(str(n))



cnt = 0

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

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

        if len(set(k)) != 3:

            continue

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

            cnt += 1



print(cnt)
N = int(eval(input()))





def dfs(current, judge, count):

    if current > N:

        return

    if judge == 0b111:

        count.append(1)



    dfs(current * 10 + 7, judge | 0b100, count)

    dfs(current * 10 + 5, judge | 0b010, count)

    dfs(current * 10 + 3, judge | 0b001, count)





cnt = []

dfs(0, 0, cnt)

print((sum(cnt)))
from itertools import product

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

N = int(eval(input()))


def dfs(current, judge, count):
    if current > N:
        return
    if judge == 0b111:
        count.append(1)
    dfs(current * 10 + 7, judge | 0b100, count)
    dfs(current * 10 + 5, judge | 0b010, count)
    dfs(current * 10 + 3, judge | 0b001, count)


cnt = []
dfs(0, 0, cnt)
print((sum(cnt)))

-from itertools import product +N = int(eval(input())) -n = int(eval(input())) -i = len(str(n)) -cnt = 0 -for j in range(3, i + 1): -    for k in product(["3", "5", "7"], repeat=j): -        if len(set(k)) != 3: -            continue -        if int("".join(k)) <= n: -            cnt += 1 -print(cnt) + +def dfs(current, judge, count): +    if current > N: +        return +    if judge == 0b111: +        count.append(1) +    dfs(current * 10 + 7, judge | 0b100, count) +    dfs(current * 10 + 5, judge | 0b010, count) +    dfs(current * 10 + 3, judge | 0b001, count) + + +cnt = [] +dfs(0, 0, cnt) +print((sum(cnt)))