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())

dig = len(N)

N = int(N)



# 全探索

# 3^9 <= 20000

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



def count_num(A,n):

  Comb = itertools.product(A, repeat=n)

  cnt = 0

  for X in Comb:

    X = list(X)

    X_num = int(''.join(X))

    if(X_num <= N):

      j3,j5,j7 = 0,0,0

      for x in X:   

        if(x == '3'): j3 = 1

        elif(x == '5'): j5 = 1

        elif(x == '7'): j7 = 1

      if(j3*j5*j7 == 1):

        cnt += 1

  return cnt      



ans = 0

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

  ans += count_num(A,i)

print(ans)      
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())
dig = len(N)
N = int(N)
# 全探索
# 3^9 <= 20000
A = ["3", "5", "7"]


def count_num(A, n):
    Comb = itertools.product(A, repeat=n)
    cnt = 0
    for X in Comb:
        X = list(X)
        X_num = int("".join(X))
        if X_num <= N:
            j3, j5, j7 = 0, 0, 0
            for x in X:
                if x == "3":
                    j3 = 1
                elif x == "5":
                    j5 = 1
                elif x == "7":
                    j7 = 1
            if j3 * j5 * j7 == 1:
                cnt += 1
    return cnt


ans = 0
for i in range(3, dig + 1):
    ans += count_num(A, i)
print(ans)

-N_ = eval(input()) -N = int(N_) -n = len(list(N_))  # Nの桁数 -# (方針) N<=10**9 だと3,5,7のみを使ってできる数は多くても3**9=2*10**4通りなので全探索 +N = eval(input()) +dig = len(N) +N = int(N) +# 全探索 +# 3^9 <= 20000 + + +def count_num(A, n): +    Comb = itertools.product(A, repeat=n) +    cnt = 0 +    for X in Comb: +        X = list(X) +        X_num = int("".join(X)) +        if X_num <= N: +            j3, j5, j7 = 0, 0, 0 +            for x in X: +                if x == "3": +                    j3 = 1 +                elif x == "5": +                    j5 = 1 +                elif x == "7": +                    j7 = 1 +            if j3 * j5 * j7 == 1: +                cnt += 1 +    return cnt + + -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 +for i in range(3, dig + 1): +    ans += count_num(A, i)