N=raw_input()
l=len(N)
 
s="375"


def func(n):
	#print "func ::: ", n
	ret=0
	if len(n) == 0 :
		ret+=func(n+"3")
		ret+=func(n+"5")
		ret+=func(n+"7")
	elif  int(n)<=int(N):
		for i in s:
			if i not in n:
				ret=0
				break
		else:
			ret=1

		ret+=func(n+"3")
		ret+=func(n+"5")
		ret+=func(n+"7")
	return ret

print func("")