def makestr(lst):
	s = ''
	for i in range(0, len(lst)):
		s = s + lst[i]
	return s

N = int(raw_input())
queue = [[]]
cnt = 0
while(True):
	now = queue.pop(0)
	if now != []:
		if int(makestr(now)) > N: break
		elif '3' in now and '5' in now and '7' in now:
			cnt += 1
	lst = ['3', '5', '7']
	for i in range(0, 3):
		next = []
		for j in range(0, len(now)):
			next.append(now[j])
		next.append(lst[i])
		queue.append(next)

print cnt