s = eval(input())

l = len(s)

N = int(s)

ans = 0

for i1, a in enumerate(" 357"):

    if l<9 and i1>0: break

    for i2, b in enumerate(" 357"):

        if l<8 and i2>0: break

        for i3, c in enumerate(" 357"):

            if l<7 and i3>0: break

            for i4, d in enumerate(" 357"):

                if l<6 and i4>0: break

                for i5, e in enumerate(" 357"):

                    if l<5 and i5>0: break

                    for i6, f in enumerate(" 357"):

                        if l<4 and i6>0: break

                        for g in " 357":

                            for h in " 357":

                                for i in " 357":

                                    for j in "357":

                                        try:

                                            s = a+b+c+d+e+f+g+h+i+j

                                            n = int(s)

                                            if N >= n and "3" in s and "5" in s and "7" in s:

                                                ans += 1

                                        except ValueError:

                                            pass

print(ans)
from functools import lru_cache

@lru_cache(maxsize=1000)

def digit_search(k, tight, own, X, started):

    if k == len(X):

        return int(own==7)



    digit = int(X[k])

    lim = digit if tight else 9

    res = 0

    for i in range(lim+1):

        if started:

            if i!=3 and i!=5 and i!=7: continue

        else:

            if i!=0 and i!=3 and i!=5 and i!=7: continue



        res += digit_search(k+1, tight and digit==i,\

                            own | (i==7)*4 | (i==5)*2 | (i==3),\

                            X, started or i!=0)



    return res



print((digit_search(0, True, 0, eval(input()), False)))

s = eval(input())
l = len(s)
N = int(s)
ans = 0
for i1, a in enumerate(" 357"):
    if l < 9 and i1 > 0:
        break
    for i2, b in enumerate(" 357"):
        if l < 8 and i2 > 0:
            break
        for i3, c in enumerate(" 357"):
            if l < 7 and i3 > 0:
                break
            for i4, d in enumerate(" 357"):
                if l < 6 and i4 > 0:
                    break
                for i5, e in enumerate(" 357"):
                    if l < 5 and i5 > 0:
                        break
                    for i6, f in enumerate(" 357"):
                        if l < 4 and i6 > 0:
                            break
                        for g in " 357":
                            for h in " 357":
                                for i in " 357":
                                    for j in "357":
                                        try:
                                            s = a + b + c + d + e + f + g + h + i + j
                                            n = int(s)
                                            if (
                                                N >= n
                                                and "3" in s
                                                and "5" in s
                                                and "7" in s
                                            ):
                                                ans += 1
                                        except ValueError:
                                            pass
print(ans)

from functools import lru_cache


@lru_cache(maxsize=1000)
def digit_search(k, tight, own, X, started):
    if k == len(X):
        return int(own == 7)
    digit = int(X[k])
    lim = digit if tight else 9
    res = 0
    for i in range(lim + 1):
        if started:
            if i != 3 and i != 5 and i != 7:
                continue
        else:
            if i != 0 and i != 3 and i != 5 and i != 7:
                continue
        res += digit_search(
            k + 1,
            tight and digit == i,
            own | (i == 7) * 4 | (i == 5) * 2 | (i == 3),
            X,
            started or i != 0,
        )
    return res


print((digit_search(0, True, 0, eval(input()), False)))

-s = eval(input()) -l = len(s) -N = int(s) -ans = 0 -for i1, a in enumerate(" 357"): -    if l < 9 and i1 > 0: -        break -    for i2, b in enumerate(" 357"): -        if l < 8 and i2 > 0: -            break -        for i3, c in enumerate(" 357"): -            if l < 7 and i3 > 0: -                break -            for i4, d in enumerate(" 357"): -                if l < 6 and i4 > 0: -                    break -                for i5, e in enumerate(" 357"): -                    if l < 5 and i5 > 0: -                        break -                    for i6, f in enumerate(" 357"): -                        if l < 4 and i6 > 0: -                            break -                        for g in " 357": -                            for h in " 357": -                                for i in " 357": -                                    for j in "357": -                                        try: -                                            s = a + b + c + d + e + f + g + h + i + j -                                            n = int(s) -                                            if ( -                                                N >= n -                                                and "3" in s -                                                and "5" in s -                                                and "7" in s -                                            ): -                                                ans += 1 -                                        except ValueError: -                                            pass -print(ans) +from functools import lru_cache + + +@lru_cache(maxsize=1000) +def digit_search(k, tight, own, X, started): +    if k == len(X): +        return int(own == 7) +    digit = int(X[k]) +    lim = digit if tight else 9 +    res = 0 +    for i in range(lim + 1): +        if started: +            if i != 3 and i != 5 and i != 7: +                continue +        else: +            if i != 0 and i != 3 and i != 5 and i != 7: +                continue +        res += digit_search( +            k + 1, +            tight and digit == i, +            own | (i == 7) * 4 | (i == 5) * 2 | (i == 3), +            X, +            started or i != 0, +        ) +    return res + + +print((digit_search(0, True, 0, eval(input()), False)))