# https://atcoder.jp/contests/abc114/submissions/6262572



from itertools import product

N = int(eval(input()))

ans = 0

for i in range(3,10):

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

        if int("".join(s)) <= N and "3" in s and "5" in s and "7" in s:

            ans += 1

print(ans)

def dfs(start, n, len_n):

    queue = [start]



    cnt = 0

    while queue:

        parent = queue.pop()

        for c in '357':

            cc = parent+c

            if int(cc) <= n and '3' in cc and '5' in cc and '7' in cc:

                cnt += 1

            if  len(cc) < len_n:

                queue.append(cc)

    return cnt



n = eval(input())

len_n = len(n)

n = int(n)

print((dfs('', n, len_n)))

# https://atcoder.jp/contests/abc114/submissions/6262572
from itertools import product

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

def dfs(start, n, len_n):
    queue = [start]
    cnt = 0
    while queue:
        parent = queue.pop()
        for c in "357":
            cc = parent + c
            if int(cc) <= n and "3" in cc and "5" in cc and "7" in cc:
                cnt += 1
            if len(cc) < len_n:
                queue.append(cc)
    return cnt


n = eval(input())
len_n = len(n)
n = int(n)
print((dfs("", n, len_n)))

-# https://atcoder.jp/contests/abc114/submissions/6262572 -from itertools import product +def dfs(start, n, len_n): +    queue = [start] +    cnt = 0 +    while queue: +        parent = queue.pop() +        for c in "357": +            cc = parent + c +            if int(cc) <= n and "3" in cc and "5" in cc and "7" in cc: +                cnt += 1 +            if len(cc) < len_n: +                queue.append(cc) +    return cnt -N = int(eval(input())) -ans = 0 -for i in range(3, 10): -    for s in product(["3", "5", "7"], repeat=i): -        if int("".join(s)) <= N and "3" in s and "5" in s and "7" in s: -            ans += 1 -print(ans) + +n = eval(input()) +len_n = len(n) +n = int(n) +print((dfs("", n, len_n)))