N=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
	