def function(n):

    digit=len(str(n))

    N=str(n)

    if digit<3:

        return 0

    else:

        k=int(N[0])

        m=int(N[1])

        if k<3:

            return function(10**(digit-1)-1)

        elif k==3 and m>0:

            return function(10**(digit-1)-1)+function(n%(10**(digit-1)))-function(10**(digit-2))+subfunction(5,7,n%(10**(digit-1)))

        elif k==3 and m==0:

            return function(10**(digit-1)-1)

        elif k==4:

            return function(4*(10**(digit-1))-1)

        elif k==5 and m>0:

            return function(4*(10**(digit-1))-1)+function(n%(10**(digit-1)))-function(10**(digit-2))+subfunction(3,7,n%(10**(digit-1)))

        elif k==5 and m==0:

            return function(4*(10**(digit-1))-1)

        elif k==6:

            return function(6*(10**(digit-1))-1)

        elif k==7 and m>0:

            return function(6*(10**(digit-1))-1)+function(n%(10**(digit-1)))-function(10**(digit-2))+subfunction(3,5,n%(10**(digit-1)))

        elif k==7 and m==0:

            return function(6*(10**(digit-1))-1)

        else:

            return function(8*(10**(digit-1))-1)



def subfunction(a,b,n):

    digit=len(str(n))

    N=str(n)

    k=int(N[0])

    if digit<2:

        return 0

    else:

        if k<a:

            return 0

        elif k==a:

            if n%(10**(digit-1))<b*(10**(digit-1)-1)//9:

                s=0

            else:

                s=1

            return subfunction(a,b,n%(10**(digit-1)))+s

        elif a<k<b:

            return subfunction(a,b,(a+1)*(10**(digit-1))-1)

        elif k==b:

            if n%(10**(digit-1))<a*(10**(digit-1)-1)//9:

                s=0

            else:

                s=1

            return subfunction(a,b,(a+1)*(10**(digit-1))-1)+subfunction(a,b,n%(10**(digit-1)))+s

        else:

            return subfunction(a,b,(b+1)*(10**(digit-1))-1)



N=int(eval(input()))

print((function(N)))
import heapq



N=int(eval(input()))

count=0

que=[3,5,7]

heapq.heapify(que)

ans=[]

while True:

    x=heapq.heappop(que)

    if N>=x:

        count+=1

        ans.append(x)

    else:

        break

    heapq.heappush(que,10*x+3)

    heapq.heappush(que,10*x+5)

    heapq.heappush(que,10*x+7)



count=0

check=["3","5","7"]

for i in ans:

    for j in check:

        if str(i).count(j)==0:

            break

    else:

        count+=1



print(count)
def function(n):
    digit = len(str(n))
    N = str(n)
    if digit < 3:
        return 0
    else:
        k = int(N[0])
        m = int(N[1])
        if k < 3:
            return function(10 ** (digit - 1) - 1)
        elif k == 3 and m > 0:
            return (
                function(10 ** (digit - 1) - 1)
                + function(n % (10 ** (digit - 1)))
                - function(10 ** (digit - 2))
                + subfunction(5, 7, n % (10 ** (digit - 1)))
            )
        elif k == 3 and m == 0:
            return function(10 ** (digit - 1) - 1)
        elif k == 4:
            return function(4 * (10 ** (digit - 1)) - 1)
        elif k == 5 and m > 0:
            return (
                function(4 * (10 ** (digit - 1)) - 1)
                + function(n % (10 ** (digit - 1)))
                - function(10 ** (digit - 2))
                + subfunction(3, 7, n % (10 ** (digit - 1)))
            )
        elif k == 5 and m == 0:
            return function(4 * (10 ** (digit - 1)) - 1)
        elif k == 6:
            return function(6 * (10 ** (digit - 1)) - 1)
        elif k == 7 and m > 0:
            return (
                function(6 * (10 ** (digit - 1)) - 1)
                + function(n % (10 ** (digit - 1)))
                - function(10 ** (digit - 2))
                + subfunction(3, 5, n % (10 ** (digit - 1)))
            )
        elif k == 7 and m == 0:
            return function(6 * (10 ** (digit - 1)) - 1)
        else:
            return function(8 * (10 ** (digit - 1)) - 1)


