# coding:utf-8



import sys





input = sys.stdin.readline

INF = float('inf')

MOD = 10 ** 9 + 7





def inpl(): return list(map(int, input().split()))





N = int(eval(input()))





def DFS(s):

    if int(s) > N:

        return 0



    if all(s.count(c) > 0 for c in '753'):

        ret = 1

    else:

        ret = 0



    for c in '753':

        ret += DFS(s + c)

    return ret





print((DFS('0')))

# coding:utf-8



import itertools



N = int(eval(input()))



ans = 0

for i in range(2, len(str(N))):

    for s in itertools.product('753', repeat=i+1):

        if int(''.join(s)) > N:

            continue

        if all(s.count(c) > 0 for c in '753'):

            ans += 1



print(ans)

# coding:utf-8
import sys

input = sys.stdin.readline
INF = float("inf")
MOD = 10**9 + 7


def inpl():
    return list(map(int, input().split()))


N = int(eval(input()))


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


print((DFS("0")))

# coding:utf-8
import itertools

N = int(eval(input()))
ans = 0
for i in range(2, len(str(N))):
    for s in itertools.product("753", repeat=i + 1):
        if int("".join(s)) > N:
            continue
        if all(s.count(c) > 0 for c in "753"):
            ans += 1
print(ans)

-import sys - -input = sys.stdin.readline -INF = float("inf") -MOD = 10**9 + 7 - - -def inpl(): -    return list(map(int, input().split())) - +import itertools - - -def DFS(s): -    if int(s) > N: -        return 0 -    if all(s.count(c) > 0 for c in "753"): -        ret = 1 -    else: -        ret = 0 -    for c in "753": -        ret += DFS(s + c) -    return ret - - -print((DFS("0"))) +ans = 0 +for i in range(2, len(str(N))): +    for s in itertools.product("753", repeat=i + 1): +        if int("".join(s)) > N: +            continue +        if all(s.count(c) > 0 for c in "753"): +            ans += 1 +print(ans)