import numpy as np

N = int(input())

def check(i):
	s = str(i)
	f3 = False
	f5 = False
	f7 = False
	for c in s:
		if c is '3':
			f3 = True
		elif c is '5':
			f5 = True
		elif c is '7':
			f7 = True
		else:
			return False
	return f3 & f5 & f7

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