import itertools

N = int(eval(input()))

ans = 0

for i in range(3, 10):

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

    for li in product:

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

            if int(''.join(li)) <= N:

                ans += 1

print(ans)

N = int(eval(input()))





def dfs(cur, use, cnt):

    if cur > N:

        return

    if use == 0b111:

        cnt.append(1)

    dfs(cur*10 + 7, use | 0b001, cnt)

    dfs(cur*10 + 5, use | 0b010, cnt)

    dfs(cur*10 + 3, use | 0b100, cnt)





res = []

dfs(0, 0, res)

print((sum(res)))

import itertools

N = int(eval(input()))
ans = 0
for i in range(3, 10):
    product = list(itertools.product(["3", "5", "7"], repeat=i))
    for li in product:
        if len(set(li)) == 3:
            if int("".join(li)) <= N:
                ans += 1
print(ans)

N = int(eval(input()))


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


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

-import itertools +N = int(eval(input())) -N = int(eval(input())) -ans = 0 -for i in range(3, 10): -    product = list(itertools.product(["3", "5", "7"], repeat=i)) -    for li in product: -        if len(set(li)) == 3: -            if int("".join(li)) <= N: -                ans += 1 -print(ans) + +def dfs(cur, use, cnt): +    if cur > N: +        return +    if use == 0b111: +        cnt.append(1) +    dfs(cur * 10 + 7, use | 0b001, cnt) +    dfs(cur * 10 + 5, use | 0b010, cnt) +    dfs(cur * 10 + 3, use | 0b100, cnt) + + +res = [] +dfs(0, 0, res) +print((sum(res)))