N=raw_input()

l=len(N)

s="375"

ans=0
def func(t):
	global ans
	#print "func( ", t, " )", len(t)
	if len(t)>len(N):
		return
	else:
		for si in s:
			if si not in t:
				break
		else:
			if int(t)<=int(N):
				ans+=1
	func(t+"3")
	func(t+"5")
	func(t+"7")

	return ans

print func("") 
