import itertools

N = int(eval(input()))

p = 3

digits = [3, 5, 7]

A = []

flag = False

while True:

    for tup in itertools.product(digits, repeat=p):

        a = int("".join(list(map(str, tup))))

        if a > N:

            flag = True

            break

        A.append(a)

    if flag:

        break

    p += 1

count = 0

for a in A:

    if "3" in str(a) and "5" in str(a) and "7" in str(a):

        count += 1

print(count)

import itertools

N = int(eval(input()))

digits = [3, 5, 7]





def get_A_product(digits, N):

    A = []

    flag = False

    p = 3

    while True:

        for tup in itertools.product(digits, repeat=p):

            a = int("".join(list(map(str, tup))))

            if a > N:

                flag = True

                break

            A.append(a)

        if flag:

            break

        p += 1

    return A





count = 0

A = get_A_product(digits, N)

for a in A:

    if "3" in str(a) and "5" in str(a) and "7" in str(a):

        count += 1

print(count)

import itertools

N = int(eval(input()))
p = 3
digits = [3, 5, 7]
A = []
flag = False
while True:
    for tup in itertools.product(digits, repeat=p):
        a = int("".join(list(map(str, tup))))
        if a > N:
            flag = True
            break
        A.append(a)
    if flag:
        break
    p += 1
count = 0
for a in A:
    if "3" in str(a) and "5" in str(a) and "7" in str(a):
        count += 1
print(count)

import itertools

N = int(eval(input()))
digits = [3, 5, 7]


def get_A_product(digits, N):
    A = []
    flag = False
    p = 3
    while True:
        for tup in itertools.product(digits, repeat=p):
            a = int("".join(list(map(str, tup))))
            if a > N:
                flag = True
                break
            A.append(a)
        if flag:
            break
        p += 1
    return A


count = 0
A = get_A_product(digits, N)
for a in A:
    if "3" in str(a) and "5" in str(a) and "7" in str(a):
        count += 1
print(count)

-p = 3 -A = [] -flag = False -while True: -    for tup in itertools.product(digits, repeat=p): -        a = int("".join(list(map(str, tup)))) -        if a > N: -            flag = True + + +def get_A_product(digits, N): +    A = [] +    flag = False +    p = 3 +    while True: +        for tup in itertools.product(digits, repeat=p): +            a = int("".join(list(map(str, tup)))) +            if a > N: +                flag = True +                break +            A.append(a) +        if flag: -        A.append(a) -    if flag: -        break -    p += 1 +        p += 1 +    return A + + +A = get_A_product(digits, N)