from collections import deque

N = int(eval(input()))

stack = deque(["0"])

cnt = 0

while len(stack)>0:

    c = stack.pop()

    for s in "357":

        cs = c + s

        # print(cs)

        if int(cs)<=N:

            stack.append(cs)

            if cs.count("3")*cs.count("5")*cs.count("7")>0:

                cnt += 1

print(cnt)
"""

dfsでとき直し114

7,5,3がそれぞれ1回以上現れる



3-3-3

   -5

   -7

 -5-3

   -5

   -7

 -7-3

   -5

   -7

とかそういうヤツ



3 33 35 37 5 

"""



import sys

sys.setrecursionlimit(100000)



cnt = 0

num = "0"

X = int(eval(input()))

def dfs(num,is3,is5,is7):

    # print(num,is3 and is5 and is7)

    global cnt

    if is3 and is5 and is7:

        cnt += 1 

    N = "357"

    for n in N:

        if int(num+n) > X: continue #終了条件

        if n == "3":

            dfs(num+n,True,is5,is7)

        elif n == "5":

            dfs(num+n,is3,True,is7)

        elif n == "7":

            dfs(num+n,is3,is5,True)





dfs("0",0,0,0)

print(cnt)
from collections import deque

N = int(eval(input()))
stack = deque(["0"])
cnt = 0
while len(stack) > 0:
    c = stack.pop()
    for s in "357":
        cs = c + s
        # print(cs)
        if int(cs) <= N:
            stack.append(cs)
            if cs.count("3") * cs.count("5") * cs.count("7") > 0:
                cnt += 1
print(cnt)

"""
dfsでとき直し114
7,5,3がそれぞれ1回以上現れる
3-3-3
   -5
   -7
 -5-3
   -5
   -7
 -7-3
   -5
   -7
とかそういうヤツ
3 33 35 37 5 
"""
import sys

sys.setrecursionlimit(100000)
cnt = 0
num = "0"
X = int(eval(input()))


def dfs(num, is3, is5, is7):
    # print(num,is3 and is5 and is7)
    global cnt
    if is3 and is5 and is7:
        cnt += 1
    N = "357"
    for n in N:
        if int(num + n) > X:
            continue  # 終了条件
        if n == "3":
            dfs(num + n, True, is5, is7)
        elif n == "5":
            dfs(num + n, is3, True, is7)
        elif n == "7":
            dfs(num + n, is3, is5, True)


dfs("0", 0, 0, 0)
print(cnt)

-from collections import deque +""" +dfsでとき直し114 +7,5,3がそれぞれ1回以上現れる +3-3-3 +   -5 +   -7 + -5-3 +   -5 +   -7 + -7-3 +   -5 +   -7 +とかそういうヤツ +3 33 35 37 5 +""" +import sys -N = int(eval(input())) -stack = deque(["0"]) +sys.setrecursionlimit(100000) -while len(stack) > 0: -    c = stack.pop() -    for s in "357": -        cs = c + s -        # print(cs) -        if int(cs) <= N: -            stack.append(cs) -            if cs.count("3") * cs.count("5") * cs.count("7") > 0: -                cnt += 1 +num = "0" +X = int(eval(input())) + + +def dfs(num, is3, is5, is7): +    # print(num,is3 and is5 and is7) +    global cnt +    if is3 and is5 and is7: +        cnt += 1 +    N = "357" +    for n in N: +        if int(num + n) > X: +            continue  # 終了条件 +        if n == "3": +            dfs(num + n, True, is5, is7) +        elif n == "5": +            dfs(num + n, is3, True, is7) +        elif n == "7": +            dfs(num + n, is3, is5, True) + + +dfs("0", 0, 0, 0)