def number_lst(x): #x桁での753
    lst = ['3', '5', '7']
    flag = False
    while True:
        for i in range(len(lst)):
            number = lst[i]
            if len(number)==x:
                flag = True
                break

            y1 = number + '3'
            y2 = number + '5'
            y3 = number + '7'
            lst.append(y1)
            lst.append(y2)
            lst.append(y3)

        if flag:
            break

        z_lst = []
        for i in range(len(lst)):
            z_lst.append(len(lst[i]))
        min_z = min(z_lst)

        new_lst = []
        for i in range(len(lst)):
            if len(lst[i])!=min_z:
               new_lst.append(lst[i])
        lst = new_lst.copy()

    new_lst = []
    for i in range(len(lst)):
        number = lst[i]
        tmp_lst = [number.count('3'), number.count('5'), number.count('7')]
        if 0 not in tmp_lst:
            new_lst.append(number)

    return new_lst

n = str(input())
digit = len(n)

if digit<3:
    answer = 0
else:
    x = digit-1
    tmp1 = (3**(x-1) - 2**x + 1) * 3 #一個くらいを消去した時の個数
    tmp2 = 0

    lst_1 = number_lst(digit).copy()

    for i in range(len(lst_1)):
        number = int(lst_1[i])

        if number<=int(n):
            tmp2 += 1

    answer = tmp1 + tmp2

print(answer)