import itertools



a = eval(input())

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

d = 0

for i in range(1, len(a)+1):

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

        c = ""

        for k in range(len(j)):

            c += j[k]

        if int(c) <= int(a):

            if "3" in c and "5" in c and "7" in c:

                d += 1

print(d)

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 = ["3", "5", "7"]
d = 0
for i in range(1, len(a) + 1):
    for j in itertools.product(b, repeat=i):
        c = ""
        for k in range(len(j)):
            c += j[k]
        if int(c) <= int(a):
            if "3" in c and "5" in c and "7" in c:
                d += 1
print(d)

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 +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 = eval(input()) -b = ["3", "5", "7"] -d = 0 -for i in range(1, len(a) + 1): -    for j in itertools.product(b, repeat=i): -        c = "" -        for k in range(len(j)): -            c += j[k] -        if int(c) <= int(a): -            if "3" in c and "5" in c and "7" in c: -                d += 1 -print(d) + +a = int(input()) +print(ac("", a, 0, 0, 0))