N = int(input())
X = 0
for i in range(356, N+1):
	A = str(i)
	if A.count('3') > 0 and A.count('5') > 0 and A.count('7') > 0 and A.count('1')== 0 and A.count('2')== 0 and A.count('4')== 0 and A.count('6')== 0 and A.count('8')== 0 and A.count('9')== 0 and A.count('0')== 0:
		X = X+1
print(X)