N = int(eval(input()))

def n_ary(l,d): # リストl中の文字でd桁までを全列挙(sorted)

    if d == 1:

        return(l)

    n = len(l)

    ll = n_ary(l,d-1)

    lll = []

    for i in l:

        for j in ll[n*(n**(d-2)-1)//(n-1):]:

            lll.append(i+j)

    return(ll+lll)

possible = [i.replace('0','3').replace('1', '5').replace('2','7') for i in n_ary(['0','1','2'],9)] # 制約が10^9なので9

print((len([int(i) for i in possible if ('3' in i and '5' in i and '7' in i and int(i) <= N)])))

N = int(eval(input()))

def n_ary(l,d): # リストl中の文字でd桁までを全列挙(sorted)

    if d == 1:

        return(l)

    n = len(l)

    ll = n_ary(l,d-1)

    lll = []

    for i in l:

        for j in ll[n*(n**(d-2)-1)//(n-1):]:

            lll.append(i+j)

    return(ll+lll)

possible = [i for i in n_ary(['3','5','7'],9)] # 制約が10**9なので9

print((len([int(i) for i in possible if ('3' in i and '5' in i and '7' in i and int(i) <= N)])))
N = int(eval(input()))


def n_ary(l, d):  # リストl中の文字でd桁までを全列挙(sorted)
    if d == 1:
        return l
    n = len(l)
    ll = n_ary(l, d - 1)
    lll = []
    for i in l:
        for j in ll[n * (n ** (d - 2) - 1) // (n - 1) :]:
            lll.append(i + j)
    return ll + lll


possible = [
    i.replace("0", "3").replace("1", "5").replace("2", "7")
    for i in n_ary(["0", "1", "2"], 9)
]  # 制約が10^9なので9
print(
    (
        len(
            [
                int(i)
                for i in possible
                if ("3" in i and "5" in i and "7" in i and int(i) <= N)
            ]
        )
    )
)

N = int(eval(input()))


def n_ary(l, d):  # リストl中の文字でd桁までを全列挙(sorted)
    if d == 1:
        return l
    n = len(l)
    ll = n_ary(l, d - 1)
    lll = []
    for i in l:
        for j in ll[n * (n ** (d - 2) - 1) // (n - 1) :]:
            lll.append(i + j)
    return ll + lll


possible = [i for i in n_ary(["3", "5", "7"], 9)]  # 制約が10**9なので9
print(
    (
        len(
            [
                int(i)
                for i in possible
                if ("3" in i and "5" in i and "7" in i and int(i) <= N)
            ]
        )
    )
)

-possible = [ -    i.replace("0", "3").replace("1", "5").replace("2", "7") -    for i in n_ary(["0", "1", "2"], 9) -]  # 制約が10^9なので9 +possible = [i for i in n_ary(["3", "5", "7"], 9)]  # 制約が10**9なので9