from itertools import product

N = int(eval(input()))

E = [3,5,7]

ans = 0



for i in range(3, len(str(N))+1) :

    L = product(E, repeat=i)

    for l in L :

        if (3 not in l) or (5 not in l) or (7 not in l) :

            continue

        number = int("".join(list(map(str,l))))

        if number <= N :

            ans += 1

print(ans)

from itertools import *



N = int(eval(input()))



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



ans = 0



length = len(str(N))



for i in range(3, length+1) :

    for prod in product(A, repeat=i) :

        if prod.count("3") == 0 or prod.count("5") == 0 or prod.count("7") == 0 :

            continue

        

        num = int("".join(prod))

        if num > N :

            break

        

        ans += 1

        

print(ans)

from itertools import product

N = int(eval(input()))
E = [3, 5, 7]
ans = 0
for i in range(3, len(str(N)) + 1):
    L = product(E, repeat=i)
    for l in L:
        if (3 not in l) or (5 not in l) or (7 not in l):
            continue
        number = int("".join(list(map(str, l))))
        if number <= N:
            ans += 1
print(ans)

from itertools import *

N = int(eval(input()))
A = ["3", "5", "7"]
ans = 0
length = len(str(N))
for i in range(3, length + 1):
    for prod in product(A, repeat=i):
        if prod.count("3") == 0 or prod.count("5") == 0 or prod.count("7") == 0:
            continue
        num = int("".join(prod))
        if num > N:
            break
        ans += 1
print(ans)

-from itertools import product +from itertools import * -E = [3, 5, 7] +A = ["3", "5", "7"] -for i in range(3, len(str(N)) + 1): -    L = product(E, repeat=i) -    for l in L: -        if (3 not in l) or (5 not in l) or (7 not in l): +length = len(str(N)) +for i in range(3, length + 1): +    for prod in product(A, repeat=i): +        if prod.count("3") == 0 or prod.count("5") == 0 or prod.count("7") == 0: -        number = int("".join(list(map(str, l)))) -        if number <= N: -            ans += 1 +        num = int("".join(prod)) +        if num > N: +            break +        ans += 1