from collections import deque



N = int(eval(input()))

ans = 0

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

dq = deque()

for s in option:

    dq.append(s)



def judge(string):

    bit = [0]*3

    chenge = {"7":0, "5":1, "3":2}

    for s in string:

        bit[chenge[s]] = 1

    return all(bit)



while dq:

    n = dq.popleft()

    if int(n) <= N and judge(n):

        ans += 1

    if int(n) > N:

        continue

    for i,s in enumerate(option):

        dq.append(n+s)



print(ans)
N = int(eval(input()))

ans = 0

def dfs(n=0,a=0,b=0,c=0):

    if n > N:

        return

    if a*b*c > 0:

        global ans

        ans += 1

    dfs(10*n+3,a+1,b,c)

    dfs(10*n+5,a,b+1,c)

    dfs(10*n+7,a,b,c+1)



dfs()

print(ans)
from collections import deque

N = int(eval(input()))
ans = 0
option = ["7", "5", "3"]
dq = deque()
for s in option:
    dq.append(s)


def judge(string):
    bit = [0] * 3
    chenge = {"7": 0, "5": 1, "3": 2}
    for s in string:
        bit[chenge[s]] = 1
    return all(bit)


while dq:
    n = dq.popleft()
    if int(n) <= N and judge(n):
        ans += 1
    if int(n) > N:
        continue
    for i, s in enumerate(option):
        dq.append(n + s)
print(ans)

N = int(eval(input()))
ans = 0


def dfs(n=0, a=0, b=0, c=0):
    if n > N:
        return
    if a * b * c > 0:
        global ans
        ans += 1
    dfs(10 * n + 3, a + 1, b, c)
    dfs(10 * n + 5, a, b + 1, c)
    dfs(10 * n + 7, a, b, c + 1)


dfs()
print(ans)

-from collections import deque - -option = ["7", "5", "3"] -dq = deque() -for s in option: -    dq.append(s) -def judge(string): -    bit = [0] * 3 -    chenge = {"7": 0, "5": 1, "3": 2} -    for s in string: -        bit[chenge[s]] = 1 -    return all(bit) +def dfs(n=0, a=0, b=0, c=0): +    if n > N: +        return +    if a * b * c > 0: +        global ans +        ans += 1 +    dfs(10 * n + 3, a + 1, b, c) +    dfs(10 * n + 5, a, b + 1, c) +    dfs(10 * n + 7, a, b, c + 1) -while dq: -    n = dq.popleft() -    if int(n) <= N and judge(n): -        ans += 1 -    if int(n) > N: -        continue -    for i, s in enumerate(option): -        dq.append(n + s) +dfs()