N = eval(input())

def rec(list1,initial,time):

    empty = []

    for e in list1:

        for b in [0,1,2]:

            if b == 0:

                e_copy = e + "3"

                empty.append(e_copy)

            elif b == 1:

                e_copy = e + "5"

                empty.append(e_copy)

            elif b == 2:

                e_copy = e + "7"

                empty.append(e_copy)

    list1 = empty[:]

    # initial + 1 がn回目のループ

    if initial + 1 >= time :

        return list1

    else:

        return rec(list1,initial + 1, time)

l1 = [""]

result = rec(l1,0,3)

for i in range(len(N)-3):

    result += rec(result,0,1)

result = [int(e) for e in result if e.count("3")*e.count("5")*e.count("7") >= 1]

result = list(set(result))

result.sort()

count = 0

for e in result:

    if int(N) < e:

        break

    count += 1

print(count)
from collections import Counter

N = eval(input())

def rec(list1,initial,time):

    empty = []

    for e in list1:

        for b in [0,1,2]:

            if b == 0:

                e_copy = e + "3"

                empty.append(e_copy)

            elif b == 1:

                e_copy = e + "5"

                empty.append(e_copy)

            elif b == 2:

                e_copy = e + "7"

                empty.append(e_copy)

    list1 = empty[:]

    # initial + 1 がn回目のループ

    if initial + 1 >= time :

        return list1

    else:

        return rec(list1,initial + 1, time)

l1 = [""]

result = [""]

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

    result += rec(l1,0,i)

result = [int(e) for e in result if e.count("3")*e.count("5")*e.count("7") >= 1]

#result = list(set(result))

count = 0

for e in result:

    if int(N) < e:

        break

    count += 1

print(count)
N = eval(input())


def rec(list1, initial, time):
    empty = []
    for e in list1:
        for b in [0, 1, 2]:
            if b == 0:
                e_copy = e + "3"
                empty.append(e_copy)
            elif b == 1:
                e_copy = e + "5"
                empty.append(e_copy)
            elif b == 2:
                e_copy = e + "7"
                empty.append(e_copy)
    list1 = empty[:]
    # initial + 1 がn回目のループ
    if initial + 1 >= time:
        return list1
    else:
        return rec(list1, initial + 1, time)


l1 = [""]
result = rec(l1, 0, 3)
for i in range(len(N) - 3):
    result += rec(result, 0, 1)
result = [int(e) for e in result if e.count("3") * e.count("5") * e.count("7") >= 1]
result = list(set(result))
result.sort()
count = 0
for e in result:
    if int(N) < e:
        break
    count += 1
print(count)

from collections import Counter

N = eval(input())


def rec(list1, initial, time):
    empty = []
    for e in list1:
        for b in [0, 1, 2]:
            if b == 0:
                e_copy = e + "3"
                empty.append(e_copy)
            elif b == 1:
                e_copy = e + "5"
                empty.append(e_copy)
            elif b == 2:
                e_copy = e + "7"
                empty.append(e_copy)
    list1 = empty[:]
    # initial + 1 がn回目のループ
    if initial + 1 >= time:
        return list1
    else:
        return rec(list1, initial + 1, time)


l1 = [""]
result = [""]
for i in range(1, len(N) + 1):
    result += rec(l1, 0, i)
result = [int(e) for e in result if e.count("3") * e.count("5") * e.count("7") >= 1]
# result = list(set(result))
count = 0
for e in result:
    if int(N) < e:
        break
    count += 1
print(count)

+from collections import Counter + -result = rec(l1, 0, 3) -for i in range(len(N) - 3): -    result += rec(result, 0, 1) +result = [""] +for i in range(1, len(N) + 1): +    result += rec(l1, 0, i) -result = list(set(result)) -result.sort() +# result = list(set(result))