def subfunction(a, b, n):
    digit = len(str(n))
    N = str(n)
    k = int(N[0])
    if digit < 2:
        return 0
    else:
        if k < a:
            return 0
        elif k == a:
            if n % (10 ** (digit - 1)) < b * (10 ** (digit - 1) - 1) // 9:
                s = 0
            else:
                s = 1
            return subfunction(a, b, n % (10 ** (digit - 1))) + s
        elif a < k < b:
            return subfunction(a, b, (a + 1) * (10 ** (digit - 1)) - 1)
        elif k == b:
            if n % (10 ** (digit - 1)) < a * (10 ** (digit - 1) - 1) // 9:
                s = 0
            else:
                s = 1
            return (
                subfunction(a, b, (a + 1) * (10 ** (digit - 1)) - 1)
                + subfunction(a, b, n % (10 ** (digit - 1)))
                + s
            )
        else:
            return subfunction(a, b, (b + 1) * (10 ** (digit - 1)) - 1)


N = int(eval(input()))
print((function(N)))

import heapq

N = int(eval(input()))
count = 0
que = [3, 5, 7]
heapq.heapify(que)
ans = []
while True:
    x = heapq.heappop(que)
    if N >= x:
        count += 1
        ans.append(x)
    else:
        break
    heapq.heappush(que, 10 * x + 3)
    heapq.heappush(que, 10 * x + 5)
    heapq.heappush(que, 10 * x + 7)
count = 0
check = ["3", "5", "7"]
for i in ans:
    for j in check:
        if str(i).count(j) == 0:
            break
    else:
        count += 1
print(count)

-def function(n): -    digit = len(str(n)) -    N = str(n) -    if digit < 3: -        return 0 -    else: -        k = int(N[0]) -        m = int(N[1]) -        if k < 3: -            return function(10 ** (digit - 1) - 1) -        elif k == 3 and m > 0: -            return ( -                function(10 ** (digit - 1) - 1) -                + function(n % (10 ** (digit - 1))) -                - function(10 ** (digit - 2)) -                + subfunction(5, 7, n % (10 ** (digit - 1))) -            ) -        elif k == 3 and m == 0: -            return function(10 ** (digit - 1) - 1) -        elif k == 4: -            return function(4 * (10 ** (digit - 1)) - 1) -        elif k == 5 and m > 0: -            return ( -                function(4 * (10 ** (digit - 1)) - 1) -                + function(n % (10 ** (digit - 1))) -                - function(10 ** (digit - 2)) -                + subfunction(3, 7, n % (10 ** (digit - 1))) -            ) -        elif k == 5 and m == 0: -            return function(4 * (10 ** (digit - 1)) - 1) -        elif k == 6: -            return function(6 * (10 ** (digit - 1)) - 1) -        elif k == 7 and m > 0: -            return ( -                function(6 * (10 ** (digit - 1)) - 1) -                + function(n % (10 ** (digit - 1))) -                - function(10 ** (digit - 2)) -                + subfunction(3, 5, n % (10 ** (digit - 1))) -            ) -        elif k == 7 and m == 0: -            return function(6 * (10 ** (digit - 1)) - 1) -        else: -            return function(8 * (10 ** (digit - 1)) - 1) - - -def subfunction(a, b, n): -    digit = len(str(n)) -    N = str(n) -    k = int(N[0]) -    if digit < 2: -        return 0 -    else: -        if k < a: -            return 0 -        elif k == a: -            if n % (10 ** (digit - 1)) < b * (10 ** (digit - 1) - 1) // 9: -                s = 0 -            else: -                s = 1 -            return subfunction(a, b, n % (10 ** (digit - 1))) + s -        elif a < k < b: -            return subfunction(a, b, (a + 1) * (10 ** (digit - 1)) - 1) -        elif k == b: -            if n % (10 ** (digit - 1)) < a * (10 ** (digit - 1) - 1) // 9: -                s = 0 -            else: -                s = 1 -            return ( -                subfunction(a, b, (a + 1) * (10 ** (digit - 1)) - 1) -                + subfunction(a, b, n % (10 ** (digit - 1))) -                + s -            ) -        else: -            return subfunction(a, b, (b + 1) * (10 ** (digit - 1)) - 1) - +import heapq -print((function(N))) +count = 0 +que = [3, 5, 7] +heapq.heapify(que) +ans = [] +while True: +    x = heapq.heappop(que) +    if N >= x: +        count += 1 +        ans.append(x) +    else: +        break +    heapq.heappush(que, 10 * x + 3) +    heapq.heappush(que, 10 * x + 5) +    heapq.heappush(que, 10 * x + 7) +count = 0 +check = ["3", "5", "7"] +for i in ans: +    for j in check: +        if str(i).count(j) == 0: +            break +    else: +        count += 1 +print(count)