n = int(input())
ans = 0
for i in range(1,n+1):
    seven = 0
    five = 0
    three = 0
    while i > 0:
        if i % 10 == 7:
            seven = 1
        elif i % 10 == 3:
            three = 1
        elif i % 10 == 5:
            five = 1
        else:
            break
        i = i // 10
    if i == 0 and seven == 1 and five == 1 and three == 1:
        ans += 1
print(ans)
