n = int(input())
count = 0
for i in range(n):
    c = str(i)
    a = []
    a = list(c)
    s = a.count('7')
    f = a.count('5')
    t = a.count('3')
    if s != 0 and f != 0 and t != 0:
        if len(a) == s+t+f:
            count += 1

print(count)