import sys

sys.setrecursionlimit(10 ** 5)



N = int(eval(input()))



def check(p):

  return ("3" in p and "5" in p and "7" in p)

  

cnt = 0

def dfs(n):

  if int(n) > N:

    return

  global cnt

  if check(n):

    cnt += 1

  for c in ("3","5","7"):

    dfs(n + c)



dfs("0")

print(cnt)
N = eval(input())

digit = len(N)



N = int(N)



import itertools



ans = 0

for i in range(1, digit + 1):

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

    if int("".join(prod)) <= N and len(set(prod)) == 3:

      ans += 1



print(ans)
import sys

sys.setrecursionlimit(10**5)
N = int(eval(input()))


def check(p):
    return "3" in p and "5" in p and "7" in p


cnt = 0


def dfs(n):
    if int(n) > N:
        return
    global cnt
    if check(n):
        cnt += 1
    for c in ("3", "5", "7"):
        dfs(n + c)


dfs("0")
print(cnt)

N = eval(input())
digit = len(N)
N = int(N)
import itertools

ans = 0
for i in range(1, digit + 1):
    for prod in itertools.product(("3", "5", "7"), repeat=i):
        if int("".join(prod)) <= N and len(set(prod)) == 3:
            ans += 1
print(ans)

-import sys +N = eval(input()) +digit = len(N) +N = int(N) +import itertools -sys.setrecursionlimit(10**5) -N = int(eval(input())) - - -def check(p): -    return "3" in p and "5" in p and "7" in p - - -cnt = 0 - - -def dfs(n): -    if int(n) > N: -        return -    global cnt -    if check(n): -        cnt += 1 -    for c in ("3", "5", "7"): -        dfs(n + c) - - -dfs("0") -print(cnt) +ans = 0 +for i in range(1, digit + 1): +    for prod in itertools.product(("3", "5", "7"), repeat=i): +        if int("".join(prod)) <= N and len(set(prod)) == 3: +            ans += 1 +print(ans)