import itertools
from collections import defaultdict

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

