N = eval(input())



def dfs(A):

    if int(A) > int(N):

        return 0

    if all(A.count(c) for c in "753") >0:

        ans = 1

    else:

        ans = 0

        

    for i in "357":

        A += i

        ans += dfs(A)

        A = A[:-1]

        

    return ans



print((dfs("0")))
import itertools

N = eval(input())

keta = len(N)

s = 0

for i in range(3,keta+1):

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

    for j in a:

        if 3 in j and 5 in j and 7 in j:

            if int("".join(map(str,j)))<= int(N):

                s +=1

print(s)
N = eval(input())


def dfs(A):
    if int(A) > int(N):
        return 0
    if all(A.count(c) for c in "753") > 0:
        ans = 1
    else:
        ans = 0
    for i in "357":
        A += i
        ans += dfs(A)
        A = A[:-1]
    return ans


print((dfs("0")))

import itertools

N = eval(input())
keta = len(N)
s = 0
for i in range(3, keta + 1):
    a = itertools.product([3, 5, 7], repeat=i)
    for j in a:
        if 3 in j and 5 in j and 7 in j:
            if int("".join(map(str, j))) <= int(N):
                s += 1
print(s)

+import itertools + - - -def dfs(A): -    if int(A) > int(N): -        return 0 -    if all(A.count(c) for c in "753") > 0: -        ans = 1 -    else: -        ans = 0 -    for i in "357": -        A += i -        ans += dfs(A) -        A = A[:-1] -    return ans - - -print((dfs("0"))) +keta = len(N) +s = 0 +for i in range(3, keta + 1): +    a = itertools.product([3, 5, 7], repeat=i) +    for j in a: +        if 3 in j and 5 in j and 7 in j: +            if int("".join(map(str, j))) <= int(N): +                s += 1 +print(s)