import numpy as np

N = int(input())

def check(i):
	s = str(i)
	for c in s:
		if c is '3' or c is '5' or c is '7':
			pass
		else:
			return False
	return True

t = 0
for i in range(1,N+1):
	if check(i):
		t+=1
print(t)
