import itertools

from collections import defaultdict



N=input()

k=len(N)



if int(N)<357:

	print(0)

	quit()



ans=0



for k in range(3,k+1):

	L=list(itertools.product( (3,5,7) , repeat=k))



	for t  in L:

		C=defaultdict(lambda: 0)

		v=0



		for idx, x in enumerate(t):

			v+=x*(10**idx)

			if x!=0:

				C[x]+=1

	

		if v<=int(N) and len(C)==3:

			ans+=1



print(ans)



N=eval(input())



l=len( str(N) )



s="357"



P=[ set() for i in range(l+1) ]   #Pattern

P[0].add(0)



for i in range(1,l+1):

	k=l-i	#keta

	for x in P[i-1]:

		for j in s:

			j=int(j)

			P[i].add(  x+(10**k)*j )

			P[i].add( 0 )





ans=0

for x in P[-1]:

	if  1<= x <= N:

		for i in s:

			if i not in str(x):

				break

		else:

			ans+=1



print(ans)

	
import itertools
from collections import defaultdict

N = input()
k = len(N)
if int(N) < 357:
    print(0)
    quit()
ans = 0
for k in range(3, k + 1):
    L = list(itertools.product((3, 5, 7), repeat=k))
    for t in L:
        C = defaultdict(lambda: 0)
        v = 0
        for idx, x in enumerate(t):
            v += x * (10**idx)
            if x != 0:
                C[x] += 1
        if v <= int(N) and len(C) == 3:
            ans += 1
print(ans)

N = eval(input())
l = len(str(N))
s = "357"
P = [set() for i in range(l + 1)]  # Pattern
P[0].add(0)
for i in range(1, l + 1):
    k = l - i  # keta
    for x in P[i - 1]:
        for j in s:
            j = int(j)
            P[i].add(x + (10**k) * j)
            P[i].add(0)
ans = 0
for x in P[-1]:
    if 1 <= x <= N:
        for i in s:
            if i not in str(x):
                break
        else:
            ans += 1
print(ans)

-import itertools -from collections import defaultdict - -N = input() -k = len(N) -if int(N) < 357: -    print(0) -    quit() +N = eval(input()) +l = len(str(N)) +s = "357" +P = [set() for i in range(l + 1)]  # Pattern +P[0].add(0) +for i in range(1, l + 1): +    k = l - i  # keta +    for x in P[i - 1]: +        for j in s: +            j = int(j) +            P[i].add(x + (10**k) * j) +            P[i].add(0) -for k in range(3, k + 1): -    L = list(itertools.product((3, 5, 7), repeat=k)) -    for t in L: -        C = defaultdict(lambda: 0) -        v = 0 -        for idx, x in enumerate(t): -            v += x * (10**idx) -            if x != 0: -                C[x] += 1 -        if v <= int(N) and len(C) == 3: +for x in P[-1]: +    if 1 <= x <= N: +        for i in s: +            if i not in str(x): +                break +        else: