from itertools import product

n = eval(input())

p = []

for i in range(len(n)):

	p += list(product(["7","5","3"], repeat = i+1))

a = []

for i in p:

	if ("7" not in i) or ("5" not in i) or ("3" not in i):

		continue

	else:

		if int("".join(i)) <= int(n):

			a.append(int("".join(i)))

print((len(a)))

import bisect

n = int(eval(input()))

l = len(str(n))



ary = []



siti = ["3","5","7"]

def dfs (s,t):

	if len(s) == t:

		if s.count("3") > 0 and s.count("5") > 0 and s.count("7") > 0:

			ary.append(int(s))

		return

	for j in siti:

		dfs(s+j,t)



for i in range(3,l+1):

	dfs("",i)



ary.sort()

print((bisect.bisect_right(ary,n)))
from itertools import product

n = eval(input())
p = []
for i in range(len(n)):
    p += list(product(["7", "5", "3"], repeat=i + 1))
a = []
for i in p:
    if ("7" not in i) or ("5" not in i) or ("3" not in i):
        continue
    else:
        if int("".join(i)) <= int(n):
            a.append(int("".join(i)))
print((len(a)))

import bisect

n = int(eval(input()))
l = len(str(n))
ary = []
siti = ["3", "5", "7"]


def dfs(s, t):
    if len(s) == t:
        if s.count("3") > 0 and s.count("5") > 0 and s.count("7") > 0:
            ary.append(int(s))
        return
    for j in siti:
        dfs(s + j, t)


for i in range(3, l + 1):
    dfs("", i)
ary.sort()
print((bisect.bisect_right(ary, n)))

-from itertools import product +import bisect -n = eval(input()) -p = [] -for i in range(len(n)): -    p += list(product(["7", "5", "3"], repeat=i + 1)) -a = [] -for i in p: -    if ("7" not in i) or ("5" not in i) or ("3" not in i): -        continue -    else: -        if int("".join(i)) <= int(n): -            a.append(int("".join(i))) -print((len(a))) +n = int(eval(input())) +l = len(str(n)) +ary = [] +siti = ["3", "5", "7"] + + +def dfs(s, t): +    if len(s) == t: +        if s.count("3") > 0 and s.count("5") > 0 and s.count("7") > 0: +            ary.append(int(s)) +        return +    for j in siti: +        dfs(s + j, t) + + +for i in range(3, l + 1): +    dfs("", i) +ary.sort() +print((bisect.bisect_right(ary, n)))