import itertools

N = int(eval(input()))

ans = 0



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

  for ptn in itertools.product((3, 5, 7), repeat=i):

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

        continue

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

    if a <= N:

      ans +=1



print(ans)
import itertools

N = int(eval(input()))

ans = 0

for i in range(1, 10):

  for x in itertools.product("753", repeat=i):

    s= ''.join(x)

    if int(s) > N: continue

    if '3' not in s: continue

    if '5' not in s: continue

    if '7' not in s: continue

    ans += 1

print(ans)
import itertools

N = int(eval(input()))
ans = 0
for i in range(3, len(str(N)) + 1):
    for ptn in itertools.product((3, 5, 7), repeat=i):
        if (3 not in ptn) or (5 not in ptn) or (7 not in ptn):
            continue
        a = int("".join(list(map(str, ptn))))
        if a <= N:
            ans += 1
print(ans)

import itertools

N = int(eval(input()))
ans = 0
for i in range(1, 10):
    for x in itertools.product("753", repeat=i):
        s = "".join(x)
        if int(s) > N:
            continue
        if "3" not in s:
            continue
        if "5" not in s:
            continue
        if "7" not in s:
            continue
        ans += 1
print(ans)

-for i in range(3, len(str(N)) + 1): -    for ptn in itertools.product((3, 5, 7), repeat=i): -        if (3 not in ptn) or (5 not in ptn) or (7 not in ptn): +for i in range(1, 10): +    for x in itertools.product("753", repeat=i): +        s = "".join(x) +        if int(s) > N: -        a = int("".join(list(map(str, ptn)))) -        if a <= N: -            ans += 1 +        if "3" not in s: +            continue +        if "5" not in s: +            continue +        if "7" not in s: +            continue +        ans += 1