import itertools

n=eval(input())

ans=0



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

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

    

    for j in li:

        t=''.join(map(str,j))

        

        if int(t)<=int(n):

            if t.count("3")>=1 and t.count("5")>=1 and t.count("7")>=1:

                ans+=1



print(ans)

n=int(eval(input()))



def dfs(num):

    if int(num)>n:

        return 0

    else:

        if num.count("3")>=1 and num.count("5")>=1 and num.count("7")>=1:

            ans=1

        else:

            ans=0

        

        for i in "753":

            ans=ans+dfs(num+i)

        return ans

        



print((dfs("0")))

import itertools

n = eval(input())
ans = 0
for i in range(3, len(n) + 1):
    li = itertools.product([3, 5, 7], repeat=i)
    for j in li:
        t = "".join(map(str, j))
        if int(t) <= int(n):
            if t.count("3") >= 1 and t.count("5") >= 1 and t.count("7") >= 1:
                ans += 1
print(ans)

n = int(eval(input()))


def dfs(num):
    if int(num) > n:
        return 0
    else:
        if num.count("3") >= 1 and num.count("5") >= 1 and num.count("7") >= 1:
            ans = 1
        else:
            ans = 0
        for i in "753":
            ans = ans + dfs(num + i)
        return ans


print((dfs("0")))

-import itertools +n = int(eval(input())) -n = eval(input()) -ans = 0 -for i in range(3, len(n) + 1): -    li = itertools.product([3, 5, 7], repeat=i) -    for j in li: -        t = "".join(map(str, j)) -        if int(t) <= int(n): -            if t.count("3") >= 1 and t.count("5") >= 1 and t.count("7") >= 1: -                ans += 1 -print(ans) + +def dfs(num): +    if int(num) > n: +        return 0 +    else: +        if num.count("3") >= 1 and num.count("5") >= 1 and num.count("7") >= 1: +            ans = 1 +        else: +            ans = 0 +        for i in "753": +            ans = ans + dfs(num + i) +        return ans + + +print((dfs("0")))