import numpy as np



def count(n,s):

    if s == 0:

        return 3**n - 3*(2**n) + 3

    elif s == 1:

        return 3**n - 2**(n+1) + 1

    elif s == 2:

        return 3**n - 2**n

    else:

        return 3**n



def num753(Nlist, appeared):

    n = len(Nlist)

    if n == 0:

        if appeared == 7:

            return 1

        else:

            return 0

    

    top = Nlist[-1]

    

    ap3 = appeared|1

    s3 = ap3 % 2 + (ap3 % 4)//2 + ap3 // 4

    ap5 = appeared|2

    s5 = ap5 % 2 + (ap5 % 4)//2 + ap5 // 4

    ap7 = appeared|4

    s7 = ap7 % 2 + (ap7 % 4)//2 + ap7 // 4



    if appeared == 0:

        ans = sum([count(i,0) for i in range(3,n)])

    else:

        ans = 0



    if top < 3:

        pass

    elif top == 3:

        ans = ans + num753(Nlist[:-1],ap3)

    elif top == 4:

        ans = ans + count(n-1,s3)

    elif top == 5:

        ans = ans + count(n-1,s3) + num753(Nlist[:-1],ap5)

    elif top == 6:

        ans = ans + count(n-1,s3) + count(n-1,s5)

    elif top == 7:

        ans = ans + count(n-1,s3) + count(n-1,s5) + num753(Nlist[:-1],ap7)

    else: # top == 8,9

        ans = ans + count(n-1,s3) + count(n-1,s5) + count(n-1,s7)

    

    return ans



N = int(eval(input()))

Nlist=[]

while N > 0:

    Nlist.append(N % 10)

    N = N // 10

Nlist = np.array(Nlist,dtype=np.int)



print((num753(Nlist,0)))
import numpy as np



def list753(n):

    if n == 1:

        return np.array([3,5,7],dtype=np.int)

    else:

        prev = list753(n-1)

        return np.concatenate((10*prev+3,10*prev+5,10*prev+7))



def all_list753(n):

    return np.concatenate(tuple([list753(i) for i in range(1,n+1)]))



Nstr = eval(input())

N = int(Nstr)

Nlen = len(Nstr)



candidates = all_list753(Nlen)

ans = 0



for c in candidates:

    if c > N:

        continue

    cstr = str(c)

    if '3' in cstr and '5' in cstr and '7' in cstr:

        ans += 1



print(ans)
import numpy as np


def count(n, s):
    if s == 0:
        return 3**n - 3 * (2**n) + 3
    elif s == 1:
        return 3**n - 2 ** (n + 1) + 1
    elif s == 2:
        return 3**n - 2**n
    else:
        return 3**n


def num753(Nlist, appeared):
    n = len(Nlist)
    if n == 0:
        if appeared == 7:
            return 1
        else:
            return 0
    top = Nlist[-1]
    ap3 = appeared | 1
    s3 = ap3 % 2 + (ap3 % 4) // 2 + ap3 // 4
    ap5 = appeared | 2
    s5 = ap5 % 2 + (ap5 % 4) // 2 + ap5 // 4
    ap7 = appeared | 4
    s7 = ap7 % 2 + (ap7 % 4) // 2 + ap7 // 4
    if appeared == 0:
        ans = sum([count(i, 0) for i in range(3, n)])
    else:
        ans = 0
    if top < 3:
        pass
    elif top == 3:
        ans = ans + num753(Nlist[:-1], ap3)
    elif top == 4:
        ans = ans + count(n - 1, s3)
    elif top == 5:
        ans = ans + count(n - 1, s3) + num753(Nlist[:-1], ap5)
    elif top == 6:
        ans = ans + count(n - 1, s3) + count(n - 1, s5)
    elif top == 7:
        ans = ans + count(n - 1, s3) + count(n - 1, s5) + num753(Nlist[:-1], ap7)
    else:  # top == 8,9
        ans = ans + count(n - 1, s3) + count(n - 1, s5) + count(n - 1, s7)
    return ans


N = int(eval(input()))
Nlist = []
while N > 0:
    Nlist.append(N % 10)
    N = N // 10
Nlist = np.array(Nlist, dtype=np.int)
print((num753(Nlist, 0)))

import numpy as np


def list753(n):
    if n == 1:
        return np.array([3, 5, 7], dtype=np.int)
    else:
        prev = list753(n - 1)
        return np.concatenate((10 * prev + 3, 10 * prev + 5, 10 * prev + 7))


def all_list753(n):
    return np.concatenate(tuple([list753(i) for i in range(1, n + 1)]))


Nstr = eval(input())
N = int(Nstr)
Nlen = len(Nstr)
candidates = all_list753(Nlen)
ans = 0
for c in candidates:
    if c > N:
        continue
    cstr = str(c)
    if "3" in cstr and "5" in cstr and "7" in cstr:
        ans += 1
print(ans)

-def count(n, s): -    if s == 0: -        return 3**n - 3 * (2**n) + 3 -    elif s == 1: -        return 3**n - 2 ** (n + 1) + 1 -    elif s == 2: -        return 3**n - 2**n +def list753(n): +    if n == 1: +        return np.array([3, 5, 7], dtype=np.int) -        return 3**n +        prev = list753(n - 1) +        return np.concatenate((10 * prev + 3, 10 * prev + 5, 10 * prev + 7)) -def num753(Nlist, appeared): -    n = len(Nlist) -    if n == 0: -        if appeared == 7: -            return 1 -        else: -            return 0 -    top = Nlist[-1] -    ap3 = appeared | 1 -    s3 = ap3 % 2 + (ap3 % 4) // 2 + ap3 // 4 -    ap5 = appeared | 2 -    s5 = ap5 % 2 + (ap5 % 4) // 2 + ap5 // 4 -    ap7 = appeared | 4 -    s7 = ap7 % 2 + (ap7 % 4) // 2 + ap7 // 4 -    if appeared == 0: -        ans = sum([count(i, 0) for i in range(3, n)]) -    else: -        ans = 0 -    if top < 3: -        pass -    elif top == 3: -        ans = ans + num753(Nlist[:-1], ap3) -    elif top == 4: -        ans = ans + count(n - 1, s3) -    elif top == 5: -        ans = ans + count(n - 1, s3) + num753(Nlist[:-1], ap5) -    elif top == 6: -        ans = ans + count(n - 1, s3) + count(n - 1, s5) -    elif top == 7: -        ans = ans + count(n - 1, s3) + count(n - 1, s5) + num753(Nlist[:-1], ap7) -    else:  # top == 8,9 -        ans = ans + count(n - 1, s3) + count(n - 1, s5) + count(n - 1, s7) -    return ans +def all_list753(n): +    return np.concatenate(tuple([list753(i) for i in range(1, n + 1)])) -N = int(eval(input())) -Nlist = [] -while N > 0: -    Nlist.append(N % 10) -    N = N // 10 -Nlist = np.array(Nlist, dtype=np.int) -print((num753(Nlist, 0))) +Nstr = eval(input()) +N = int(Nstr) +Nlen = len(Nstr) +candidates = all_list753(Nlen) +ans = 0 +for c in candidates: +    if c > N: +        continue +    cstr = str(c) +    if "3" in cstr and "5" in cstr and "7" in cstr: +        ans += 1 +print(ans)