s = eval(input())

l = len(s)

n = int(s)

ans = 0

import itertools

for li in range(3, l+1):

    for i in itertools.product([7, 5, 3], repeat=li):

        num = int(''.join(map(str, i)))

        if num > n:

            continue

        if len(set(i)) == 3:

            ans += 1

print(ans)
s = eval(input())

l = len(s)

n = int(s)

ans = 0

import itertools

for li in range(3, l+1):

    for i in itertools.product([7, 5, 3], repeat=li):

        if len(set(i)) != 3:

            continue

        num = int(''.join(map(str, i)))

        if num <= n:

            ans += 1



print(ans)
s = eval(input())
l = len(s)
n = int(s)
ans = 0
import itertools

for li in range(3, l + 1):
    for i in itertools.product([7, 5, 3], repeat=li):
        num = int("".join(map(str, i)))
        if num > n:
            continue
        if len(set(i)) == 3:
            ans += 1
print(ans)

s = eval(input())
l = len(s)
n = int(s)
ans = 0
import itertools

for li in range(3, l + 1):
    for i in itertools.product([7, 5, 3], repeat=li):
        if len(set(i)) != 3:
            continue
        num = int("".join(map(str, i)))
        if num <= n:
            ans += 1
print(ans)

+        if len(set(i)) != 3: +            continue -        if num > n: -            continue -        if len(set(i)) == 3: +        if num <= n: