import sys

from collections import deque



input = sys.stdin.readline





def dfs(N):

    stack = deque(["3", "5", "7"])

    num = 0

    while stack:

        n = stack.pop()

        if int(n) > N:

            continue

        num += 1 if all(s in n for s in "357") else 0

        stack.append("3" + n)

        stack.append("5" + n)

        stack.append("7" + n)

    return num





def main():

    N = int(eval(input()))



    ans = dfs(N)



    print(ans)





if __name__ == "__main__":

    main()

import sys

from collections import deque



input = sys.stdin.readline





def bfs(N):

    res = 0

    queue = deque(["3", "5", "7"])

    while queue:

        num = queue.popleft()

        if int(num) > N:

            break

        if all(("3" in num, "5" in num, "7" in num)):

            res += 1

        queue.append("".join([num, "3"]))

        queue.append("".join([num, "5"]))

        queue.append("".join([num, "7"]))

    return res





def main():

    N = int(eval(input()))



    ans = bfs(N)



    print(ans)





if __name__ == "__main__":

    main()

import sys
from collections import deque

input = sys.stdin.readline


def dfs(N):
    stack = deque(["3", "5", "7"])
    num = 0
    while stack:
        n = stack.pop()
        if int(n) > N:
            continue
        num += 1 if all(s in n for s in "357") else 0
        stack.append("3" + n)
        stack.append("5" + n)
        stack.append("7" + n)
    return num


def main():
    N = int(eval(input()))
    ans = dfs(N)
    print(ans)


if __name__ == "__main__":
    main()

import sys
from collections import deque

input = sys.stdin.readline


def bfs(N):
    res = 0
    queue = deque(["3", "5", "7"])
    while queue:
        num = queue.popleft()
        if int(num) > N:
            break
        if all(("3" in num, "5" in num, "7" in num)):
            res += 1
        queue.append("".join([num, "3"]))
        queue.append("".join([num, "5"]))
        queue.append("".join([num, "7"]))
    return res


def main():
    N = int(eval(input()))
    ans = bfs(N)
    print(ans)


if __name__ == "__main__":
    main()

-def dfs(N): -    stack = deque(["3", "5", "7"]) -    num = 0 -    while stack: -        n = stack.pop() -        if int(n) > N: -            continue -        num += 1 if all(s in n for s in "357") else 0 -        stack.append("3" + n) -        stack.append("5" + n) -        stack.append("7" + n) -    return num +def bfs(N): +    res = 0 +    queue = deque(["3", "5", "7"]) +    while queue: +        num = queue.popleft() +        if int(num) > N: +            break +        if all(("3" in num, "5" in num, "7" in num)): +            res += 1 +        queue.append("".join([num, "3"])) +        queue.append("".join([num, "5"])) +        queue.append("".join([num, "7"])) +    return res -    ans = dfs(N) +    ans = bfs(N)