import sys



readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

read = sys.stdin.buffer.read

sys.setrecursionlimit(10 ** 7)

INF = float('inf')



N = int(eval(input()))



def F(list_):

    if list_ and int("".join(map(str, list_))) > N:

        return

    

    if 3 in list_ and 5 in list_ and 7 in list_:

        yield 1

    

    for v in [3, 5, 7]:

        list_.append(v)

        yield from F(list_)

        list_.pop()

    return



ans = sum(F([]))

print(ans)
import sys



readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

read = sys.stdin.buffer.read

sys.setrecursionlimit(10 ** 7)

INF = float('inf')



N = int(eval(input()))



def dfs(s):

    if int(s) > N:

        return 0

    ret = 1 if all(s.count(c) > 0 for c in '753') else 0

    for c in '753':

        ret += dfs(s + c)

    return ret



ans = dfs("0")

print(ans)
import sys

readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10**7)
INF = float("inf")
N = int(eval(input()))


def F(list_):
    if list_ and int("".join(map(str, list_))) > N:
        return
    if 3 in list_ and 5 in list_ and 7 in list_:
        yield 1
    for v in [3, 5, 7]:
        list_.append(v)
        yield from F(list_)
        list_.pop()
    return


ans = sum(F([]))
print(ans)

import sys

readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10**7)
INF = float("inf")
N = int(eval(input()))


def dfs(s):
    if int(s) > N:
        return 0
    ret = 1 if all(s.count(c) > 0 for c in "753") else 0
    for c in "753":
        ret += dfs(s + c)
    return ret


ans = dfs("0")
print(ans)

-def F(list_): -    if list_ and int("".join(map(str, list_))) > N: -        return -    if 3 in list_ and 5 in list_ and 7 in list_: -        yield 1 -    for v in [3, 5, 7]: -        list_.append(v) -        yield from F(list_) -        list_.pop() -    return +def dfs(s): +    if int(s) > N: +        return 0 +    ret = 1 if all(s.count(c) > 0 for c in "753") else 0 +    for c in "753": +        ret += dfs(s + c) +    return ret -ans = sum(F([])) +ans = dfs("0")