n = int(eval(input()))



def dfs(val, A):

	if val > n:

		return



	A.append(val)



	for v in [3, 5, 7]:

		dfs(10 * val + v, A)





A = []

for v in [3, 5, 7]:

	dfs(v, A)



cnt = 0

for v in A:

	if '3' in str(v) and '5' in str(v) and '7' in str(v):

		cnt += 1



print(cnt)
from itertools import product

from bisect import bisect_left, bisect_right



n = int(eval(input()))

s = []

for i in range(3, 10):

    for v in product('753', repeat=i):

        if len(set(v)) >= 3:

            s.append(int(''.join(v)))



s.sort()



idx = bisect_right(s, n)

print((len(s[:idx])))
n = int(eval(input()))


def dfs(val, A):
    if val > n:
        return
    A.append(val)
    for v in [3, 5, 7]:
        dfs(10 * val + v, A)


A = []
for v in [3, 5, 7]:
    dfs(v, A)
cnt = 0
for v in A:
    if "3" in str(v) and "5" in str(v) and "7" in str(v):
        cnt += 1
print(cnt)

from itertools import product
from bisect import bisect_left, bisect_right

n = int(eval(input()))
s = []
for i in range(3, 10):
    for v in product("753", repeat=i):
        if len(set(v)) >= 3:
            s.append(int("".join(v)))
s.sort()
idx = bisect_right(s, n)
print((len(s[:idx])))

+from itertools import product +from bisect import bisect_left, bisect_right + - - -def dfs(val, A): -    if val > n: -        return -    A.append(val) -    for v in [3, 5, 7]: -        dfs(10 * val + v, A) - - -A = [] -for v in [3, 5, 7]: -    dfs(v, A) -cnt = 0 -for v in A: -    if "3" in str(v) and "5" in str(v) and "7" in str(v): -        cnt += 1 -print(cnt) +s = [] +for i in range(3, 10): +    for v in product("753", repeat=i): +        if len(set(v)) >= 3: +            s.append(int("".join(v))) +s.sort() +idx = bisect_right(s, n) +print((len(s[:idx])))