N = eval(input())

def rec(list1,list2,initial,time):

    for e in list1:

        for b in [0,1,2,3]:

            if b == 0:

                e_copy = e

                list2.append(e_copy)

            elif b == 1:

                e_copy = e + "3"

                list2.append(e_copy)

            elif b == 2:

                e_copy = e + "5"

                list2.append(e_copy)

            elif b == 3:

                e_copy = e + "7"

                list2.append(e_copy)

    list1.clear()

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

    if initial + 1 >= time :

        return list2

    else:

        return rec(list2,list1,initial + 1, time)

l1 = [""]

l2 = []

result = rec(l1,l2,0,len(N))

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)
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)
N = eval(input())


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


l1 = [""]
l2 = []
result = rec(l1, l2, 0, len(N))
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)

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)

-def rec(list1, list2, initial, time): +def rec(list1, initial, time): +    empty = [] -        for b in [0, 1, 2, 3]: +        for b in [0, 1, 2]: -                e_copy = e -                list2.append(e_copy) +                e_copy = e + "3" +                empty.append(e_copy) -                e_copy = e + "3" -                list2.append(e_copy) +                e_copy = e + "5" +                empty.append(e_copy) -                e_copy = e + "5" -                list2.append(e_copy) -            elif b == 3: -                list2.append(e_copy) -    list1.clear() +                empty.append(e_copy) +    list1 = empty[:] -        return list2 +        return list1 -        return rec(list2, list1, initial + 1, time) +        return rec(list1, initial + 1, time) -l2 = [] -result = rec(l1, l2, 0, len(N)) +result = rec(l1, 0, 3) +for i in range(len(N) - 3): +    result += rec(result, 0, 1)