S = eval(input())



def solve(s, n=0, tight=True, value=""):

	if n == len(s):

		while value and value[0] == "0":

			value = value[1:]

		if set("753") == set(value):

			#print(value)

			return 1

		return 0

	hi = int(s[n]) if tight else 9

	c = 0

	for i in range(hi + 1):

		if i in [7, 5, 3, 0]:

			c += solve(s, n + 1, tight and not(i < hi), value + str(i))

	return c



print((solve(S)))

S = eval(input())



def solve(s):

	if s and int(s) > int(S):

		return 0

	count = 0

	if set(s) == set("753"):

		#print(s)

		count = 1

	for c in "753":

		count += solve(s + c)

	return count



print((solve("")))

S = eval(input())


def solve(s, n=0, tight=True, value=""):
    if n == len(s):
        while value and value[0] == "0":
            value = value[1:]
        if set("753") == set(value):
            # print(value)
            return 1
        return 0
    hi = int(s[n]) if tight else 9
    c = 0
    for i in range(hi + 1):
        if i in [7, 5, 3, 0]:
            c += solve(s, n + 1, tight and not (i < hi), value + str(i))
    return c


print((solve(S)))

S = eval(input())


def solve(s):
    if s and int(s) > int(S):
        return 0
    count = 0
    if set(s) == set("753"):
        # print(s)
        count = 1
    for c in "753":
        count += solve(s + c)
    return count


print((solve("")))

-def solve(s, n=0, tight=True, value=""): -    if n == len(s): -        while value and value[0] == "0": -            value = value[1:] -        if set("753") == set(value): -            # print(value) -            return 1 +def solve(s): +    if s and int(s) > int(S): -    hi = int(s[n]) if tight else 9 -    c = 0 -    for i in range(hi + 1): -        if i in [7, 5, 3, 0]: -            c += solve(s, n + 1, tight and not (i < hi), value + str(i)) -    return c +    count = 0 +    if set(s) == set("753"): +        # print(s) +        count = 1 +    for c in "753": +        count += solve(s + c) +    return count -print((solve(S))) +print((solve("")))