n = input()
counter = 0
for i in range(1, int(n) + 1):
    li = list(str(i))
    a = li.count("3")
    b = li.count("5")
    c = li.count("7")
    if a > 0 and b > 0 and c > 0 and a+b+c==len(li):
        counter += 1
print(counter)