from collections import deque

N = int(eval(input()))

memo = {i:1 for i in [357, 375, 537, 573, 735, 753]}

ans = 0

queue = deque()

mod = [10**i for i in range(10)]

for key in list(memo.keys()):

  if key <= N:

    ans += 1

    queue.append(key)

while queue:

    key = queue.popleft()

    len_key = len(str(key))

    for i in range(len_key):

        for j in [3,5,7]:

            tmp = (key // mod[i]) * mod[i+1] + j * mod[i] + key % mod[i]

            if tmp not in memo and tmp <= N:

                ans += 1

                memo[tmp] = 1

                queue.append(tmp)

print(ans)

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



from itertools import product

N = eval(input())

n = int(N)

ans = 0

for i in range(3, len(N)+1):

    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)

from collections import deque

N = int(eval(input()))
memo = {i: 1 for i in [357, 375, 537, 573, 735, 753]}
ans = 0
queue = deque()
mod = [10**i for i in range(10)]
for key in list(memo.keys()):
    if key <= N:
        ans += 1
        queue.append(key)
while queue:
    key = queue.popleft()
    len_key = len(str(key))
    for i in range(len_key):
        for j in [3, 5, 7]:
            tmp = (key // mod[i]) * mod[i + 1] + j * mod[i] + key % mod[i]
            if tmp not in memo and tmp <= N:
                ans += 1
                memo[tmp] = 1
                queue.append(tmp)
print(ans)

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

N = eval(input())
n = int(N)
ans = 0
for i in range(3, len(N) + 1):
    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)

-from collections import deque +# https://atcoder.jp/contests/abc114/submissions/6262572 +from itertools import product -N = int(eval(input())) -memo = {i: 1 for i in [357, 375, 537, 573, 735, 753]} +N = eval(input()) +n = int(N) -queue = deque() -mod = [10**i for i in range(10)] -for key in list(memo.keys()): -    if key <= N: -        ans += 1 -        queue.append(key) -while queue: -    key = queue.popleft() -    len_key = len(str(key)) -    for i in range(len_key): -        for j in [3, 5, 7]: -            tmp = (key // mod[i]) * mod[i + 1] + j * mod[i] + key % mod[i] -            if tmp not in memo and tmp <= N: -                ans += 1 -                memo[tmp] = 1 -                queue.append(tmp) +for i in range(3, len(N) + 1): +    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