N = int(input())
cnt = 0
for i in range(1, N + 1):
    a = list(str(i))
    if "1" in a or "2" in a or "4" in a or "6" in a or "8" in a or "9" in a or "0" in a:
        continue
    if a.count("3") >= 1 and a.count("5") >= 1and a.count("7") >= 1:
        cnt += 1
    
print(cnt)