N = int(eval(input()))



l = len(str(10**9))

def dfs(A):#配列Aからできる753数

    global N

    if len(A)>0 and(int("".join(map(str, A)))>N):

        return 0

    

    ans = 0

    if(all(A.count(i)==0 for i in [0, 1, 2, 4, 6, 8, 9]) and (A.count(3) >0 and A.count(5) >0 and A.count(7) >0)):

        ans = ans + 1

    

    for i in [3, 5, 7]:

        A.append(i)

        ans = ans + dfs(A)

        A.pop()

    

    return ans

print((dfs([])))

N = int(eval(input()))

import sys

sys.setrecursionlimit(500000)

def dfs(l):

    global N



    if l!=[] and N<int("".join(l)):

        return 0

    ans = 0

    if all(l.count(i)>0 for i in ["3", "5", "7"]):

        ans = 1

    for i in ["3", "5", "7"]:

        l.append(i)

        #参照渡し

        ans += dfs(l)

        l.pop()



    return ans



print((dfs([])))
N = int(eval(input()))
l = len(str(10**9))


def dfs(A):  # 配列Aからできる753数
    global N
    if len(A) > 0 and (int("".join(map(str, A))) > N):
        return 0
    ans = 0
    if all(A.count(i) == 0 for i in [0, 1, 2, 4, 6, 8, 9]) and (
        A.count(3) > 0 and A.count(5) > 0 and A.count(7) > 0
    ):
        ans = ans + 1
    for i in [3, 5, 7]:
        A.append(i)
        ans = ans + dfs(A)
        A.pop()
    return ans


print((dfs([])))

N = int(eval(input()))
import sys

sys.setrecursionlimit(500000)


def dfs(l):
    global N
    if l != [] and N < int("".join(l)):
        return 0
    ans = 0
    if all(l.count(i) > 0 for i in ["3", "5", "7"]):
        ans = 1
    for i in ["3", "5", "7"]:
        l.append(i)
        # 参照渡し
        ans += dfs(l)
        l.pop()
    return ans


print((dfs([])))

-l = len(str(10**9)) +import sys + +sys.setrecursionlimit(500000) -def dfs(A):  # 配列Aからできる753数 +def dfs(l): -    if len(A) > 0 and (int("".join(map(str, A))) > N): +    if l != [] and N < int("".join(l)): -    if all(A.count(i) == 0 for i in [0, 1, 2, 4, 6, 8, 9]) and ( -        A.count(3) > 0 and A.count(5) > 0 and A.count(7) > 0 -    ): -        ans = ans + 1 -    for i in [3, 5, 7]: -        A.append(i) -        ans = ans + dfs(A) -        A.pop() +    if all(l.count(i) > 0 for i in ["3", "5", "7"]): +        ans = 1 +    for i in ["3", "5", "7"]: +        l.append(i) +        # 参照渡し +        ans += dfs(l) +        l.pop()