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 bisect

N = int(eval(input()))

seven53 = []

def dfs(cur, s):

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

        seven53.append(s)

    if cur > 8:

        return

    else:

        for i in "753":

            dfs(cur + 1, s+i)

dfs(0, "")

seven53 = list(map(int, seven53))

seven53.sort()

print((bisect.bisect_right(seven53, N)))
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 bisect

N = int(eval(input()))
seven53 = []


def dfs(cur, s):
    if all(s.count(c) > 0 for c in "753"):
        seven53.append(s)
    if cur > 8:
        return
    else:
        for i in "753":
            dfs(cur + 1, s + i)


dfs(0, "")
seven53 = list(map(int, seven53))
seven53.sort()
print((bisect.bisect_right(seven53, N)))

+import bisect + +seven53 = [] -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 dfs(cur, s): +    if all(s.count(c) > 0 for c in "753"): +        seven53.append(s) +    if cur > 8: +        return +    else: +        for i in "753": +            dfs(cur + 1, s + i) -print((dfs("0"))) +dfs(0, "") +seven53 = list(map(int, seven53)) +seven53.sort() +print((bisect.bisect_right(seven53, N)))