import itertools

N = int(raw_input())
count = 0

for i in range(3,10):
	for j in itertools.product("357", repeat=i):
		if int("".join(j))<=N and "7" in j and "5" in j and "3" in j:
			count += 1
print count