N = int(eval(input()))

dp = []



def dfs(x):

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

        dp.append(x)



    if x < 10**9:

        dfs(x*10+3)

        dfs(x*10+5)

        dfs(x*10+7)



dfs(0)

print((len([item for item in dp if item <= N])))

from collections import deque

N = int(eval(input()))

q = deque()

q.append(0)

memo = []

while q:

    x = q.pop()

    if x < 10**9:

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

            memo.append(x)

        q.append(10*x+3)

        q.append(10*x+5)

        q.append(10*x+7)



print((len([num for num in memo if num <= N])))

N = int(eval(input()))
dp = []


def dfs(x):
    if len(set(str(x))) == 3:
        dp.append(x)
    if x < 10**9:
        dfs(x * 10 + 3)
        dfs(x * 10 + 5)
        dfs(x * 10 + 7)


dfs(0)
print((len([item for item in dp if item <= N])))

from collections import deque

N = int(eval(input()))
q = deque()
q.append(0)
memo = []
while q:
    x = q.pop()
    if x < 10**9:
        if len(set(str(x))) == 3:
            memo.append(x)
        q.append(10 * x + 3)
        q.append(10 * x + 5)
        q.append(10 * x + 7)
print((len([num for num in memo if num <= N])))

+from collections import deque + -dp = [] - - -def dfs(x): -    if len(set(str(x))) == 3: -        dp.append(x) +q = deque() +q.append(0) +memo = [] +while q: +    x = q.pop() -        dfs(x * 10 + 3) -        dfs(x * 10 + 5) -        dfs(x * 10 + 7) - - -dfs(0) -print((len([item for item in dp if item <= N]))) +        if len(set(str(x))) == 3: +            memo.append(x) +        q.append(10 * x + 3) +        q.append(10 * x + 5) +        q.append(10 * x + 7) +print((len([num for num in memo if num <= N])))