import sys

input = sys.stdin.readline





c = 0

num = 0

def check(n):

	strn = str(n)

	l = [0, 0, 0]

	for c in strn:

		if c == '3':

			l[0] = 1

		elif c == '5':

			l[1] = 1

		elif c == '7':

			l[2] = 1

	return all(l) or False



def gen(n):

	global c

	# print(n)

	if n > num:

		return

	if check(n):

		# print(n)

		c += 1

	for i in [3, 5, 7]:

		k = 10 * n + i

		gen(k)



def main():

	global num

	num = int(input().strip())

	gen(0)

	print(c)



if __name__ == '__main__':

	main()

import sys

input = sys.stdin.readline

from operator import itemgetter

sys.setrecursionlimit(10000000)

INF = 10**30



ans = 0

c = ['3', '5', '7']

N = 0



def check(l):

    return len(set(l)) == 3



def nummaker(k, n):

    global ans

    if k == 0:

        q = int(''.join(n))

        if q > N:

            print(ans)

            sys.exit(0)

        if check(n):

            ans += 1

        return

    for i in c:

        m = n[:]

        m.append(i)

        nummaker(k-1, m)



def main():

    global N

    N = int(input().strip())

    for i in range(1, 11):

        nummaker(i, [])



if __name__ == '__main__':

    main()

import sys

input = sys.stdin.readline
c = 0
num = 0


def check(n):
    strn = str(n)
    l = [0, 0, 0]
    for c in strn:
        if c == "3":
            l[0] = 1
        elif c == "5":
            l[1] = 1
        elif c == "7":
            l[2] = 1
    return all(l) or False


def gen(n):
    global c
    # print(n)
    if n > num:
        return
    if check(n):
        # print(n)
        c += 1
    for i in [3, 5, 7]:
        k = 10 * n + i
        gen(k)


def main():
    global num
    num = int(input().strip())
    gen(0)
    print(c)


if __name__ == "__main__":
    main()

import sys

input = sys.stdin.readline
from operator import itemgetter

sys.setrecursionlimit(10000000)
INF = 10**30
ans = 0
c = ["3", "5", "7"]
N = 0


def check(l):
    return len(set(l)) == 3


def nummaker(k, n):
    global ans
    if k == 0:
        q = int("".join(n))
        if q > N:
            print(ans)
            sys.exit(0)
        if check(n):
            ans += 1
        return
    for i in c:
        m = n[:]
        m.append(i)
        nummaker(k - 1, m)


def main():
    global N
    N = int(input().strip())
    for i in range(1, 11):
        nummaker(i, [])


if __name__ == "__main__":
    main()

-c = 0 -num = 0 +from operator import itemgetter + +sys.setrecursionlimit(10000000) +INF = 10**30 +ans = 0 +c = ["3", "5", "7"] +N = 0 -def check(n): -    strn = str(n) -    l = [0, 0, 0] -    for c in strn: -        if c == "3": -            l[0] = 1 -        elif c == "5": -            l[1] = 1 -        elif c == "7": -            l[2] = 1 -    return all(l) or False +def check(l): +    return len(set(l)) == 3 -def gen(n): -    global c -    # print(n) -    if n > num: +def nummaker(k, n): +    global ans +    if k == 0: +        q = int("".join(n)) +        if q > N: +            print(ans) +            sys.exit(0) +        if check(n): +            ans += 1 -    if check(n): -        # print(n) -        c += 1 -    for i in [3, 5, 7]: -        k = 10 * n + i -        gen(k) +    for i in c: +        m = n[:] +        m.append(i) +        nummaker(k - 1, m) -    global num -    num = int(input().strip()) -    gen(0) -    print(c) +    global N +    N = int(input().strip()) +    for i in range(1, 11): +        nummaker(i, [])