N = int(input())
ans = 0
for n in range(1, N):
	n = list(str(n))
	if n.count("7") > 0:
		n = [i for i in n if i != "7"]
		if n.count("5") > 0:
			n = [j for j in n if j != "5"]
			if n.count("3") > 0:
				n = [k for k in n if k != "3"]
				if len(n) == 0:
					ans += 1
print(ans)
