from collections import Counter

N = int(eval(input()))



def change_to_num(ls):

    ls = list(map(str, ls))

    strnum = ''.join(ls)

    return int(strnum)

def dfs(num_ls):

    '''

    引数のnum_ls以降の753numの総数を返す

    '''

    if change_to_num(num_ls) > N:

        return 0

    

    tmp = 0

    # 引数のnum_lsは753か？

    c = Counter(num_ls)

    is753 = True

    for num in [7,5,3]:

        if c[num] == 0:

            is753 = False

    if is753:

        tmp += 1

    

    # 次の状態の753総数を足す

    for num in [7,5,3]:

        num_ls.append(num)

        tmp += dfs(num_ls)

        num_ls.pop()

    return tmp

print((dfs([0])))





    
from collections import Counter

n = int(eval(input()))

ans = 0

def dfs(A):

    if A and int(A) > n:

        return

    if len(A) >= 3:

        c = Counter(A)

        is753 = True

        for i in ['7','5','3']:

            if c[i] < 1:

                is753 = False

        if is753:

            global ans 

            ans += 1

    for nex in ['7','5','3']:

        A += nex

        dfs(A)

        A = A[:-1]

dfs('')

print(ans)
from collections import Counter

N = int(eval(input()))


def change_to_num(ls):
    ls = list(map(str, ls))
    strnum = "".join(ls)
    return int(strnum)


def dfs(num_ls):
    """
    引数のnum_ls以降の753numの総数を返す
    """
    if change_to_num(num_ls) > N:
        return 0
    tmp = 0
    # 引数のnum_lsは753か？
    c = Counter(num_ls)
    is753 = True
    for num in [7, 5, 3]:
        if c[num] == 0:
            is753 = False
    if is753:
        tmp += 1
    # 次の状態の753総数を足す
    for num in [7, 5, 3]:
        num_ls.append(num)
        tmp += dfs(num_ls)
        num_ls.pop()
    return tmp


print((dfs([0])))

from collections import Counter

n = int(eval(input()))
ans = 0


def dfs(A):
    if A and int(A) > n:
        return
    if len(A) >= 3:
        c = Counter(A)
        is753 = True
        for i in ["7", "5", "3"]:
            if c[i] < 1:
                is753 = False
        if is753:
            global ans
            ans += 1
    for nex in ["7", "5", "3"]:
        A += nex
        dfs(A)
        A = A[:-1]


dfs("")
print(ans)

-N = int(eval(input())) +n = int(eval(input())) +ans = 0 -def change_to_num(ls): -    ls = list(map(str, ls)) -    strnum = "".join(ls) -    return int(strnum) +def dfs(A): +    if A and int(A) > n: +        return +    if len(A) >= 3: +        c = Counter(A) +        is753 = True +        for i in ["7", "5", "3"]: +            if c[i] < 1: +                is753 = False +        if is753: +            global ans +            ans += 1 +    for nex in ["7", "5", "3"]: +        A += nex +        dfs(A) +        A = A[:-1] -def dfs(num_ls): -    """ -    引数のnum_ls以降の753numの総数を返す -    """ -    if change_to_num(num_ls) > N: -        return 0 -    tmp = 0 -    # 引数のnum_lsは753か？ -    c = Counter(num_ls) -    is753 = True -    for num in [7, 5, 3]: -        if c[num] == 0: -            is753 = False -    if is753: -        tmp += 1 -    # 次の状態の753総数を足す -    for num in [7, 5, 3]: -        num_ls.append(num) -        tmp += dfs(num_ls) -        num_ls.pop() -    return tmp - - -print((dfs([0]))) +dfs("") +print(ans)