import sys

import math

import itertools





# \n

def input():

    return sys.stdin.readline().rstrip()





def main():

    N = int(eval(input()))



    A = int(math.log10(N))

    flag=0

    count =0

    for a in range(3,A+2):



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

            digit=0

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





                for s in range(a):

                    digit+=10**(a-s-1)*i[s]

                if digit <=N:

                    count+=1

                else:

                    break

    print(count)





if __name__ == "__main__":

    main()

import sys

import math

import itertools





# \n

def input():

    return sys.stdin.readline().rstrip()





def main():

    list = [[3, 5, 7]]

    N=int(eval(input()))

    for i in range(9):

        new = []

        for j in list[-1]:

            a = 10 * j

            new.append(a + 3)

            new.append(a + 5)

            new.append(a + 7)

        list.append(new)



    pass

    count =0

    for sub in list:

        for j in sub:

            s =str(j)

            if j>N:

                print(count)

                exit()

            if "3" in s and "7" in s and "5" in s:

                count +=1













if __name__ == "__main__":

    main()

import sys
import math
import itertools

# \n
def input():
    return sys.stdin.readline().rstrip()


def main():
    N = int(eval(input()))
    A = int(math.log10(N))
    flag = 0
    count = 0
    for a in range(3, A + 2):
        for i in itertools.product([3, 5, 7], repeat=a):
            digit = 0
            if 3 in i and 5 in i and 7 in i:
                for s in range(a):
                    digit += 10 ** (a - s - 1) * i[s]
                if digit <= N:
                    count += 1
                else:
                    break
    print(count)


if __name__ == "__main__":
    main()

import sys
import math
import itertools

# \n
def input():
    return sys.stdin.readline().rstrip()


def main():
    list = [[3, 5, 7]]
    N = int(eval(input()))
    for i in range(9):
        new = []
        for j in list[-1]:
            a = 10 * j
            new.append(a + 3)
            new.append(a + 5)
            new.append(a + 7)
        list.append(new)
    pass
    count = 0
    for sub in list:
        for j in sub:
            s = str(j)
            if j > N:
                print(count)
                exit()
            if "3" in s and "7" in s and "5" in s:
                count += 1


if __name__ == "__main__":
    main()

+    list = [[3, 5, 7]] -    A = int(math.log10(N)) -    flag = 0 +    for i in range(9): +        new = [] +        for j in list[-1]: +            a = 10 * j +            new.append(a + 3) +            new.append(a + 5) +            new.append(a + 7) +        list.append(new) +    pass -    for a in range(3, A + 2): -        for i in itertools.product([3, 5, 7], repeat=a): -            digit = 0 -            if 3 in i and 5 in i and 7 in i: -                for s in range(a): -                    digit += 10 ** (a - s - 1) * i[s] -                if digit <= N: -                    count += 1 -                else: -                    break -    print(count) +    for sub in list: +        for j in sub: +            s = str(j) +            if j > N: +                print(count) +                exit() +            if "3" in s and "7" in s and "5" in s: +                count += 1