from collections import deque

n=int(eval(input()))

l=["3","5","7"]

q=deque(["3","5","7"])

l1=["3","5","7"]

count=0

while q:

  a=q.popleft()

  for i in l:

    if int(i+a)<=n:

      q.append(i+a)

      l1.append(i+a)

for i in l1:

  if ("3" in i) and ("5" in i) and ("7" in i):

    count+=1

print(count)
num=int(eval(input()))

def dfs(n):

  if n>num:

    return 0

  else:

    w=str(n)

    if w=="0":

      w=""

    if "3" in w and "7" in w and "5" in w:

      ret=1

    else:

      ret=0

    for i in "357":   

      ret+=dfs(int(i+w))

    return ret

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

n = int(eval(input()))
l = ["3", "5", "7"]
q = deque(["3", "5", "7"])
l1 = ["3", "5", "7"]
count = 0
while q:
    a = q.popleft()
    for i in l:
        if int(i + a) <= n:
            q.append(i + a)
            l1.append(i + a)
for i in l1:
    if ("3" in i) and ("5" in i) and ("7" in i):
        count += 1
print(count)

num = int(eval(input()))


def dfs(n):
    if n > num:
        return 0
    else:
        w = str(n)
        if w == "0":
            w = ""
        if "3" in w and "7" in w and "5" in w:
            ret = 1
        else:
            ret = 0
        for i in "357":
            ret += dfs(int(i + w))
        return ret


print((dfs(0)))

-from collections import deque +num = int(eval(input())) -n = int(eval(input())) -l = ["3", "5", "7"] -q = deque(["3", "5", "7"]) -l1 = ["3", "5", "7"] -count = 0 -while q: -    a = q.popleft() -    for i in l: -        if int(i + a) <= n: -            q.append(i + a) -            l1.append(i + a) -for i in l1: -    if ("3" in i) and ("5" in i) and ("7" in i): -        count += 1 -print(count) + +def dfs(n): +    if n > num: +        return 0 +    else: +        w = str(n) +        if w == "0": +            w = "" +        if "3" in w and "7" in w and "5" in w: +            ret = 1 +        else: +            ret = 0 +        for i in "357": +            ret += dfs(int(i + w)) +        return ret + + +print((dfs(0)))