N = int(eval(input()))



def dfs(s):

    if int(s) > N:

        return 0

    ret = 1 if all(s.count(c) for c in "357") else 0

 

    for c in "357":

        ret += dfs(s+c)

    return ret

 

print((dfs("0")))
from collections import deque

n = int(eval(input()))



li = [3, 5, 7]



def dfs():

  stack = deque()

  for i in li:

    stack.append(i)

  while stack:

    q = stack.popleft()

    if all(str(l) in str(q) for l in li):

      ans.append(q)

    for k in li:

      if q * 10 + k <= n:

        stack.append(q * 10 + k)

          

ans = []

dfs()

print((len(ans)))
N = int(eval(input()))


def dfs(s):
    if int(s) > N:
        return 0
    ret = 1 if all(s.count(c) for c in "357") else 0
    for c in "357":
        ret += dfs(s + c)
    return ret


print((dfs("0")))

from collections import deque

n = int(eval(input()))
li = [3, 5, 7]


def dfs():
    stack = deque()
    for i in li:
        stack.append(i)
    while stack:
        q = stack.popleft()
        if all(str(l) in str(q) for l in li):
            ans.append(q)
        for k in li:
            if q * 10 + k <= n:
                stack.append(q * 10 + k)


ans = []
dfs()
print((len(ans)))

-N = int(eval(input())) +from collections import deque + +n = int(eval(input())) +li = [3, 5, 7] -def dfs(s): -    if int(s) > N: -        return 0 -    ret = 1 if all(s.count(c) for c in "357") else 0 -    for c in "357": -        ret += dfs(s + c) -    return ret +def dfs(): +    stack = deque() +    for i in li: +        stack.append(i) +    while stack: +        q = stack.popleft() +        if all(str(l) in str(q) for l in li): +            ans.append(q) +        for k in li: +            if q * 10 + k <= n: +                stack.append(q * 10 + k) -print((dfs("0"))) +ans = [] +dfs() +print((len(ans)))