from collections import deque

N=int(eval(input()))

nums=["3","5","7"]

stack=deque(nums)

cnt=0

while stack:

    cand=stack.pop()

    if ('3' in cand) and ('5' in cand) and ('7' in cand):

        cnt+=1

    for c in nums:

        if int(cand+c)<=N:

            stack.append(cand+c)



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

lim=len(str(n))

cand=[3,5,7]

ans=[]

while cand:

    i=cand.pop()

    for j in [3,5,7]:

        k=int(str(i)+str(j))

        if k<=n:

            cand.append(k)

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

                ans.append(k)

print((len(ans)))
from collections import deque

N = int(eval(input()))
nums = ["3", "5", "7"]
stack = deque(nums)
cnt = 0
while stack:
    cand = stack.pop()
    if ("3" in cand) and ("5" in cand) and ("7" in cand):
        cnt += 1
    for c in nums:
        if int(cand + c) <= N:
            stack.append(cand + c)
print(cnt)

n = int(eval(input()))
lim = len(str(n))
cand = [3, 5, 7]
ans = []
while cand:
    i = cand.pop()
    for j in [3, 5, 7]:
        k = int(str(i) + str(j))
        if k <= n:
            cand.append(k)
            if len(set(str(k))) == 3:
                ans.append(k)
print((len(ans)))

-from collections import deque - -N = int(eval(input())) -nums = ["3", "5", "7"] -stack = deque(nums) -cnt = 0 -while stack: -    cand = stack.pop() -    if ("3" in cand) and ("5" in cand) and ("7" in cand): -        cnt += 1 -    for c in nums: -        if int(cand + c) <= N: -            stack.append(cand + c) -print(cnt) +n = int(eval(input())) +lim = len(str(n)) +cand = [3, 5, 7] +ans = [] +while cand: +    i = cand.pop() +    for j in [3, 5, 7]: +        k = int(str(i) + str(j)) +        if k <= n: +            cand.append(k) +            if len(set(str(k))) == 3: +                ans.append(k) +print((len(ans)))