def ac(s, t, int3, int5, int7):

    if s == "":

        return ac(s + "3", t, int3 + 1, int5, int7) \

               + ac(s + "5", t, int3, int5+1, int7) \

               + ac(s + "7", t, int3, int5, int7+1)

    elif int(s) <= t:

        if int3 != 0 and int5 != 0 and int7 != 0:

            return 1 \

                   + ac(s + "3", t, int3 + 1, int5, int7) \

                   + ac(s + "5", t, int3, int5+1, int7) \

                   + ac(s + "7", t, int3, int5, int7+1)

        else:

            return 0 \

                   + ac(s + "3", t, int3 + 1, int5, int7) \

                   + ac(s + "5", t, int3, int5 + 1, int7) \

                   + ac(s + "7", t, int3, int5, int7 + 1)

    else:

        return 0





a = int(input())

print(ac("", a, 0, 0, 0))

import itertools

a = eval(input())

b = list("357")

c = 0

for j in range(3, len(a) + 1):

    for i in itertools.product(b, repeat=j):

        if int("".join(i)) <= int(a) and "3" in i and "5" in i and "7" in i:

            c += 1

print(c)

def ac(s, t, int3, int5, int7):
    if s == "":
        return (
            ac(s + "3", t, int3 + 1, int5, int7)
            + ac(s + "5", t, int3, int5 + 1, int7)
            + ac(s + "7", t, int3, int5, int7 + 1)
        )
    elif int(s) <= t:
        if int3 != 0 and int5 != 0 and int7 != 0:
            return (
                1
                + ac(s + "3", t, int3 + 1, int5, int7)
                + ac(s + "5", t, int3, int5 + 1, int7)
                + ac(s + "7", t, int3, int5, int7 + 1)
            )
        else:
            return (
                0
                + ac(s + "3", t, int3 + 1, int5, int7)
                + ac(s + "5", t, int3, int5 + 1, int7)
                + ac(s + "7", t, int3, int5, int7 + 1)
            )
    else:
        return 0


a = int(input())
print(ac("", a, 0, 0, 0))

import itertools

a = eval(input())
b = list("357")
c = 0
for j in range(3, len(a) + 1):
    for i in itertools.product(b, repeat=j):
        if int("".join(i)) <= int(a) and "3" in i and "5" in i and "7" in i:
            c += 1
print(c)

-def ac(s, t, int3, int5, int7): -    if s == "": -        return ( -            ac(s + "3", t, int3 + 1, int5, int7) -            + ac(s + "5", t, int3, int5 + 1, int7) -            + ac(s + "7", t, int3, int5, int7 + 1) -        ) -    elif int(s) <= t: -        if int3 != 0 and int5 != 0 and int7 != 0: -            return ( -                1 -                + ac(s + "3", t, int3 + 1, int5, int7) -                + ac(s + "5", t, int3, int5 + 1, int7) -                + ac(s + "7", t, int3, int5, int7 + 1) -            ) -        else: -            return ( -                0 -                + ac(s + "3", t, int3 + 1, int5, int7) -                + ac(s + "5", t, int3, int5 + 1, int7) -                + ac(s + "7", t, int3, int5, int7 + 1) -            ) -    else: -        return 0 +import itertools - -a = int(input()) -print(ac("", a, 0, 0, 0)) +a = eval(input()) +b = list("357") +c = 0 +for j in range(3, len(a) + 1): +    for i in itertools.product(b, repeat=j): +        if int("".join(i)) <= int(a) and "3" in i and "5" in i and "7" in i: +            c += 1 +print(c)