# -*- coding: utf-8 -*-
import math
a = int(input())
c = str(a)
b = 0
"""
if (b >= 357):    
    for i in range(357, a):
"""


keta = int (math.log10(a) + 1)
list = []
if a >= 357:
    count = 0
    for i in range(3, keta):
        c = 1
        b = 3
        for j in range(0, i):
            c *= 3
            b *= 2
        list.append(c - b +3)
    start = pow(10, keta - 1) * 3
    while start - 1 <= a:
        start += 1
        flg3 = 0
        flg5 = 0
        flg7 = 0

        if math.floor(start / (pow(10, keta - 1))) == 4:
            start += pow(10, keta - 1)
        if math.floor(start / (pow(10, keta - 1))) == 6:
            start += pow(10, keta - 1)
        if math.floor(start / (pow(10, keta - 1))) == 8:
            break
 
        for j in range(0, keta):
            if (str(start)[j] == "3"):
                flg3 = 1
            elif (str(start)[j] == "5"):
                flg5 = 1
            elif (str(start)[j] == "7"):
                flg7 = 1
            else:
                break
            if (j == keta - 1 and flg3 == 1 and flg5 == 1 and flg7 == 1):
                count += 1
                
    b = count + sum(list)
print(b)
              

