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



print((dfs('0')))
import itertools



n = int(eval(input()))

digits = [3, 5, 7]



def count(digits, n):

	A = []

	p = 3

	while True:

		for tup in itertools.product(digits, repeat=p):

			a = int(''.join(list(map(str, tup))))

			if a > n:

				break

			A.append(a)

		else:

			p += 1

			continue

		break

	return A



lst = count(digits, n)



cnt = 0

for v in lst:

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

		cnt += 1



print(cnt)

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


print((dfs("0")))

import itertools

n = int(eval(input()))
digits = [3, 5, 7]


def count(digits, n):
    A = []
    p = 3
    while True:
        for tup in itertools.product(digits, repeat=p):
            a = int("".join(list(map(str, tup))))
            if a > n:
                break
            A.append(a)
        else:
            p += 1
            continue
        break
    return A


lst = count(digits, n)
cnt = 0
for v in lst:
    if all(str(v).count(c) > 0 for c in "753"):
        cnt += 1
print(cnt)

+import itertools + +digits = [3, 5, 7] -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 +def count(digits, n): +    A = [] +    p = 3 +    while True: +        for tup in itertools.product(digits, repeat=p): +            a = int("".join(list(map(str, tup)))) +            if a > n: +                break +            A.append(a) +        else: +            p += 1 +            continue +        break +    return A -print((dfs("0"))) +lst = count(digits, n) +cnt = 0 +for v in lst: +    if all(str(v).count(c) > 0 for c in "753"): +        cnt += 1 +print(cnt)