def sigm(nk):

    s=3**3*(3**(nk-2)-1)/(3-1)

    s=s-3*2**3*(2**(nk-2)-1)/(2-1)

    s=s+(nk-2)*3

    return int(s)

    

n=int(eval(input()))



if n<357:

    print((0))

else:

    x0=[357,375,537,573,735,753]

    x1=[3,5,7]

    m=0

    nk=len(str(n))

    if nk==3:

        for j in range(6):

            x=x0[j] 

#            print(x)

            if x<=n:

                m=m+1

    else:

        m=sigm(nk-1)

        for i in range(3**nk):

            ii=i

            x=0

            for j in range(nk):

                iii=ii//3

                ir=ii-iii*3

                ii=(ii-ir)//3

                x=x+int(x1[ir])*10**j

            xstr=str(x)

            if xstr.find("3")>=0 and xstr.find("5")>=0 and xstr.find("7")>=0 and n>=x:

                m=m+1                 

    print(m)



import itertools



n=int(eval(input()))



kn=len(str(n))



icnt=0

for kkn in range(3,kn+1):

    for i in itertools.product([3,5,7], repeat=kkn):

        if (3 in i) and (5 in i) and (7 in i):

            ni=0

            for ii in i:

                ni=ni*10+ii

#            print("1:",i,ni)

            if ni<=n:

                icnt+=1    

print(icnt)

def sigm(nk):
    s = 3**3 * (3 ** (nk - 2) - 1) / (3 - 1)
    s = s - 3 * 2**3 * (2 ** (nk - 2) - 1) / (2 - 1)
    s = s + (nk - 2) * 3
    return int(s)


n = int(eval(input()))
if n < 357:
    print((0))
else:
    x0 = [357, 375, 537, 573, 735, 753]
    x1 = [3, 5, 7]
    m = 0
    nk = len(str(n))
    if nk == 3:
        for j in range(6):
            x = x0[j]
            #            print(x)
            if x <= n:
                m = m + 1
    else:
        m = sigm(nk - 1)
        for i in range(3**nk):
            ii = i
            x = 0
            for j in range(nk):
                iii = ii // 3
                ir = ii - iii * 3
                ii = (ii - ir) // 3
                x = x + int(x1[ir]) * 10**j
            xstr = str(x)
            if (
                xstr.find("3") >= 0
                and xstr.find("5") >= 0
                and xstr.find("7") >= 0
                and n >= x
            ):
                m = m + 1
    print(m)

import itertools

n = int(eval(input()))
kn = len(str(n))
icnt = 0
for kkn in range(3, kn + 1):
    for i in itertools.product([3, 5, 7], repeat=kkn):
        if (3 in i) and (5 in i) and (7 in i):
            ni = 0
            for ii in i:
                ni = ni * 10 + ii
            #            print("1:",i,ni)
            if ni <= n:
                icnt += 1
print(icnt)

-def sigm(nk): -    s = 3**3 * (3 ** (nk - 2) - 1) / (3 - 1) -    s = s - 3 * 2**3 * (2 ** (nk - 2) - 1) / (2 - 1) -    s = s + (nk - 2) * 3 -    return int(s) - +import itertools -if n < 357: -    print((0)) -else: -    x0 = [357, 375, 537, 573, 735, 753] -    x1 = [3, 5, 7] -    m = 0 -    nk = len(str(n)) -    if nk == 3: -        for j in range(6): -            x = x0[j] -            #            print(x) -            if x <= n: -                m = m + 1 -    else: -        m = sigm(nk - 1) -        for i in range(3**nk): -            ii = i -            x = 0 -            for j in range(nk): -                iii = ii // 3 -                ir = ii - iii * 3 -                ii = (ii - ir) // 3 -                x = x + int(x1[ir]) * 10**j -            xstr = str(x) -            if ( -                xstr.find("3") >= 0 -                and xstr.find("5") >= 0 -                and xstr.find("7") >= 0 -                and n >= x -            ): -                m = m + 1 -    print(m) +kn = len(str(n)) +icnt = 0 +for kkn in range(3, kn + 1): +    for i in itertools.product([3, 5, 7], repeat=kkn): +        if (3 in i) and (5 in i) and (7 in i): +            ni = 0 +            for ii in i: +                ni = ni * 10 + ii +            #            print("1:",i,ni) +            if ni <= n: +                icnt += 1 +print(icnt)