from bisect import  bisect



def convert(number) :

    if number == 0 :

        out = "0"

    else :

        out = ""

    while number > 0 :

        surplus = (number % 4)

        out = str(surplus) + out

        number //= 4

    return out



def seven_five_three(string) :

    string = string.replace("3","7").replace("2","5").replace("1","3")

    return string



L = []

for i in range(3*10**5) :

    l = convert(i)

    l = seven_five_three(l)

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

        continue

    l = int(l)

    L.append(l)



N = int(eval(input()))

ans = bisect(L,N)

print(ans)

from itertools import product

element = [3,5,7]



N = int(eval(input()))

ans = 0

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

    L = product(element, repeat=i)

    for candidate in L :

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

            continue

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

        if l <= N :

            ans += 1

print(ans)
from bisect import bisect


def convert(number):
    if number == 0:
        out = "0"
    else:
        out = ""
    while number > 0:
        surplus = number % 4
        out = str(surplus) + out
        number //= 4
    return out


def seven_five_three(string):
    string = string.replace("3", "7").replace("2", "5").replace("1", "3")
    return string


L = []
for i in range(3 * 10**5):
    l = convert(i)
    l = seven_five_three(l)
    if ("0" in l) or ("3" not in l) or ("5" not in l) or ("7" not in l):
        continue
    l = int(l)
    L.append(l)
N = int(eval(input()))
ans = bisect(L, N)
print(ans)

from itertools import product

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

-from bisect import bisect +from itertools import product - -def convert(number): -    if number == 0: -        out = "0" -    else: -        out = "" -    while number > 0: -        surplus = number % 4 -        out = str(surplus) + out -        number //= 4 -    return out - - -def seven_five_three(string): -    string = string.replace("3", "7").replace("2", "5").replace("1", "3") -    return string - - -L = [] -for i in range(3 * 10**5): -    l = convert(i) -    l = seven_five_three(l) -    if ("0" in l) or ("3" not in l) or ("5" not in l) or ("7" not in l): -        continue -    l = int(l) -    L.append(l) +element = [3, 5, 7] -ans = bisect(L, N) +ans = 0 +for i in range(3, len(str(N)) + 1): +    L = product(element, repeat=i) +    for candidate in L: +        if (3 not in candidate) or (5 not in candidate) or (7 not in candidate): +            continue +        l = int("".join(list(map(str, candidate)))) +        if l <= N: +            ans += 1