import itertools



N = eval(input())

N1 = int(N)

N2 = len(N)



num753_comb = []

for i in range(N2):

  num753_comb.append([0,3,5,7])

All_comb = list(itertools.product(*num753_comb))



count = 0

for i in range(len(All_comb)):

 tmp = list(All_comb[i])

 tmp_num = 0

 judge0,judge3,judge5,judge7 = 0,0,0,0



 for j in range(N2):

   tmp_num += tmp[j]*(10**(N2-1-j))   

   if((tmp_num > 0)and(tmp[j] == 0)): judge0 += 1

   elif(tmp[j] == 3): judge3 += 1

   elif(tmp[j] == 5): judge5 += 1

   elif(tmp[j] == 7): judge7 += 1

   

 if(tmp_num <= N1):

   if((judge3>=1)and(judge5>=1)and(judge7>=1)and(judge0 == 0)):

      count += 1     

print(count)

    
import itertools

N_ = eval(input())

N = int(N_) 

n = len(list(N_)) #Nの桁数



#(方針) N<=10**9 だと3,5,7のみを使ってできる数は多くても3**9=2*10**4通りなので全探索

A = ['3','5','7']



ans = 0

if(n >= 3): #桁数が3以上なら

 for i in range(3,n+1):

  Comb = list(itertools.product(A, repeat=i)) #重複組み合わせ

  

  for j in range(len(Comb)):

   tmp = list(Comb[j])

   #print(tmp) #########

   judge = 1 #条件を満たす数: 1,満たさない数: 0

    

   #選んだ数がN以下かの判定

   tmp_num = ''

   for k in range(len(tmp)):

     tmp_num += tmp[k]

   tmp_num = int(tmp_num)

   if(tmp_num > N):

      judge = 0

   #print(tmp_num) #########

    

   #選んだ数が3,5,7を1回以上含むかの判定

   three,five,seven = 0,0,0

   for k in range(len(tmp)):

     if(tmp[k]=='3'): three += 1

     elif(tmp[k]=='5'): five += 1

     elif(tmp[k]=='7'): seven += 1

   if(three*five*seven == 0): #どれか1つでも0なら積は0

    judge = 0

   

   #条件をみたすならカウント+1 

   if(judge == 1): ans += 1



print(ans)
import itertools

N = eval(input())
N1 = int(N)
N2 = len(N)
num753_comb = []
for i in range(N2):
    num753_comb.append([0, 3, 5, 7])
All_comb = list(itertools.product(*num753_comb))
count = 0
for i in range(len(All_comb)):
    tmp = list(All_comb[i])
    tmp_num = 0
    judge0, judge3, judge5, judge7 = 0, 0, 0, 0
    for j in range(N2):
        tmp_num += tmp[j] * (10 ** (N2 - 1 - j))
        if (tmp_num > 0) and (tmp[j] == 0):
            judge0 += 1
        elif tmp[j] == 3:
            judge3 += 1
        elif tmp[j] == 5:
            judge5 += 1
        elif tmp[j] == 7:
            judge7 += 1
    if tmp_num <= N1:
        if (judge3 >= 1) and (judge5 >= 1) and (judge7 >= 1) and (judge0 == 0):
            count += 1
print(count)

import itertools

N_ = eval(input())
N = int(N_)
n = len(list(N_))  # Nの桁数
# (方針) N<=10**9 だと3,5,7のみを使ってできる数は多くても3**9=2*10**4通りなので全探索
A = ["3", "5", "7"]
ans = 0
if n >= 3:  # 桁数が3以上なら
    for i in range(3, n + 1):
        Comb = list(itertools.product(A, repeat=i))  # 重複組み合わせ
        for j in range(len(Comb)):
            tmp = list(Comb[j])
            # print(tmp) #########
            judge = 1  # 条件を満たす数: 1,満たさない数: 0
            # 選んだ数がN以下かの判定
            tmp_num = ""
            for k in range(len(tmp)):
                tmp_num += tmp[k]
            tmp_num = int(tmp_num)
            if tmp_num > N:
                judge = 0
            # print(tmp_num) #########
            # 選んだ数が3,5,7を1回以上含むかの判定
            three, five, seven = 0, 0, 0
            for k in range(len(tmp)):
                if tmp[k] == "3":
                    three += 1
                elif tmp[k] == "5":
                    five += 1
                elif tmp[k] == "7":
                    seven += 1
            if three * five * seven == 0:  # どれか1つでも0なら積は0
                judge = 0
            # 条件をみたすならカウント+1
            if judge == 1:
                ans += 1
print(ans)

-N = eval(input()) -N1 = int(N) -N2 = len(N) -num753_comb = [] -for i in range(N2): -    num753_comb.append([0, 3, 5, 7]) -All_comb = list(itertools.product(*num753_comb)) -count = 0 -for i in range(len(All_comb)): -    tmp = list(All_comb[i]) -    tmp_num = 0 -    judge0, judge3, judge5, judge7 = 0, 0, 0, 0 -    for j in range(N2): -        tmp_num += tmp[j] * (10 ** (N2 - 1 - j)) -        if (tmp_num > 0) and (tmp[j] == 0): -            judge0 += 1 -        elif tmp[j] == 3: -            judge3 += 1 -        elif tmp[j] == 5: -            judge5 += 1 -        elif tmp[j] == 7: -            judge7 += 1 -    if tmp_num <= N1: -        if (judge3 >= 1) and (judge5 >= 1) and (judge7 >= 1) and (judge0 == 0): -            count += 1 -print(count) +N_ = eval(input()) +N = int(N_) +n = len(list(N_))  # Nの桁数 +# (方針) N<=10**9 だと3,5,7のみを使ってできる数は多くても3**9=2*10**4通りなので全探索 +A = ["3", "5", "7"] +ans = 0 +if n >= 3:  # 桁数が3以上なら +    for i in range(3, n + 1): +        Comb = list(itertools.product(A, repeat=i))  # 重複組み合わせ +        for j in range(len(Comb)): +            tmp = list(Comb[j]) +            # print(tmp) ######### +            judge = 1  # 条件を満たす数: 1,満たさない数: 0 +            # 選んだ数がN以下かの判定 +            tmp_num = "" +            for k in range(len(tmp)): +                tmp_num += tmp[k] +            tmp_num = int(tmp_num) +            if tmp_num > N: +                judge = 0 +            # print(tmp_num) ######### +            # 選んだ数が3,5,7を1回以上含むかの判定 +            three, five, seven = 0, 0, 0 +            for k in range(len(tmp)): +                if tmp[k] == "3": +                    three += 1 +                elif tmp[k] == "5": +                    five += 1 +                elif tmp[k] == "7": +                    seven += 1 +            if three * five * seven == 0:  # どれか1つでも0なら積は0 +                judge = 0 +            # 条件をみたすならカウント+1 +            if judge == 1: +                ans += 1 +print(ans)