N = int(eval(input()))

T = ("3","5","7")



from collections import deque

que = deque(list(T))



ans = 0

while que:

  num = que.pop()

  if int(num) > N:

    continue

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

    ans += 1

  for t in T:

    que.append(num + t)



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

T = ("3","5","7")



def dfs(x):

  if x != "" and int(x) > N:

    return 0

  res = 0

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

    res = 1

  for t in T:

    res += dfs(x + t)

  return res

  

print((dfs("")))
N = int(eval(input()))
T = ("3", "5", "7")
from collections import deque

que = deque(list(T))
ans = 0
while que:
    num = que.pop()
    if int(num) > N:
        continue
    if len(set(num)) == 3:
        ans += 1
    for t in T:
        que.append(num + t)
print(ans)

N = int(eval(input()))
T = ("3", "5", "7")


def dfs(x):
    if x != "" and int(x) > N:
        return 0
    res = 0
    if len(set(x)) == 3:
        res = 1
    for t in T:
        res += dfs(x + t)
    return res


print((dfs("")))

-from collections import deque -que = deque(list(T)) -ans = 0 -while que: -    num = que.pop() -    if int(num) > N: -        continue -    if len(set(num)) == 3: -        ans += 1 + +def dfs(x): +    if x != "" and int(x) > N: +        return 0 +    res = 0 +    if len(set(x)) == 3: +        res = 1 -        que.append(num + t) -print(ans) +        res += dfs(x + t) +    return res + + +print((dfs("")))