n = int(input())
c = 0

for i in range(n+1):
    i2 = list(str(i))
    if i2.count("3") >= 1 and i2.count("5") >= 1 and i2.count("7") >= 1:
        if i2.count("3") + i2.count("5") + i2.count("7") == len(i2):
            c += 1

print(c)